echarts.js 2.8 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579685806858168582685836858468585685866858768588685896859068591685926859368594685956859668597685986859968600686016860268603686046860568606686076860868609686106861168612686136861468615686166861768618686196862068621686226862368624686256862668627686286862968630686316863268633686346863568636686376863868639686406864168642686436864468645686466864768648686496865068651686526865368654686556865668657686586865968660686616866268663686646866568666686676866868669686706867168672686736867468675686766867768678686796868068681686826868368684686856868668687686886868968690686916869268693686946869568696686976869868699687006870168702687036870468705687066870768708687096871068711687126871368714687156871668717687186871968720687216872268723687246872568726687276872868729687306873168732687336873468735687366873768738687396874068741687426874368744687456874668747687486874968750687516875268753687546875568756687576875868759687606876168762687636876468765687666876768768687696877068771687726877368774687756877668777687786877968780687816878268783687846878568786687876878868789687906879168792687936879468795687966879768798687996880068801688026880368804688056880668807688086880968810688116881268813688146881568816688176881868819688206882168822688236882468825688266882768828688296883068831688326883368834688356883668837688386883968840688416884268843688446884568846688476884868849688506885168852688536885468855688566885768858688596886068861688626886368864688656886668867688686886968870688716887268873688746887568876688776887868879688806888168882688836888468885688866888768888688896889068891688926889368894688956889668897688986889968900689016890268903689046890568906689076890868909689106891168912689136891468915689166891768918689196892068921689226892368924689256892668927689286892968930689316893268933689346893568936689376893868939689406894168942689436894468945689466894768948689496895068951689526895368954689556895668957689586895968960689616896268963689646896568966689676896868969689706897168972689736897468975689766897768978689796898068981689826898368984689856898668987689886898968990689916899268993689946899568996689976899868999690006900169002690036900469005690066900769008690096901069011690126901369014690156901669017690186901969020690216902269023690246902569026690276902869029690306903169032690336903469035690366903769038690396904069041690426904369044690456904669047690486904969050690516905269053690546905569056690576905869059690606906169062690636906469065690666906769068690696907069071690726907369074690756907669077690786907969080690816908269083690846908569086690876908869089690906909169092690936909469095690966909769098690996910069101691026910369104691056910669107691086910969110691116911269113691146911569116691176911869119691206912169122691236912469125691266912769128691296913069131691326913369134691356913669137691386913969140691416914269143691446914569146691476914869149691506915169152691536915469155691566915769158691596916069161691626916369164691656916669167691686916969170691716917269173691746917569176691776917869179691806918169182691836918469185691866918769188691896919069191691926919369194691956919669197691986919969200692016920269203692046920569206692076920869209692106921169212692136921469215692166921769218692196922069221692226922369224692256922669227692286922969230692316923269233692346923569236692376923869239692406924169242692436924469245692466924769248692496925069251692526925369254692556925669257692586925969260692616926269263692646926569266692676926869269692706927169272692736927469275692766927769278692796928069281692826928369284692856928669287692886928969290692916929269293692946929569296692976929869299693006930169302693036930469305693066930769308693096931069311693126931369314693156931669317693186931969320693216932269323693246932569326693276932869329693306933169332693336933469335693366933769338693396934069341693426934369344693456934669347693486934969350693516935269353693546935569356693576935869359693606936169362693636936469365693666936769368693696937069371693726937369374693756937669377693786937969380693816938269383693846938569386693876938869389693906939169392693936939469395693966939769398693996940069401694026940369404694056940669407694086940969410694116941269413694146941569416694176941869419694206942169422694236942469425694266942769428694296943069431694326943369434694356943669437694386943969440694416944269443694446944569446694476944869449694506945169452694536945469455694566945769458694596946069461694626946369464694656946669467694686946969470694716947269473694746947569476694776947869479694806948169482694836948469485694866948769488694896949069491694926949369494694956949669497694986949969500695016950269503695046950569506695076950869509695106951169512695136951469515695166951769518695196952069521695226952369524695256952669527695286952969530695316953269533695346953569536695376953869539695406954169542695436954469545695466954769548695496955069551695526955369554695556955669557695586955969560695616956269563695646956569566695676956869569695706957169572695736957469575695766957769578695796958069581695826958369584695856958669587695886958969590695916959269593695946959569596695976959869599696006960169602696036960469605696066960769608696096961069611696126961369614696156961669617696186961969620696216962269623696246962569626696276962869629696306963169632696336963469635696366963769638696396964069641696426964369644696456964669647696486964969650696516965269653696546965569656696576965869659696606966169662696636966469665696666966769668696696967069671696726967369674696756967669677696786967969680696816968269683696846968569686696876968869689696906969169692696936969469695696966969769698696996970069701697026970369704697056970669707697086970969710697116971269713697146971569716697176971869719697206972169722697236972469725697266972769728697296973069731697326973369734697356973669737697386973969740697416974269743697446974569746697476974869749697506975169752697536975469755697566975769758697596976069761697626976369764697656976669767697686976969770697716977269773697746977569776697776977869779697806978169782697836978469785697866978769788697896979069791697926979369794697956979669797697986979969800698016980269803698046980569806698076980869809698106981169812698136981469815698166981769818698196982069821698226982369824698256982669827698286982969830698316983269833698346983569836698376983869839698406984169842698436984469845698466984769848698496985069851698526985369854698556985669857698586985969860698616986269863698646986569866698676986869869698706987169872698736987469875698766987769878698796988069881698826988369884698856988669887698886988969890698916989269893698946989569896698976989869899699006990169902699036990469905699066990769908699096991069911699126991369914699156991669917699186991969920699216992269923699246992569926699276992869929699306993169932699336993469935699366993769938699396994069941699426994369944699456994669947699486994969950699516995269953699546995569956699576995869959699606996169962699636996469965699666996769968699696997069971699726997369974699756997669977699786997969980699816998269983699846998569986699876998869989699906999169992699936999469995699966999769998699997000070001700027000370004700057000670007700087000970010700117001270013700147001570016700177001870019700207002170022700237002470025700267002770028700297003070031700327003370034700357003670037700387003970040700417004270043700447004570046700477004870049700507005170052700537005470055700567005770058700597006070061700627006370064700657006670067700687006970070700717007270073700747007570076700777007870079700807008170082700837008470085700867008770088700897009070091700927009370094700957009670097700987009970100701017010270103701047010570106701077010870109701107011170112701137011470115701167011770118701197012070121701227012370124701257012670127701287012970130701317013270133701347013570136701377013870139701407014170142701437014470145701467014770148701497015070151701527015370154701557015670157701587015970160701617016270163701647016570166701677016870169701707017170172701737017470175701767017770178701797018070181701827018370184701857018670187701887018970190701917019270193701947019570196701977019870199702007020170202702037020470205702067020770208702097021070211702127021370214702157021670217702187021970220702217022270223702247022570226702277022870229702307023170232702337023470235702367023770238702397024070241702427024370244702457024670247702487024970250702517025270253702547025570256702577025870259702607026170262702637026470265702667026770268702697027070271702727027370274702757027670277702787027970280702817028270283702847028570286702877028870289702907029170292702937029470295702967029770298702997030070301703027030370304703057030670307703087030970310703117031270313703147031570316703177031870319703207032170322703237032470325703267032770328703297033070331703327033370334703357033670337703387033970340703417034270343703447034570346703477034870349703507035170352703537035470355703567035770358703597036070361703627036370364703657036670367703687036970370703717037270373703747037570376703777037870379703807038170382703837038470385703867038770388703897039070391703927039370394703957039670397703987039970400704017040270403704047040570406704077040870409704107041170412704137041470415704167041770418704197042070421704227042370424704257042670427704287042970430704317043270433704347043570436704377043870439704407044170442704437044470445704467044770448704497045070451704527045370454704557045670457704587045970460704617046270463704647046570466704677046870469704707047170472704737047470475704767047770478704797048070481704827048370484704857048670487704887048970490704917049270493704947049570496704977049870499705007050170502705037050470505705067050770508705097051070511705127051370514705157051670517705187051970520705217052270523705247052570526705277052870529705307053170532705337053470535705367053770538705397054070541705427054370544705457054670547705487054970550705517055270553705547055570556705577055870559705607056170562705637056470565705667056770568705697057070571705727057370574705757057670577705787057970580705817058270583705847058570586705877058870589705907059170592705937059470595705967059770598705997060070601706027060370604706057060670607706087060970610706117061270613706147061570616706177061870619706207062170622706237062470625706267062770628706297063070631706327063370634706357063670637706387063970640706417064270643706447064570646706477064870649706507065170652706537065470655706567065770658706597066070661706627066370664706657066670667706687066970670706717067270673706747067570676706777067870679706807068170682706837068470685706867068770688706897069070691706927069370694706957069670697706987069970700707017070270703707047070570706707077070870709707107071170712707137071470715707167071770718707197072070721707227072370724707257072670727707287072970730707317073270733707347073570736707377073870739707407074170742707437074470745707467074770748707497075070751707527075370754707557075670757707587075970760707617076270763707647076570766707677076870769707707077170772707737077470775707767077770778707797078070781707827078370784707857078670787707887078970790707917079270793707947079570796707977079870799708007080170802708037080470805708067080770808708097081070811708127081370814708157081670817708187081970820708217082270823708247082570826708277082870829708307083170832708337083470835708367083770838708397084070841708427084370844708457084670847708487084970850708517085270853708547085570856708577085870859708607086170862708637086470865708667086770868708697087070871708727087370874708757087670877708787087970880708817088270883708847088570886708877088870889708907089170892708937089470895708967089770898708997090070901709027090370904709057090670907709087090970910709117091270913709147091570916709177091870919709207092170922709237092470925709267092770928709297093070931709327093370934709357093670937709387093970940709417094270943709447094570946709477094870949709507095170952709537095470955709567095770958709597096070961709627096370964709657096670967709687096970970709717097270973709747097570976709777097870979709807098170982709837098470985709867098770988709897099070991709927099370994709957099670997709987099971000710017100271003710047100571006710077100871009710107101171012710137101471015710167101771018710197102071021710227102371024710257102671027710287102971030710317103271033710347103571036710377103871039710407104171042710437104471045710467104771048710497105071051710527105371054710557105671057710587105971060710617106271063710647106571066710677106871069710707107171072710737107471075710767107771078710797108071081710827108371084710857108671087710887108971090710917109271093710947109571096710977109871099711007110171102711037110471105711067110771108711097111071111711127111371114711157111671117711187111971120711217112271123711247112571126711277112871129711307113171132711337113471135711367113771138711397114071141711427114371144711457114671147711487114971150711517115271153711547115571156711577115871159711607116171162711637116471165711667116771168711697117071171711727117371174711757117671177711787117971180711817118271183711847118571186711877118871189711907119171192711937119471195711967119771198711997120071201712027120371204712057120671207712087120971210712117121271213712147121571216712177121871219712207122171222712237122471225712267122771228712297123071231712327123371234712357123671237712387123971240712417124271243712447124571246712477124871249712507125171252712537125471255712567125771258712597126071261712627126371264712657126671267712687126971270712717127271273712747127571276712777127871279712807128171282712837128471285712867128771288712897129071291712927129371294712957129671297712987129971300713017130271303713047130571306713077130871309713107131171312713137131471315713167131771318713197132071321713227132371324713257132671327713287132971330713317133271333713347133571336713377133871339713407134171342713437134471345713467134771348713497135071351713527135371354713557135671357713587135971360713617136271363713647136571366713677136871369713707137171372713737137471375713767137771378713797138071381713827138371384713857138671387713887138971390713917139271393713947139571396713977139871399714007140171402714037140471405714067140771408714097141071411714127141371414714157141671417714187141971420714217142271423714247142571426714277142871429714307143171432714337143471435714367143771438714397144071441714427144371444714457144671447714487144971450714517145271453714547145571456714577145871459714607146171462714637146471465714667146771468714697147071471714727147371474714757147671477714787147971480714817148271483714847148571486714877148871489714907149171492714937149471495714967149771498714997150071501715027150371504715057150671507715087150971510715117151271513715147151571516715177151871519715207152171522715237152471525715267152771528715297153071531715327153371534715357153671537715387153971540715417154271543715447154571546715477154871549715507155171552715537155471555715567155771558715597156071561715627156371564715657156671567715687156971570715717157271573715747157571576715777157871579715807158171582715837158471585715867158771588715897159071591715927159371594715957159671597715987159971600716017160271603716047160571606716077160871609716107161171612716137161471615716167161771618716197162071621716227162371624716257162671627716287162971630716317163271633716347163571636716377163871639716407164171642716437164471645716467164771648716497165071651716527165371654716557165671657716587165971660716617166271663716647166571666716677166871669716707167171672716737167471675716767167771678716797168071681716827168371684716857168671687716887168971690716917169271693716947169571696716977169871699717007170171702717037170471705717067170771708717097171071711717127171371714717157171671717717187171971720717217172271723717247172571726717277172871729717307173171732717337173471735717367173771738717397174071741717427174371744717457174671747717487174971750717517175271753717547175571756717577175871759717607176171762717637176471765717667176771768717697177071771717727177371774717757177671777717787177971780717817178271783717847178571786717877178871789717907179171792717937179471795717967179771798717997180071801718027180371804718057180671807718087180971810718117181271813718147181571816718177181871819718207182171822718237182471825718267182771828718297183071831718327183371834718357183671837718387183971840718417184271843718447184571846718477184871849718507185171852718537185471855718567185771858718597186071861718627186371864718657186671867718687186971870718717187271873718747187571876718777187871879718807188171882718837188471885718867188771888718897189071891718927189371894718957189671897718987189971900719017190271903719047190571906719077190871909719107191171912719137191471915719167191771918719197192071921719227192371924719257192671927719287192971930719317193271933719347193571936719377193871939719407194171942719437194471945719467194771948719497195071951719527195371954719557195671957719587195971960719617196271963719647196571966719677196871969719707197171972719737197471975719767197771978719797198071981719827198371984719857198671987719887198971990719917199271993719947199571996719977199871999720007200172002720037200472005720067200772008720097201072011720127201372014720157201672017720187201972020720217202272023720247202572026720277202872029720307203172032720337203472035720367203772038720397204072041720427204372044720457204672047720487204972050720517205272053720547205572056720577205872059720607206172062720637206472065720667206772068720697207072071720727207372074720757207672077720787207972080720817208272083720847208572086720877208872089720907209172092720937209472095720967209772098720997210072101721027210372104721057210672107721087210972110721117211272113721147211572116721177211872119721207212172122721237212472125721267212772128721297213072131721327213372134721357213672137721387213972140721417214272143721447214572146721477214872149721507215172152721537215472155721567215772158721597216072161721627216372164721657216672167721687216972170721717217272173721747217572176721777217872179721807218172182721837218472185721867218772188721897219072191721927219372194721957219672197721987219972200722017220272203722047220572206722077220872209722107221172212722137221472215722167221772218722197222072221722227222372224722257222672227722287222972230722317223272233722347223572236722377223872239722407224172242722437224472245722467224772248722497225072251722527225372254722557225672257722587225972260722617226272263722647226572266722677226872269722707227172272722737227472275722767227772278722797228072281722827228372284722857228672287722887228972290722917229272293722947229572296722977229872299723007230172302723037230472305723067230772308723097231072311723127231372314723157231672317723187231972320723217232272323723247232572326723277232872329723307233172332723337233472335723367233772338723397234072341723427234372344723457234672347723487234972350723517235272353723547235572356723577235872359723607236172362723637236472365723667236772368723697237072371723727237372374723757237672377723787237972380723817238272383723847238572386723877238872389723907239172392723937239472395723967239772398723997240072401724027240372404724057240672407724087240972410724117241272413724147241572416724177241872419724207242172422724237242472425724267242772428724297243072431724327243372434724357243672437724387243972440724417244272443724447244572446724477244872449724507245172452724537245472455724567245772458724597246072461724627246372464724657246672467724687246972470724717247272473724747247572476724777247872479724807248172482724837248472485724867248772488724897249072491724927249372494724957249672497724987249972500725017250272503725047250572506725077250872509725107251172512725137251472515725167251772518725197252072521725227252372524725257252672527725287252972530725317253272533725347253572536725377253872539725407254172542725437254472545725467254772548725497255072551725527255372554725557255672557725587255972560725617256272563725647256572566725677256872569725707257172572725737257472575725767257772578725797258072581725827258372584725857258672587725887258972590725917259272593725947259572596725977259872599726007260172602726037260472605726067260772608726097261072611726127261372614726157261672617726187261972620726217262272623726247262572626726277262872629726307263172632726337263472635726367263772638726397264072641726427264372644726457264672647726487264972650726517265272653726547265572656726577265872659726607266172662726637266472665726667266772668726697267072671726727267372674726757267672677726787267972680726817268272683726847268572686726877268872689726907269172692726937269472695726967269772698726997270072701727027270372704727057270672707727087270972710727117271272713727147271572716727177271872719727207272172722727237272472725727267272772728727297273072731727327273372734727357273672737727387273972740727417274272743727447274572746727477274872749727507275172752727537275472755727567275772758727597276072761727627276372764727657276672767727687276972770727717277272773727747277572776727777277872779727807278172782727837278472785727867278772788727897279072791727927279372794727957279672797727987279972800728017280272803728047280572806728077280872809728107281172812728137281472815728167281772818728197282072821728227282372824728257282672827728287282972830728317283272833728347283572836728377283872839728407284172842728437284472845728467284772848728497285072851728527285372854728557285672857728587285972860728617286272863728647286572866728677286872869728707287172872728737287472875728767287772878728797288072881728827288372884728857288672887728887288972890728917289272893728947289572896728977289872899729007290172902729037290472905729067290772908729097291072911729127291372914729157291672917729187291972920729217292272923729247292572926729277292872929729307293172932729337293472935729367293772938729397294072941729427294372944729457294672947729487294972950729517295272953729547295572956729577295872959729607296172962729637296472965729667296772968729697297072971729727297372974729757297672977729787297972980729817298272983729847298572986729877298872989729907299172992729937299472995729967299772998729997300073001730027300373004730057300673007730087300973010730117301273013730147301573016730177301873019730207302173022730237302473025730267302773028730297303073031730327303373034730357303673037730387303973040730417304273043730447304573046730477304873049730507305173052730537305473055730567305773058730597306073061730627306373064730657306673067730687306973070730717307273073730747307573076730777307873079730807308173082730837308473085730867308773088730897309073091730927309373094730957309673097730987309973100731017310273103731047310573106731077310873109731107311173112731137311473115731167311773118731197312073121731227312373124731257312673127731287312973130731317313273133731347313573136731377313873139731407314173142731437314473145731467314773148731497315073151731527315373154731557315673157731587315973160731617316273163731647316573166731677316873169731707317173172731737317473175731767317773178731797318073181731827318373184731857318673187731887318973190731917319273193731947319573196731977319873199732007320173202732037320473205732067320773208732097321073211732127321373214732157321673217732187321973220732217322273223732247322573226732277322873229732307323173232732337323473235732367323773238732397324073241732427324373244732457324673247732487324973250732517325273253732547325573256732577325873259732607326173262732637326473265732667326773268732697327073271732727327373274732757327673277732787327973280732817328273283732847328573286732877328873289732907329173292732937329473295732967329773298732997330073301733027330373304733057330673307733087330973310733117331273313733147331573316733177331873319733207332173322733237332473325733267332773328733297333073331733327333373334733357333673337733387333973340733417334273343733447334573346733477334873349733507335173352733537335473355733567335773358733597336073361733627336373364733657336673367733687336973370733717337273373733747337573376733777337873379733807338173382733837338473385733867338773388733897339073391733927339373394733957339673397733987339973400734017340273403734047340573406734077340873409734107341173412734137341473415734167341773418734197342073421734227342373424734257342673427734287342973430734317343273433734347343573436734377343873439734407344173442734437344473445734467344773448734497345073451734527345373454734557345673457734587345973460734617346273463734647346573466734677346873469734707347173472734737347473475734767347773478734797348073481734827348373484734857348673487734887348973490734917349273493734947349573496734977349873499735007350173502735037350473505735067350773508735097351073511735127351373514735157351673517735187351973520735217352273523735247352573526735277352873529735307353173532735337353473535735367353773538735397354073541735427354373544735457354673547735487354973550735517355273553735547355573556735577355873559735607356173562735637356473565735667356773568735697357073571735727357373574735757357673577735787357973580735817358273583735847358573586735877358873589735907359173592735937359473595735967359773598735997360073601736027360373604736057360673607736087360973610736117361273613736147361573616736177361873619736207362173622736237362473625736267362773628736297363073631736327363373634736357363673637736387363973640736417364273643736447364573646736477364873649736507365173652736537365473655736567365773658736597366073661736627366373664736657366673667736687366973670736717367273673736747367573676736777367873679736807368173682736837368473685736867368773688736897369073691736927369373694736957369673697736987369973700737017370273703737047370573706737077370873709737107371173712737137371473715737167371773718737197372073721737227372373724737257372673727737287372973730737317373273733737347373573736737377373873739737407374173742737437374473745737467374773748737497375073751737527375373754737557375673757737587375973760737617376273763737647376573766737677376873769737707377173772737737377473775737767377773778737797378073781737827378373784737857378673787737887378973790737917379273793737947379573796737977379873799738007380173802738037380473805738067380773808738097381073811738127381373814738157381673817738187381973820738217382273823738247382573826738277382873829738307383173832738337383473835738367383773838738397384073841738427384373844738457384673847738487384973850738517385273853738547385573856738577385873859738607386173862738637386473865738667386773868738697387073871738727387373874738757387673877738787387973880738817388273883738847388573886738877388873889738907389173892738937389473895738967389773898738997390073901739027390373904739057390673907739087390973910739117391273913739147391573916739177391873919739207392173922739237392473925739267392773928739297393073931739327393373934739357393673937739387393973940739417394273943739447394573946739477394873949739507395173952739537395473955739567395773958739597396073961739627396373964739657396673967739687396973970739717397273973739747397573976739777397873979739807398173982739837398473985739867398773988739897399073991739927399373994739957399673997739987399974000740017400274003740047400574006740077400874009740107401174012740137401474015740167401774018740197402074021740227402374024740257402674027740287402974030740317403274033740347403574036740377403874039740407404174042740437404474045740467404774048740497405074051740527405374054740557405674057740587405974060740617406274063740647406574066740677406874069740707407174072740737407474075740767407774078740797408074081740827408374084740857408674087740887408974090740917409274093740947409574096740977409874099741007410174102741037410474105741067410774108741097411074111741127411374114741157411674117741187411974120741217412274123741247412574126741277412874129741307413174132741337413474135741367413774138741397414074141741427414374144741457414674147741487414974150741517415274153741547415574156741577415874159741607416174162741637416474165741667416774168741697417074171741727417374174741757417674177741787417974180741817418274183741847418574186741877418874189741907419174192741937419474195741967419774198741997420074201742027420374204742057420674207742087420974210742117421274213742147421574216742177421874219742207422174222742237422474225742267422774228742297423074231742327423374234742357423674237742387423974240742417424274243742447424574246742477424874249742507425174252742537425474255742567425774258742597426074261742627426374264742657426674267742687426974270742717427274273742747427574276742777427874279742807428174282742837428474285742867428774288742897429074291742927429374294742957429674297742987429974300743017430274303743047430574306743077430874309743107431174312743137431474315743167431774318743197432074321743227432374324743257432674327743287432974330743317433274333743347433574336743377433874339743407434174342743437434474345743467434774348743497435074351743527435374354743557435674357743587435974360743617436274363743647436574366743677436874369743707437174372743737437474375743767437774378743797438074381743827438374384743857438674387743887438974390743917439274393743947439574396743977439874399744007440174402744037440474405744067440774408744097441074411744127441374414744157441674417744187441974420744217442274423744247442574426744277442874429744307443174432744337443474435744367443774438744397444074441744427444374444744457444674447744487444974450744517445274453744547445574456744577445874459744607446174462744637446474465744667446774468744697447074471744727447374474744757447674477744787447974480744817448274483744847448574486744877448874489744907449174492744937449474495744967449774498744997450074501745027450374504745057450674507745087450974510745117451274513745147451574516745177451874519745207452174522745237452474525745267452774528745297453074531745327453374534745357453674537745387453974540745417454274543745447454574546745477454874549745507455174552745537455474555745567455774558745597456074561745627456374564745657456674567745687456974570745717457274573745747457574576745777457874579745807458174582745837458474585745867458774588745897459074591745927459374594745957459674597745987459974600746017460274603746047460574606746077460874609746107461174612746137461474615746167461774618746197462074621746227462374624746257462674627746287462974630746317463274633746347463574636746377463874639746407464174642746437464474645746467464774648746497465074651746527465374654746557465674657746587465974660746617466274663746647466574666746677466874669746707467174672746737467474675746767467774678746797468074681746827468374684746857468674687746887468974690746917469274693746947469574696746977469874699747007470174702747037470474705747067470774708747097471074711747127471374714747157471674717747187471974720747217472274723747247472574726747277472874729747307473174732747337473474735747367473774738747397474074741747427474374744747457474674747747487474974750747517475274753747547475574756747577475874759747607476174762747637476474765747667476774768747697477074771747727477374774747757477674777747787477974780747817478274783747847478574786747877478874789747907479174792747937479474795747967479774798747997480074801748027480374804748057480674807748087480974810748117481274813748147481574816748177481874819748207482174822748237482474825748267482774828748297483074831748327483374834748357483674837748387483974840748417484274843748447484574846748477484874849748507485174852748537485474855748567485774858748597486074861748627486374864748657486674867748687486974870748717487274873748747487574876748777487874879748807488174882748837488474885748867488774888748897489074891748927489374894748957489674897748987489974900749017490274903749047490574906749077490874909749107491174912749137491474915749167491774918749197492074921749227492374924749257492674927749287492974930749317493274933749347493574936749377493874939749407494174942749437494474945749467494774948749497495074951749527495374954749557495674957749587495974960749617496274963749647496574966749677496874969749707497174972749737497474975749767497774978749797498074981749827498374984749857498674987749887498974990749917499274993749947499574996749977499874999750007500175002750037500475005750067500775008750097501075011750127501375014750157501675017750187501975020750217502275023750247502575026750277502875029750307503175032750337503475035750367503775038750397504075041750427504375044750457504675047750487504975050750517505275053750547505575056750577505875059750607506175062750637506475065750667506775068750697507075071750727507375074750757507675077750787507975080750817508275083750847508575086750877508875089750907509175092750937509475095750967509775098750997510075101751027510375104751057510675107751087510975110751117511275113751147511575116751177511875119751207512175122751237512475125751267512775128751297513075131751327513375134751357513675137751387513975140751417514275143751447514575146751477514875149751507515175152751537515475155751567515775158751597516075161751627516375164751657516675167751687516975170751717517275173751747517575176751777517875179751807518175182751837518475185751867518775188751897519075191751927519375194751957519675197751987519975200752017520275203752047520575206752077520875209752107521175212752137521475215752167521775218752197522075221752227522375224752257522675227752287522975230752317523275233752347523575236752377523875239752407524175242752437524475245752467524775248752497525075251752527525375254752557525675257752587525975260752617526275263752647526575266752677526875269752707527175272752737527475275752767527775278752797528075281752827528375284752857528675287752887528975290752917529275293752947529575296752977529875299753007530175302753037530475305753067530775308753097531075311753127531375314753157531675317753187531975320753217532275323753247532575326753277532875329753307533175332753337533475335753367533775338753397534075341753427534375344753457534675347753487534975350753517535275353753547535575356753577535875359753607536175362753637536475365753667536775368753697537075371753727537375374753757537675377753787537975380753817538275383753847538575386753877538875389753907539175392753937539475395753967539775398753997540075401754027540375404754057540675407754087540975410754117541275413754147541575416754177541875419754207542175422754237542475425754267542775428754297543075431754327543375434754357543675437754387543975440754417544275443754447544575446754477544875449754507545175452754537545475455754567545775458754597546075461754627546375464754657546675467754687546975470754717547275473754747547575476754777547875479754807548175482754837548475485754867548775488754897549075491754927549375494754957549675497754987549975500755017550275503755047550575506755077550875509755107551175512755137551475515755167551775518755197552075521755227552375524755257552675527755287552975530755317553275533755347553575536755377553875539755407554175542755437554475545755467554775548755497555075551755527555375554755557555675557755587555975560755617556275563755647556575566755677556875569755707557175572755737557475575755767557775578755797558075581755827558375584755857558675587755887558975590755917559275593755947559575596755977559875599756007560175602756037560475605756067560775608756097561075611756127561375614756157561675617756187561975620756217562275623756247562575626756277562875629756307563175632756337563475635756367563775638756397564075641756427564375644756457564675647756487564975650756517565275653756547565575656756577565875659756607566175662756637566475665756667566775668756697567075671756727567375674756757567675677756787567975680756817568275683756847568575686756877568875689756907569175692756937569475695756967569775698756997570075701757027570375704757057570675707757087570975710757117571275713757147571575716757177571875719757207572175722757237572475725757267572775728757297573075731757327573375734757357573675737757387573975740757417574275743757447574575746757477574875749757507575175752757537575475755757567575775758757597576075761757627576375764757657576675767757687576975770757717577275773757747577575776757777577875779757807578175782757837578475785757867578775788757897579075791757927579375794757957579675797757987579975800758017580275803758047580575806758077580875809758107581175812758137581475815758167581775818758197582075821758227582375824758257582675827758287582975830758317583275833758347583575836758377583875839758407584175842758437584475845758467584775848758497585075851758527585375854758557585675857758587585975860758617586275863758647586575866758677586875869758707587175872758737587475875758767587775878758797588075881758827588375884758857588675887758887588975890758917589275893758947589575896758977589875899759007590175902759037590475905759067590775908759097591075911759127591375914759157591675917759187591975920759217592275923759247592575926759277592875929759307593175932759337593475935759367593775938759397594075941759427594375944759457594675947759487594975950759517595275953759547595575956759577595875959759607596175962759637596475965759667596775968759697597075971759727597375974759757597675977759787597975980759817598275983759847598575986759877598875989759907599175992759937599475995759967599775998759997600076001760027600376004760057600676007760087600976010760117601276013760147601576016760177601876019760207602176022760237602476025760267602776028760297603076031760327603376034760357603676037760387603976040760417604276043760447604576046760477604876049760507605176052760537605476055760567605776058760597606076061760627606376064760657606676067760687606976070760717607276073760747607576076760777607876079760807608176082760837608476085760867608776088760897609076091760927609376094760957609676097760987609976100761017610276103761047610576106761077610876109761107611176112761137611476115761167611776118761197612076121761227612376124761257612676127761287612976130761317613276133761347613576136761377613876139761407614176142761437614476145761467614776148761497615076151761527615376154761557615676157761587615976160761617616276163761647616576166761677616876169761707617176172761737617476175761767617776178761797618076181761827618376184761857618676187761887618976190761917619276193761947619576196761977619876199762007620176202762037620476205762067620776208762097621076211762127621376214762157621676217762187621976220762217622276223762247622576226762277622876229762307623176232762337623476235762367623776238762397624076241762427624376244762457624676247762487624976250762517625276253762547625576256762577625876259762607626176262762637626476265762667626776268762697627076271762727627376274762757627676277762787627976280762817628276283762847628576286762877628876289762907629176292762937629476295762967629776298762997630076301763027630376304763057630676307763087630976310763117631276313763147631576316763177631876319763207632176322763237632476325763267632776328763297633076331763327633376334763357633676337763387633976340763417634276343763447634576346763477634876349763507635176352763537635476355763567635776358763597636076361763627636376364763657636676367763687636976370763717637276373763747637576376763777637876379763807638176382763837638476385763867638776388763897639076391763927639376394763957639676397763987639976400764017640276403764047640576406764077640876409764107641176412764137641476415764167641776418764197642076421764227642376424764257642676427764287642976430764317643276433764347643576436764377643876439764407644176442764437644476445764467644776448764497645076451764527645376454764557645676457764587645976460764617646276463764647646576466764677646876469764707647176472764737647476475764767647776478764797648076481764827648376484764857648676487764887648976490764917649276493764947649576496764977649876499765007650176502765037650476505765067650776508765097651076511765127651376514765157651676517765187651976520765217652276523765247652576526765277652876529765307653176532765337653476535765367653776538765397654076541765427654376544765457654676547765487654976550765517655276553765547655576556765577655876559765607656176562765637656476565765667656776568765697657076571765727657376574765757657676577765787657976580765817658276583765847658576586765877658876589765907659176592765937659476595765967659776598765997660076601766027660376604766057660676607766087660976610766117661276613766147661576616766177661876619766207662176622766237662476625766267662776628766297663076631766327663376634766357663676637766387663976640766417664276643766447664576646766477664876649766507665176652766537665476655766567665776658766597666076661766627666376664766657666676667766687666976670766717667276673766747667576676766777667876679766807668176682766837668476685766867668776688766897669076691766927669376694766957669676697766987669976700767017670276703767047670576706767077670876709767107671176712767137671476715767167671776718767197672076721767227672376724767257672676727767287672976730767317673276733767347673576736767377673876739767407674176742767437674476745767467674776748767497675076751767527675376754767557675676757767587675976760767617676276763767647676576766767677676876769767707677176772767737677476775767767677776778767797678076781767827678376784767857678676787767887678976790767917679276793767947679576796767977679876799768007680176802768037680476805768067680776808768097681076811768127681376814768157681676817768187681976820768217682276823768247682576826768277682876829768307683176832768337683476835768367683776838768397684076841768427684376844768457684676847768487684976850768517685276853768547685576856768577685876859768607686176862768637686476865768667686776868768697687076871768727687376874768757687676877768787687976880768817688276883768847688576886768877688876889768907689176892768937689476895768967689776898768997690076901769027690376904769057690676907769087690976910769117691276913769147691576916769177691876919769207692176922769237692476925769267692776928769297693076931769327693376934769357693676937769387693976940769417694276943769447694576946769477694876949769507695176952769537695476955769567695776958769597696076961769627696376964769657696676967769687696976970769717697276973769747697576976769777697876979769807698176982769837698476985769867698776988769897699076991769927699376994769957699676997769987699977000770017700277003770047700577006770077700877009770107701177012770137701477015770167701777018770197702077021770227702377024770257702677027770287702977030770317703277033770347703577036770377703877039770407704177042770437704477045770467704777048770497705077051770527705377054770557705677057770587705977060770617706277063770647706577066770677706877069770707707177072770737707477075770767707777078770797708077081770827708377084770857708677087770887708977090770917709277093770947709577096770977709877099771007710177102771037710477105771067710777108771097711077111771127711377114771157711677117771187711977120771217712277123771247712577126771277712877129771307713177132771337713477135771367713777138771397714077141771427714377144771457714677147771487714977150771517715277153771547715577156771577715877159771607716177162771637716477165771667716777168771697717077171771727717377174771757717677177771787717977180771817718277183771847718577186771877718877189771907719177192771937719477195771967719777198771997720077201772027720377204772057720677207772087720977210772117721277213772147721577216772177721877219772207722177222772237722477225772267722777228772297723077231772327723377234772357723677237772387723977240772417724277243772447724577246772477724877249772507725177252772537725477255772567725777258772597726077261772627726377264772657726677267772687726977270772717727277273772747727577276772777727877279772807728177282772837728477285772867728777288772897729077291772927729377294772957729677297772987729977300773017730277303773047730577306773077730877309773107731177312773137731477315773167731777318773197732077321773227732377324773257732677327773287732977330773317733277333773347733577336773377733877339773407734177342773437734477345773467734777348773497735077351773527735377354773557735677357773587735977360773617736277363773647736577366773677736877369773707737177372773737737477375773767737777378773797738077381773827738377384773857738677387773887738977390773917739277393773947739577396773977739877399774007740177402774037740477405774067740777408774097741077411774127741377414774157741677417774187741977420774217742277423774247742577426774277742877429774307743177432774337743477435774367743777438774397744077441774427744377444774457744677447774487744977450774517745277453774547745577456774577745877459774607746177462774637746477465774667746777468774697747077471774727747377474774757747677477774787747977480774817748277483774847748577486774877748877489774907749177492774937749477495774967749777498774997750077501775027750377504775057750677507775087750977510775117751277513775147751577516775177751877519775207752177522775237752477525775267752777528775297753077531775327753377534775357753677537775387753977540775417754277543775447754577546775477754877549775507755177552775537755477555775567755777558775597756077561775627756377564775657756677567775687756977570775717757277573775747757577576775777757877579775807758177582775837758477585775867758777588775897759077591775927759377594775957759677597775987759977600776017760277603776047760577606776077760877609776107761177612776137761477615776167761777618776197762077621776227762377624776257762677627776287762977630776317763277633776347763577636776377763877639776407764177642776437764477645776467764777648776497765077651776527765377654776557765677657776587765977660776617766277663776647766577666776677766877669776707767177672776737767477675776767767777678776797768077681776827768377684776857768677687776887768977690776917769277693776947769577696776977769877699777007770177702777037770477705777067770777708777097771077711777127771377714777157771677717777187771977720777217772277723777247772577726777277772877729777307773177732777337773477735777367773777738777397774077741777427774377744777457774677747777487774977750777517775277753777547775577756777577775877759777607776177762777637776477765777667776777768777697777077771777727777377774777757777677777777787777977780777817778277783777847778577786777877778877789777907779177792777937779477795777967779777798777997780077801778027780377804778057780677807778087780977810778117781277813778147781577816778177781877819778207782177822778237782477825778267782777828778297783077831778327783377834778357783677837778387783977840778417784277843778447784577846778477784877849778507785177852778537785477855778567785777858778597786077861778627786377864778657786677867778687786977870778717787277873778747787577876778777787877879778807788177882778837788477885778867788777888778897789077891778927789377894778957789677897778987789977900779017790277903779047790577906779077790877909779107791177912779137791477915779167791777918779197792077921779227792377924779257792677927779287792977930779317793277933779347793577936779377793877939779407794177942779437794477945779467794777948779497795077951779527795377954779557795677957779587795977960779617796277963779647796577966779677796877969779707797177972779737797477975779767797777978779797798077981779827798377984779857798677987779887798977990779917799277993779947799577996779977799877999780007800178002780037800478005780067800778008780097801078011780127801378014780157801678017780187801978020780217802278023780247802578026780277802878029780307803178032780337803478035780367803778038780397804078041780427804378044780457804678047780487804978050780517805278053780547805578056780577805878059780607806178062780637806478065780667806778068780697807078071780727807378074780757807678077780787807978080780817808278083780847808578086780877808878089780907809178092780937809478095780967809778098780997810078101781027810378104781057810678107781087810978110781117811278113781147811578116781177811878119781207812178122781237812478125781267812778128781297813078131781327813378134781357813678137781387813978140781417814278143781447814578146781477814878149781507815178152781537815478155781567815778158781597816078161781627816378164781657816678167781687816978170781717817278173781747817578176781777817878179781807818178182781837818478185781867818778188781897819078191781927819378194781957819678197781987819978200782017820278203782047820578206782077820878209782107821178212782137821478215782167821778218782197822078221782227822378224782257822678227782287822978230782317823278233782347823578236782377823878239782407824178242782437824478245782467824778248782497825078251782527825378254782557825678257782587825978260782617826278263782647826578266782677826878269782707827178272782737827478275782767827778278782797828078281782827828378284782857828678287782887828978290782917829278293782947829578296782977829878299783007830178302783037830478305783067830778308783097831078311783127831378314783157831678317783187831978320783217832278323783247832578326783277832878329783307833178332783337833478335783367833778338783397834078341783427834378344783457834678347783487834978350783517835278353783547835578356783577835878359783607836178362783637836478365783667836778368783697837078371783727837378374783757837678377783787837978380783817838278383783847838578386783877838878389783907839178392783937839478395783967839778398783997840078401784027840378404784057840678407784087840978410784117841278413784147841578416784177841878419784207842178422784237842478425784267842778428784297843078431784327843378434784357843678437784387843978440784417844278443784447844578446784477844878449784507845178452784537845478455784567845778458784597846078461784627846378464784657846678467784687846978470784717847278473784747847578476784777847878479784807848178482784837848478485784867848778488784897849078491784927849378494784957849678497784987849978500785017850278503785047850578506785077850878509785107851178512785137851478515785167851778518785197852078521785227852378524785257852678527785287852978530785317853278533785347853578536785377853878539785407854178542785437854478545785467854778548785497855078551785527855378554785557855678557785587855978560785617856278563785647856578566785677856878569785707857178572785737857478575785767857778578785797858078581785827858378584785857858678587785887858978590785917859278593785947859578596785977859878599786007860178602786037860478605786067860778608786097861078611786127861378614786157861678617786187861978620786217862278623786247862578626786277862878629786307863178632786337863478635786367863778638786397864078641786427864378644786457864678647786487864978650786517865278653786547865578656786577865878659786607866178662786637866478665786667866778668786697867078671786727867378674786757867678677786787867978680786817868278683786847868578686786877868878689786907869178692786937869478695786967869778698786997870078701787027870378704787057870678707787087870978710787117871278713787147871578716787177871878719787207872178722787237872478725787267872778728787297873078731787327873378734787357873678737787387873978740787417874278743787447874578746787477874878749787507875178752787537875478755787567875778758787597876078761787627876378764787657876678767787687876978770787717877278773787747877578776787777877878779787807878178782787837878478785787867878778788787897879078791787927879378794787957879678797787987879978800788017880278803788047880578806788077880878809788107881178812788137881478815788167881778818788197882078821788227882378824788257882678827788287882978830788317883278833788347883578836788377883878839788407884178842788437884478845788467884778848788497885078851788527885378854788557885678857788587885978860788617886278863788647886578866788677886878869788707887178872788737887478875788767887778878788797888078881788827888378884788857888678887788887888978890788917889278893788947889578896788977889878899789007890178902789037890478905789067890778908789097891078911789127891378914789157891678917789187891978920789217892278923789247892578926789277892878929789307893178932789337893478935789367893778938789397894078941789427894378944789457894678947789487894978950789517895278953789547895578956789577895878959789607896178962789637896478965789667896778968789697897078971789727897378974789757897678977789787897978980789817898278983789847898578986789877898878989789907899178992789937899478995789967899778998789997900079001790027900379004790057900679007790087900979010790117901279013790147901579016790177901879019790207902179022790237902479025790267902779028790297903079031790327903379034790357903679037790387903979040790417904279043790447904579046790477904879049790507905179052790537905479055790567905779058790597906079061790627906379064790657906679067790687906979070790717907279073790747907579076790777907879079790807908179082790837908479085790867908779088790897909079091790927909379094790957909679097790987909979100791017910279103791047910579106791077910879109791107911179112791137911479115791167911779118791197912079121791227912379124791257912679127791287912979130791317913279133791347913579136791377913879139791407914179142791437914479145791467914779148791497915079151791527915379154791557915679157791587915979160791617916279163791647916579166791677916879169791707917179172791737917479175791767917779178791797918079181791827918379184791857918679187791887918979190791917919279193791947919579196791977919879199792007920179202792037920479205792067920779208792097921079211792127921379214792157921679217792187921979220792217922279223792247922579226792277922879229792307923179232792337923479235792367923779238792397924079241792427924379244792457924679247792487924979250792517925279253792547925579256792577925879259792607926179262792637926479265792667926779268792697927079271792727927379274792757927679277792787927979280792817928279283792847928579286792877928879289792907929179292792937929479295792967929779298792997930079301793027930379304793057930679307793087930979310793117931279313793147931579316793177931879319793207932179322793237932479325793267932779328793297933079331793327933379334793357933679337793387933979340793417934279343793447934579346793477934879349793507935179352793537935479355793567935779358793597936079361793627936379364793657936679367793687936979370793717937279373793747937579376793777937879379793807938179382793837938479385793867938779388793897939079391793927939379394793957939679397793987939979400794017940279403794047940579406794077940879409794107941179412794137941479415794167941779418794197942079421794227942379424794257942679427794287942979430794317943279433794347943579436794377943879439794407944179442794437944479445794467944779448794497945079451794527945379454794557945679457794587945979460794617946279463794647946579466794677946879469794707947179472794737947479475794767947779478794797948079481794827948379484794857948679487794887948979490794917949279493794947949579496794977949879499795007950179502795037950479505795067950779508795097951079511795127951379514795157951679517795187951979520795217952279523795247952579526795277952879529795307953179532795337953479535795367953779538795397954079541795427954379544795457954679547795487954979550795517955279553795547955579556795577955879559795607956179562795637956479565795667956779568795697957079571795727957379574795757957679577795787957979580795817958279583795847958579586795877958879589795907959179592795937959479595795967959779598795997960079601796027960379604796057960679607796087960979610796117961279613796147961579616796177961879619796207962179622796237962479625796267962779628796297963079631796327963379634796357963679637796387963979640796417964279643796447964579646796477964879649796507965179652796537965479655796567965779658796597966079661796627966379664796657966679667796687966979670796717967279673796747967579676796777967879679796807968179682796837968479685796867968779688796897969079691796927969379694796957969679697796987969979700797017970279703797047970579706797077970879709797107971179712797137971479715797167971779718797197972079721797227972379724797257972679727797287972979730797317973279733797347973579736797377973879739797407974179742797437974479745797467974779748797497975079751797527975379754797557975679757797587975979760797617976279763797647976579766797677976879769797707977179772797737977479775797767977779778797797978079781797827978379784797857978679787797887978979790797917979279793797947979579796797977979879799798007980179802798037980479805798067980779808798097981079811798127981379814798157981679817798187981979820798217982279823798247982579826798277982879829798307983179832798337983479835798367983779838798397984079841798427984379844798457984679847798487984979850798517985279853798547985579856798577985879859798607986179862798637986479865798667986779868798697987079871798727987379874798757987679877798787987979880798817988279883798847988579886798877988879889798907989179892798937989479895798967989779898798997990079901799027990379904799057990679907799087990979910799117991279913799147991579916799177991879919799207992179922799237992479925799267992779928799297993079931799327993379934799357993679937799387993979940799417994279943799447994579946799477994879949799507995179952799537995479955799567995779958799597996079961799627996379964799657996679967799687996979970799717997279973799747997579976799777997879979799807998179982799837998479985799867998779988799897999079991799927999379994799957999679997799987999980000800018000280003800048000580006800078000880009800108001180012800138001480015800168001780018800198002080021800228002380024800258002680027800288002980030800318003280033800348003580036800378003880039800408004180042800438004480045800468004780048800498005080051800528005380054800558005680057800588005980060800618006280063800648006580066800678006880069800708007180072800738007480075800768007780078800798008080081800828008380084800858008680087800888008980090800918009280093800948009580096800978009880099801008010180102801038010480105801068010780108801098011080111801128011380114801158011680117801188011980120801218012280123801248012580126801278012880129801308013180132801338013480135801368013780138801398014080141801428014380144801458014680147801488014980150801518015280153801548015580156801578015880159801608016180162801638016480165801668016780168801698017080171801728017380174801758017680177801788017980180801818018280183801848018580186801878018880189801908019180192801938019480195801968019780198801998020080201802028020380204802058020680207802088020980210802118021280213802148021580216802178021880219802208022180222802238022480225802268022780228802298023080231802328023380234802358023680237802388023980240802418024280243802448024580246802478024880249802508025180252802538025480255802568025780258802598026080261802628026380264802658026680267802688026980270802718027280273802748027580276802778027880279802808028180282802838028480285802868028780288802898029080291802928029380294802958029680297802988029980300803018030280303803048030580306803078030880309803108031180312803138031480315803168031780318803198032080321803228032380324803258032680327803288032980330803318033280333803348033580336803378033880339803408034180342803438034480345803468034780348803498035080351803528035380354803558035680357803588035980360803618036280363803648036580366803678036880369803708037180372803738037480375803768037780378803798038080381803828038380384803858038680387803888038980390803918039280393803948039580396803978039880399804008040180402804038040480405804068040780408804098041080411804128041380414804158041680417804188041980420804218042280423804248042580426804278042880429804308043180432804338043480435804368043780438804398044080441804428044380444804458044680447804488044980450804518045280453804548045580456804578045880459804608046180462804638046480465804668046780468804698047080471804728047380474804758047680477804788047980480804818048280483804848048580486804878048880489804908049180492804938049480495804968049780498804998050080501805028050380504805058050680507805088050980510805118051280513805148051580516805178051880519805208052180522805238052480525805268052780528805298053080531805328053380534805358053680537805388053980540805418054280543805448054580546805478054880549805508055180552805538055480555805568055780558805598056080561805628056380564805658056680567805688056980570805718057280573805748057580576805778057880579805808058180582805838058480585805868058780588805898059080591805928059380594805958059680597805988059980600806018060280603806048060580606806078060880609806108061180612806138061480615806168061780618806198062080621806228062380624806258062680627806288062980630806318063280633806348063580636806378063880639806408064180642806438064480645806468064780648806498065080651806528065380654806558065680657806588065980660806618066280663806648066580666806678066880669806708067180672806738067480675806768067780678806798068080681806828068380684806858068680687806888068980690806918069280693806948069580696806978069880699807008070180702807038070480705807068070780708807098071080711807128071380714807158071680717807188071980720807218072280723807248072580726807278072880729807308073180732807338073480735807368073780738807398074080741807428074380744807458074680747807488074980750807518075280753807548075580756807578075880759807608076180762807638076480765807668076780768807698077080771807728077380774807758077680777807788077980780807818078280783807848078580786807878078880789807908079180792807938079480795807968079780798807998080080801808028080380804808058080680807808088080980810808118081280813808148081580816808178081880819808208082180822808238082480825808268082780828808298083080831808328083380834808358083680837808388083980840808418084280843808448084580846808478084880849808508085180852808538085480855808568085780858808598086080861808628086380864808658086680867808688086980870808718087280873808748087580876808778087880879808808088180882808838088480885808868088780888808898089080891808928089380894808958089680897808988089980900809018090280903809048090580906809078090880909809108091180912809138091480915809168091780918809198092080921809228092380924809258092680927809288092980930809318093280933809348093580936809378093880939809408094180942809438094480945809468094780948809498095080951809528095380954809558095680957809588095980960809618096280963809648096580966809678096880969809708097180972809738097480975809768097780978809798098080981809828098380984809858098680987809888098980990809918099280993809948099580996809978099880999810008100181002810038100481005810068100781008810098101081011810128101381014810158101681017810188101981020810218102281023810248102581026810278102881029810308103181032810338103481035810368103781038810398104081041810428104381044810458104681047810488104981050810518105281053810548105581056810578105881059810608106181062810638106481065810668106781068810698107081071810728107381074810758107681077810788107981080810818108281083810848108581086810878108881089810908109181092810938109481095810968109781098810998110081101811028110381104811058110681107811088110981110811118111281113811148111581116811178111881119811208112181122811238112481125811268112781128811298113081131811328113381134811358113681137811388113981140811418114281143811448114581146811478114881149811508115181152811538115481155811568115781158811598116081161811628116381164811658116681167811688116981170811718117281173811748117581176811778117881179811808118181182811838118481185811868118781188811898119081191811928119381194811958119681197811988119981200812018120281203812048120581206812078120881209812108121181212812138121481215812168121781218812198122081221812228122381224812258122681227812288122981230812318123281233812348123581236812378123881239812408124181242812438124481245812468124781248812498125081251812528125381254812558125681257812588125981260812618126281263812648126581266812678126881269812708127181272812738127481275812768127781278812798128081281812828128381284812858128681287812888128981290812918129281293812948129581296812978129881299813008130181302813038130481305813068130781308813098131081311813128131381314813158131681317813188131981320813218132281323813248132581326813278132881329813308133181332813338133481335813368133781338813398134081341813428134381344813458134681347813488134981350813518135281353813548135581356813578135881359813608136181362813638136481365813668136781368813698137081371813728137381374813758137681377813788137981380813818138281383813848138581386813878138881389813908139181392813938139481395813968139781398813998140081401814028140381404814058140681407814088140981410814118141281413814148141581416814178141881419814208142181422814238142481425814268142781428814298143081431814328143381434814358143681437814388143981440814418144281443814448144581446814478144881449814508145181452814538145481455814568145781458814598146081461814628146381464814658146681467814688146981470814718147281473814748147581476814778147881479814808148181482814838148481485814868148781488814898149081491814928149381494814958149681497814988149981500815018150281503815048150581506815078150881509815108151181512815138151481515815168151781518815198152081521815228152381524815258152681527815288152981530815318153281533815348153581536815378153881539815408154181542815438154481545815468154781548815498155081551815528155381554815558155681557815588155981560815618156281563815648156581566815678156881569815708157181572815738157481575815768157781578815798158081581815828158381584815858158681587815888158981590815918159281593815948159581596815978159881599816008160181602816038160481605816068160781608816098161081611816128161381614816158161681617816188161981620816218162281623816248162581626816278162881629816308163181632816338163481635816368163781638816398164081641816428164381644816458164681647816488164981650816518165281653816548165581656816578165881659816608166181662816638166481665816668166781668816698167081671816728167381674816758167681677816788167981680816818168281683816848168581686816878168881689816908169181692816938169481695816968169781698816998170081701817028170381704817058170681707817088170981710817118171281713817148171581716817178171881719817208172181722817238172481725817268172781728817298173081731817328173381734817358173681737817388173981740817418174281743817448174581746817478174881749817508175181752817538175481755817568175781758817598176081761817628176381764817658176681767817688176981770817718177281773817748177581776817778177881779817808178181782817838178481785817868178781788817898179081791817928179381794817958179681797817988179981800818018180281803818048180581806818078180881809818108181181812818138181481815818168181781818818198182081821818228182381824818258182681827818288182981830818318183281833818348183581836818378183881839818408184181842818438184481845818468184781848818498185081851818528185381854818558185681857818588185981860818618186281863818648186581866818678186881869818708187181872818738187481875818768187781878818798188081881818828188381884818858188681887818888188981890818918189281893818948189581896818978189881899819008190181902819038190481905819068190781908819098191081911819128191381914819158191681917819188191981920819218192281923819248192581926819278192881929819308193181932819338193481935819368193781938819398194081941819428194381944819458194681947819488194981950819518195281953819548195581956819578195881959819608196181962819638196481965819668196781968819698197081971819728197381974819758197681977819788197981980819818198281983819848198581986819878198881989819908199181992819938199481995819968199781998819998200082001820028200382004820058200682007820088200982010820118201282013820148201582016820178201882019820208202182022820238202482025820268202782028820298203082031820328203382034820358203682037820388203982040820418204282043820448204582046820478204882049820508205182052820538205482055820568205782058820598206082061820628206382064820658206682067820688206982070820718207282073820748207582076820778207882079820808208182082820838208482085820868208782088820898209082091820928209382094820958209682097820988209982100821018210282103821048210582106821078210882109821108211182112821138211482115821168211782118821198212082121821228212382124821258212682127821288212982130821318213282133821348213582136821378213882139821408214182142821438214482145821468214782148821498215082151821528215382154821558215682157821588215982160821618216282163821648216582166821678216882169821708217182172821738217482175821768217782178821798218082181821828218382184821858218682187821888218982190821918219282193821948219582196821978219882199822008220182202822038220482205822068220782208822098221082211822128221382214822158221682217822188221982220822218222282223822248222582226822278222882229822308223182232822338223482235822368223782238822398224082241822428224382244822458224682247822488224982250822518225282253822548225582256822578225882259822608226182262822638226482265822668226782268822698227082271822728227382274822758227682277822788227982280822818228282283822848228582286822878228882289822908229182292822938229482295822968229782298822998230082301823028230382304823058230682307823088230982310823118231282313823148231582316823178231882319823208232182322823238232482325823268232782328823298233082331823328233382334823358233682337823388233982340823418234282343823448234582346823478234882349823508235182352823538235482355823568235782358823598236082361823628236382364823658236682367823688236982370823718237282373823748237582376823778237882379823808238182382823838238482385823868238782388823898239082391823928239382394823958239682397823988239982400824018240282403824048240582406824078240882409824108241182412824138241482415824168241782418824198242082421824228242382424824258242682427824288242982430824318243282433824348243582436824378243882439824408244182442824438244482445824468244782448824498245082451824528245382454824558245682457824588245982460824618246282463824648246582466824678246882469824708247182472824738247482475824768247782478824798248082481824828248382484824858248682487824888248982490824918249282493824948249582496824978249882499825008250182502825038250482505825068250782508825098251082511825128251382514825158251682517825188251982520825218252282523825248252582526825278252882529825308253182532825338253482535825368253782538825398254082541825428254382544825458254682547825488254982550825518255282553825548255582556825578255882559825608256182562825638256482565825668256782568825698257082571825728257382574825758257682577825788257982580825818258282583825848258582586825878258882589825908259182592825938259482595825968259782598825998260082601826028260382604826058260682607826088260982610826118261282613826148261582616826178261882619826208262182622826238262482625826268262782628826298263082631826328263382634826358263682637826388263982640826418264282643826448264582646826478264882649826508265182652826538265482655826568265782658826598266082661826628266382664826658266682667826688266982670826718267282673826748267582676826778267882679826808268182682826838268482685826868268782688826898269082691826928269382694826958269682697826988269982700827018270282703827048270582706827078270882709827108271182712827138271482715827168271782718827198272082721827228272382724827258272682727827288272982730827318273282733827348273582736827378273882739827408274182742827438274482745827468274782748827498275082751827528275382754827558275682757827588275982760827618276282763827648276582766827678276882769827708277182772827738277482775827768277782778827798278082781827828278382784827858278682787827888278982790827918279282793827948279582796827978279882799828008280182802828038280482805828068280782808828098281082811828128281382814828158281682817828188281982820828218282282823828248282582826828278282882829828308283182832828338283482835828368283782838828398284082841828428284382844828458284682847828488284982850828518285282853828548285582856828578285882859828608286182862828638286482865828668286782868828698287082871828728287382874828758287682877828788287982880828818288282883828848288582886828878288882889828908289182892828938289482895828968289782898828998290082901829028290382904829058290682907829088290982910829118291282913829148291582916829178291882919829208292182922829238292482925829268292782928829298293082931829328293382934829358293682937829388293982940829418294282943829448294582946829478294882949829508295182952829538295482955829568295782958829598296082961829628296382964829658296682967829688296982970829718297282973829748297582976829778297882979829808298182982829838298482985829868298782988829898299082991829928299382994829958299682997829988299983000830018300283003830048300583006830078300883009830108301183012830138301483015830168301783018830198302083021830228302383024830258302683027830288302983030830318303283033830348303583036830378303883039830408304183042830438304483045830468304783048830498305083051830528305383054830558305683057830588305983060830618306283063830648306583066830678306883069830708307183072830738307483075830768307783078830798308083081830828308383084830858308683087830888308983090830918309283093830948309583096830978309883099831008310183102831038310483105831068310783108831098311083111831128311383114831158311683117831188311983120831218312283123831248312583126831278312883129831308313183132831338313483135831368313783138831398314083141831428314383144831458314683147831488314983150831518315283153831548315583156831578315883159831608316183162831638316483165831668316783168831698317083171831728317383174831758317683177831788317983180831818318283183831848318583186831878318883189831908319183192831938319483195831968319783198831998320083201832028320383204832058320683207832088320983210832118321283213832148321583216832178321883219832208322183222832238322483225832268322783228832298323083231832328323383234832358323683237832388323983240832418324283243832448324583246832478324883249832508325183252832538325483255832568325783258832598326083261832628326383264832658326683267832688326983270832718327283273832748327583276832778327883279832808328183282832838328483285832868328783288832898329083291832928329383294832958329683297832988329983300833018330283303833048330583306833078330883309833108331183312833138331483315833168331783318833198332083321833228332383324833258332683327833288332983330833318333283333833348333583336833378333883339833408334183342833438334483345833468334783348833498335083351833528335383354833558335683357833588335983360833618336283363833648336583366833678336883369833708337183372833738337483375833768337783378833798338083381833828338383384833858338683387833888338983390833918339283393833948339583396833978339883399834008340183402834038340483405834068340783408834098341083411834128341383414834158341683417834188341983420834218342283423834248342583426834278342883429834308343183432834338343483435834368343783438834398344083441834428344383444834458344683447834488344983450834518345283453834548345583456834578345883459834608346183462834638346483465834668346783468834698347083471834728347383474834758347683477834788347983480834818348283483834848348583486834878348883489834908349183492834938349483495834968349783498834998350083501835028350383504835058350683507835088350983510835118351283513835148351583516835178351883519835208352183522835238352483525835268352783528835298353083531835328353383534835358353683537835388353983540835418354283543835448354583546835478354883549835508355183552835538355483555835568355783558835598356083561835628356383564835658356683567835688356983570835718357283573835748357583576835778357883579835808358183582835838358483585835868358783588835898359083591835928359383594835958359683597835988359983600836018360283603836048360583606836078360883609836108361183612836138361483615836168361783618836198362083621836228362383624836258362683627836288362983630836318363283633836348363583636836378363883639836408364183642836438364483645836468364783648836498365083651836528365383654836558365683657836588365983660836618366283663836648366583666836678366883669836708367183672836738367483675836768367783678836798368083681836828368383684836858368683687836888368983690836918369283693836948369583696836978369883699837008370183702837038370483705837068370783708837098371083711837128371383714837158371683717837188371983720837218372283723837248372583726837278372883729837308373183732837338373483735837368373783738837398374083741837428374383744837458374683747837488374983750837518375283753837548375583756837578375883759837608376183762837638376483765837668376783768837698377083771837728377383774837758377683777837788377983780837818378283783837848378583786837878378883789837908379183792837938379483795837968379783798837998380083801838028380383804838058380683807838088380983810838118381283813838148381583816838178381883819838208382183822838238382483825838268382783828838298383083831838328383383834838358383683837838388383983840838418384283843838448384583846838478384883849838508385183852838538385483855838568385783858838598386083861838628386383864838658386683867838688386983870838718387283873838748387583876838778387883879838808388183882838838388483885838868388783888838898389083891838928389383894838958389683897838988389983900839018390283903839048390583906839078390883909839108391183912839138391483915839168391783918839198392083921839228392383924839258392683927839288392983930839318393283933839348393583936839378393883939839408394183942839438394483945839468394783948839498395083951839528395383954839558395683957839588395983960839618396283963839648396583966839678396883969839708397183972839738397483975839768397783978839798398083981839828398383984839858398683987839888398983990839918399283993839948399583996839978399883999840008400184002840038400484005840068400784008840098401084011840128401384014840158401684017840188401984020840218402284023840248402584026840278402884029840308403184032840338403484035840368403784038840398404084041840428404384044840458404684047840488404984050840518405284053840548405584056840578405884059840608406184062840638406484065840668406784068840698407084071840728407384074840758407684077840788407984080840818408284083840848408584086840878408884089840908409184092840938409484095840968409784098840998410084101841028410384104841058410684107841088410984110841118411284113841148411584116841178411884119841208412184122841238412484125841268412784128841298413084131841328413384134841358413684137841388413984140841418414284143841448414584146841478414884149841508415184152841538415484155841568415784158841598416084161841628416384164841658416684167841688416984170841718417284173841748417584176841778417884179841808418184182841838418484185841868418784188841898419084191841928419384194841958419684197841988419984200842018420284203842048420584206842078420884209842108421184212842138421484215842168421784218842198422084221842228422384224842258422684227842288422984230842318423284233842348423584236842378423884239842408424184242842438424484245842468424784248842498425084251842528425384254842558425684257842588425984260842618426284263842648426584266842678426884269842708427184272842738427484275842768427784278842798428084281842828428384284842858428684287842888428984290842918429284293842948429584296842978429884299843008430184302843038430484305843068430784308843098431084311843128431384314843158431684317843188431984320843218432284323843248432584326843278432884329843308433184332843338433484335843368433784338843398434084341843428434384344843458434684347843488434984350843518435284353843548435584356843578435884359843608436184362843638436484365843668436784368843698437084371843728437384374843758437684377843788437984380843818438284383843848438584386843878438884389843908439184392843938439484395843968439784398843998440084401844028440384404844058440684407844088440984410844118441284413844148441584416844178441884419844208442184422844238442484425844268442784428844298443084431844328443384434844358443684437844388443984440844418444284443844448444584446844478444884449844508445184452844538445484455844568445784458844598446084461844628446384464844658446684467844688446984470844718447284473844748447584476844778447884479844808448184482844838448484485844868448784488844898449084491844928449384494844958449684497844988449984500845018450284503845048450584506845078450884509845108451184512845138451484515845168451784518845198452084521845228452384524845258452684527845288452984530845318453284533845348453584536845378453884539845408454184542845438454484545845468454784548845498455084551845528455384554845558455684557845588455984560845618456284563845648456584566845678456884569845708457184572845738457484575845768457784578845798458084581845828458384584845858458684587845888458984590845918459284593845948459584596845978459884599846008460184602846038460484605846068460784608846098461084611846128461384614846158461684617846188461984620846218462284623846248462584626846278462884629846308463184632846338463484635846368463784638846398464084641846428464384644846458464684647846488464984650846518465284653846548465584656846578465884659846608466184662846638466484665846668466784668846698467084671846728467384674846758467684677846788467984680846818468284683846848468584686846878468884689846908469184692846938469484695846968469784698846998470084701847028470384704847058470684707847088470984710847118471284713847148471584716847178471884719847208472184722847238472484725847268472784728847298473084731847328473384734847358473684737847388473984740847418474284743847448474584746847478474884749847508475184752847538475484755847568475784758847598476084761847628476384764847658476684767847688476984770847718477284773847748477584776847778477884779847808478184782847838478484785847868478784788847898479084791847928479384794847958479684797847988479984800848018480284803848048480584806848078480884809848108481184812848138481484815848168481784818848198482084821848228482384824848258482684827848288482984830848318483284833848348483584836848378483884839848408484184842848438484484845848468484784848848498485084851848528485384854848558485684857848588485984860848618486284863848648486584866848678486884869848708487184872848738487484875848768487784878848798488084881848828488384884848858488684887848888488984890848918489284893848948489584896848978489884899849008490184902849038490484905849068490784908849098491084911849128491384914849158491684917849188491984920849218492284923849248492584926849278492884929849308493184932849338493484935849368493784938849398494084941849428494384944849458494684947849488494984950849518495284953849548495584956849578495884959849608496184962849638496484965849668496784968849698497084971849728497384974849758497684977849788497984980849818498284983849848498584986849878498884989849908499184992849938499484995849968499784998849998500085001850028500385004850058500685007850088500985010850118501285013850148501585016850178501885019850208502185022850238502485025850268502785028850298503085031850328503385034850358503685037850388503985040850418504285043850448504585046850478504885049850508505185052850538505485055850568505785058850598506085061850628506385064850658506685067850688506985070850718507285073850748507585076850778507885079850808508185082850838508485085850868508785088850898509085091850928509385094850958509685097850988509985100851018510285103851048510585106851078510885109851108511185112851138511485115851168511785118851198512085121851228512385124851258512685127851288512985130851318513285133851348513585136851378513885139851408514185142851438514485145851468514785148851498515085151851528515385154851558515685157851588515985160851618516285163851648516585166851678516885169851708517185172851738517485175851768517785178851798518085181851828518385184851858518685187851888518985190851918519285193851948519585196851978519885199852008520185202852038520485205852068520785208852098521085211852128521385214852158521685217852188521985220852218522285223852248522585226852278522885229852308523185232852338523485235852368523785238852398524085241852428524385244852458524685247852488524985250852518525285253852548525585256852578525885259852608526185262852638526485265852668526785268852698527085271852728527385274852758527685277852788527985280852818528285283852848528585286852878528885289852908529185292852938529485295852968529785298852998530085301853028530385304853058530685307853088530985310853118531285313853148531585316853178531885319853208532185322853238532485325853268532785328853298533085331853328533385334853358533685337853388533985340853418534285343853448534585346853478534885349853508535185352853538535485355853568535785358853598536085361853628536385364853658536685367853688536985370853718537285373853748537585376853778537885379853808538185382853838538485385853868538785388853898539085391853928539385394853958539685397853988539985400854018540285403854048540585406854078540885409854108541185412854138541485415854168541785418854198542085421854228542385424854258542685427854288542985430854318543285433854348543585436854378543885439854408544185442854438544485445854468544785448854498545085451854528545385454854558545685457854588545985460854618546285463854648546585466854678546885469854708547185472854738547485475854768547785478854798548085481854828548385484854858548685487854888548985490854918549285493854948549585496854978549885499855008550185502855038550485505855068550785508855098551085511855128551385514855158551685517855188551985520855218552285523855248552585526855278552885529855308553185532855338553485535855368553785538855398554085541855428554385544855458554685547855488554985550855518555285553855548555585556855578555885559855608556185562855638556485565855668556785568855698557085571855728557385574855758557685577855788557985580855818558285583855848558585586855878558885589855908559185592855938559485595855968559785598855998560085601856028560385604856058560685607856088560985610856118561285613856148561585616856178561885619856208562185622856238562485625856268562785628856298563085631856328563385634856358563685637856388563985640856418564285643856448564585646856478564885649856508565185652856538565485655856568565785658856598566085661856628566385664856658566685667856688566985670856718567285673856748567585676856778567885679856808568185682856838568485685856868568785688856898569085691856928569385694856958569685697856988569985700857018570285703857048570585706857078570885709857108571185712857138571485715857168571785718857198572085721857228572385724857258572685727857288572985730857318573285733857348573585736857378573885739857408574185742857438574485745857468574785748857498575085751857528575385754857558575685757857588575985760857618576285763857648576585766857678576885769857708577185772857738577485775857768577785778857798578085781857828578385784857858578685787857888578985790857918579285793857948579585796857978579885799858008580185802858038580485805858068580785808858098581085811858128581385814858158581685817858188581985820858218582285823858248582585826858278582885829858308583185832858338583485835858368583785838858398584085841858428584385844858458584685847858488584985850858518585285853858548585585856858578585885859858608586185862858638586485865858668586785868858698587085871858728587385874858758587685877858788587985880858818588285883858848588585886858878588885889858908589185892858938589485895858968589785898858998590085901859028590385904859058590685907859088590985910859118591285913859148591585916859178591885919859208592185922859238592485925859268592785928859298593085931859328593385934859358593685937859388593985940859418594285943859448594585946859478594885949859508595185952859538595485955859568595785958859598596085961859628596385964859658596685967859688596985970859718597285973859748597585976859778597885979859808598185982859838598485985859868598785988859898599085991859928599385994859958599685997859988599986000860018600286003860048600586006860078600886009860108601186012860138601486015860168601786018860198602086021860228602386024860258602686027860288602986030860318603286033860348603586036860378603886039860408604186042860438604486045860468604786048860498605086051860528605386054860558605686057860588605986060860618606286063860648606586066860678606886069860708607186072860738607486075860768607786078860798608086081860828608386084860858608686087860888608986090860918609286093860948609586096860978609886099861008610186102861038610486105861068610786108861098611086111861128611386114861158611686117861188611986120861218612286123861248612586126861278612886129861308613186132861338613486135861368613786138861398614086141861428614386144861458614686147861488614986150861518615286153861548615586156861578615886159861608616186162861638616486165861668616786168861698617086171861728617386174861758617686177861788617986180861818618286183861848618586186861878618886189861908619186192861938619486195861968619786198861998620086201862028620386204862058620686207862088620986210862118621286213862148621586216862178621886219862208622186222862238622486225862268622786228862298623086231862328623386234862358623686237862388623986240862418624286243862448624586246862478624886249862508625186252862538625486255862568625786258862598626086261862628626386264862658626686267862688626986270862718627286273862748627586276862778627886279862808628186282862838628486285862868628786288862898629086291862928629386294862958629686297862988629986300863018630286303863048630586306863078630886309863108631186312863138631486315863168631786318863198632086321863228632386324863258632686327863288632986330863318633286333863348633586336863378633886339863408634186342863438634486345863468634786348863498635086351863528635386354863558635686357863588635986360863618636286363863648636586366863678636886369863708637186372863738637486375863768637786378863798638086381863828638386384863858638686387863888638986390863918639286393863948639586396863978639886399864008640186402864038640486405864068640786408864098641086411864128641386414864158641686417864188641986420864218642286423864248642586426864278642886429864308643186432864338643486435864368643786438864398644086441864428644386444864458644686447864488644986450864518645286453864548645586456864578645886459864608646186462864638646486465864668646786468864698647086471864728647386474864758647686477864788647986480864818648286483864848648586486864878648886489864908649186492864938649486495864968649786498864998650086501865028650386504865058650686507865088650986510865118651286513865148651586516865178651886519865208652186522865238652486525865268652786528865298653086531865328653386534865358653686537865388653986540865418654286543865448654586546865478654886549865508655186552865538655486555865568655786558865598656086561865628656386564865658656686567865688656986570865718657286573865748657586576865778657886579865808658186582865838658486585865868658786588865898659086591865928659386594865958659686597865988659986600866018660286603866048660586606866078660886609866108661186612866138661486615866168661786618866198662086621866228662386624866258662686627866288662986630866318663286633866348663586636866378663886639866408664186642866438664486645866468664786648866498665086651866528665386654866558665686657866588665986660866618666286663866648666586666866678666886669866708667186672866738667486675866768667786678866798668086681866828668386684866858668686687866888668986690866918669286693866948669586696866978669886699867008670186702867038670486705867068670786708867098671086711867128671386714867158671686717867188671986720867218672286723867248672586726867278672886729867308673186732867338673486735867368673786738867398674086741867428674386744867458674686747867488674986750867518675286753867548675586756867578675886759867608676186762867638676486765867668676786768867698677086771867728677386774867758677686777867788677986780867818678286783867848678586786867878678886789867908679186792867938679486795867968679786798867998680086801868028680386804868058680686807868088680986810868118681286813868148681586816868178681886819868208682186822868238682486825868268682786828868298683086831868328683386834868358683686837868388683986840868418684286843868448684586846868478684886849868508685186852868538685486855868568685786858868598686086861868628686386864868658686686867868688686986870868718687286873868748687586876868778687886879868808688186882868838688486885868868688786888868898689086891868928689386894868958689686897868988689986900869018690286903869048690586906869078690886909869108691186912869138691486915869168691786918869198692086921869228692386924869258692686927869288692986930869318693286933869348693586936869378693886939869408694186942869438694486945869468694786948869498695086951869528695386954869558695686957869588695986960869618696286963869648696586966869678696886969869708697186972869738697486975869768697786978869798698086981869828698386984869858698686987869888698986990869918699286993869948699586996869978699886999870008700187002870038700487005870068700787008870098701087011870128701387014870158701687017870188701987020870218702287023870248702587026870278702887029870308703187032870338703487035870368703787038870398704087041870428704387044870458704687047870488704987050870518705287053870548705587056870578705887059870608706187062870638706487065870668706787068870698707087071870728707387074870758707687077870788707987080870818708287083870848708587086870878708887089870908709187092870938709487095870968709787098870998710087101871028710387104871058710687107871088710987110871118711287113871148711587116871178711887119871208712187122871238712487125871268712787128871298713087131871328713387134871358713687137871388713987140871418714287143871448714587146871478714887149871508715187152871538715487155871568715787158871598716087161871628716387164871658716687167871688716987170871718717287173871748717587176871778717887179871808718187182871838718487185871868718787188871898719087191871928719387194871958719687197871988719987200872018720287203872048720587206872078720887209872108721187212872138721487215872168721787218872198722087221872228722387224872258722687227872288722987230872318723287233872348723587236872378723887239872408724187242872438724487245872468724787248872498725087251872528725387254872558725687257872588725987260872618726287263872648726587266872678726887269872708727187272872738727487275872768727787278872798728087281872828728387284872858728687287872888728987290872918729287293872948729587296872978729887299873008730187302873038730487305873068730787308873098731087311873128731387314873158731687317873188731987320873218732287323873248732587326873278732887329873308733187332873338733487335873368733787338873398734087341873428734387344873458734687347873488734987350873518735287353873548735587356873578735887359873608736187362873638736487365873668736787368873698737087371873728737387374873758737687377873788737987380873818738287383873848738587386873878738887389873908739187392873938739487395873968739787398873998740087401874028740387404874058740687407874088740987410874118741287413874148741587416874178741887419874208742187422874238742487425874268742787428874298743087431874328743387434874358743687437874388743987440874418744287443874448744587446874478744887449874508745187452874538745487455874568745787458874598746087461874628746387464874658746687467874688746987470874718747287473874748747587476874778747887479874808748187482874838748487485874868748787488874898749087491874928749387494874958749687497874988749987500875018750287503875048750587506875078750887509875108751187512875138751487515875168751787518875198752087521875228752387524875258752687527875288752987530875318753287533875348753587536875378753887539875408754187542875438754487545875468754787548875498755087551875528755387554875558755687557875588755987560875618756287563875648756587566875678756887569875708757187572875738757487575875768757787578875798758087581875828758387584875858758687587875888758987590875918759287593875948759587596875978759887599876008760187602876038760487605876068760787608876098761087611876128761387614876158761687617876188761987620876218762287623876248762587626876278762887629876308763187632876338763487635876368763787638876398764087641876428764387644876458764687647876488764987650876518765287653876548765587656876578765887659876608766187662876638766487665876668766787668876698767087671876728767387674876758767687677876788767987680876818768287683876848768587686876878768887689876908769187692876938769487695876968769787698876998770087701877028770387704877058770687707877088770987710877118771287713877148771587716877178771887719877208772187722877238772487725877268772787728877298773087731877328773387734877358773687737877388773987740877418774287743877448774587746877478774887749877508775187752877538775487755877568775787758877598776087761877628776387764877658776687767877688776987770877718777287773877748777587776877778777887779877808778187782877838778487785877868778787788877898779087791877928779387794877958779687797877988779987800878018780287803878048780587806878078780887809878108781187812878138781487815878168781787818878198782087821878228782387824878258782687827878288782987830878318783287833878348783587836878378783887839878408784187842878438784487845878468784787848878498785087851878528785387854878558785687857878588785987860878618786287863878648786587866878678786887869878708787187872878738787487875878768787787878878798788087881878828788387884878858788687887878888788987890878918789287893878948789587896878978789887899879008790187902879038790487905879068790787908879098791087911879128791387914879158791687917879188791987920879218792287923879248792587926879278792887929879308793187932879338793487935879368793787938879398794087941879428794387944879458794687947879488794987950879518795287953879548795587956879578795887959879608796187962879638796487965879668796787968879698797087971879728797387974879758797687977879788797987980879818798287983879848798587986879878798887989879908799187992879938799487995879968799787998879998800088001880028800388004880058800688007880088800988010880118801288013880148801588016880178801888019880208802188022880238802488025880268802788028880298803088031880328803388034880358803688037880388803988040880418804288043880448804588046880478804888049880508805188052880538805488055880568805788058880598806088061880628806388064880658806688067880688806988070880718807288073880748807588076880778807888079880808808188082880838808488085880868808788088880898809088091880928809388094880958809688097880988809988100881018810288103881048810588106881078810888109881108811188112881138811488115881168811788118881198812088121881228812388124881258812688127881288812988130881318813288133881348813588136881378813888139881408814188142881438814488145881468814788148881498815088151881528815388154881558815688157881588815988160881618816288163881648816588166881678816888169881708817188172881738817488175881768817788178881798818088181881828818388184881858818688187881888818988190881918819288193881948819588196881978819888199882008820188202882038820488205882068820788208882098821088211882128821388214882158821688217882188821988220882218822288223882248822588226882278822888229882308823188232882338823488235882368823788238882398824088241882428824388244882458824688247882488824988250882518825288253882548825588256882578825888259882608826188262882638826488265882668826788268882698827088271882728827388274882758827688277882788827988280882818828288283882848828588286882878828888289882908829188292882938829488295882968829788298882998830088301883028830388304883058830688307883088830988310883118831288313883148831588316883178831888319883208832188322883238832488325883268832788328883298833088331883328833388334883358833688337883388833988340883418834288343883448834588346883478834888349883508835188352883538835488355883568835788358883598836088361883628836388364883658836688367883688836988370883718837288373883748837588376883778837888379883808838188382883838838488385883868838788388883898839088391883928839388394883958839688397883988839988400884018840288403884048840588406884078840888409884108841188412884138841488415884168841788418884198842088421884228842388424884258842688427884288842988430884318843288433884348843588436884378843888439884408844188442884438844488445884468844788448884498845088451884528845388454884558845688457884588845988460884618846288463884648846588466884678846888469884708847188472884738847488475884768847788478884798848088481884828848388484884858848688487884888848988490884918849288493884948849588496884978849888499885008850188502885038850488505885068850788508885098851088511885128851388514885158851688517885188851988520885218852288523885248852588526885278852888529885308853188532885338853488535885368853788538885398854088541885428854388544885458854688547885488854988550885518855288553885548855588556885578855888559885608856188562885638856488565885668856788568885698857088571885728857388574885758857688577885788857988580885818858288583885848858588586885878858888589885908859188592885938859488595885968859788598885998860088601886028860388604886058860688607886088860988610886118861288613886148861588616886178861888619886208862188622886238862488625886268862788628886298863088631886328863388634886358863688637886388863988640886418864288643886448864588646886478864888649886508865188652886538865488655886568865788658886598866088661886628866388664886658866688667886688866988670886718867288673886748867588676886778867888679886808868188682886838868488685886868868788688886898869088691886928869388694886958869688697886988869988700887018870288703887048870588706887078870888709887108871188712887138871488715887168871788718887198872088721887228872388724887258872688727887288872988730887318873288733887348873588736887378873888739887408874188742887438874488745887468874788748887498875088751887528875388754887558875688757887588875988760887618876288763887648876588766887678876888769887708877188772887738877488775887768877788778887798878088781887828878388784887858878688787887888878988790887918879288793887948879588796887978879888799888008880188802888038880488805888068880788808888098881088811888128881388814888158881688817888188881988820888218882288823888248882588826888278882888829888308883188832888338883488835888368883788838888398884088841888428884388844888458884688847888488884988850888518885288853888548885588856888578885888859888608886188862888638886488865888668886788868888698887088871888728887388874888758887688877888788887988880888818888288883888848888588886888878888888889888908889188892888938889488895888968889788898888998890088901889028890388904889058890688907889088890988910889118891288913889148891588916889178891888919889208892188922889238892488925889268892788928889298893088931889328893388934889358893688937889388893988940889418894288943889448894588946889478894888949889508895188952889538895488955889568895788958889598896088961889628896388964889658896688967889688896988970889718897288973889748897588976889778897888979889808898188982889838898488985889868898788988889898899088991889928899388994889958899688997889988899989000890018900289003890048900589006890078900889009890108901189012890138901489015890168901789018890198902089021890228902389024890258902689027890288902989030890318903289033890348903589036890378903889039890408904189042890438904489045890468904789048890498905089051890528905389054890558905689057890588905989060890618906289063890648906589066890678906889069890708907189072890738907489075890768907789078890798908089081890828908389084890858908689087890888908989090890918909289093890948909589096890978909889099891008910189102891038910489105891068910789108891098911089111891128911389114891158911689117891188911989120891218912289123891248912589126891278912889129891308913189132891338913489135891368913789138891398914089141891428914389144891458914689147891488914989150891518915289153891548915589156891578915889159891608916189162891638916489165891668916789168891698917089171891728917389174891758917689177891788917989180891818918289183891848918589186891878918889189891908919189192891938919489195891968919789198891998920089201892028920389204892058920689207892088920989210892118921289213892148921589216892178921889219892208922189222892238922489225892268922789228892298923089231892328923389234892358923689237892388923989240892418924289243892448924589246892478924889249892508925189252892538925489255892568925789258892598926089261892628926389264892658926689267892688926989270892718927289273892748927589276892778927889279892808928189282892838928489285892868928789288892898929089291892928929389294892958929689297892988929989300893018930289303893048930589306893078930889309893108931189312893138931489315893168931789318893198932089321893228932389324893258932689327893288932989330893318933289333893348933589336893378933889339893408934189342893438934489345893468934789348893498935089351893528935389354893558935689357893588935989360893618936289363893648936589366893678936889369893708937189372893738937489375893768937789378893798938089381893828938389384893858938689387893888938989390893918939289393893948939589396893978939889399894008940189402894038940489405894068940789408894098941089411894128941389414894158941689417894188941989420894218942289423894248942589426894278942889429894308943189432894338943489435894368943789438894398944089441894428944389444894458944689447894488944989450894518945289453894548945589456894578945889459894608946189462894638946489465894668946789468894698947089471894728947389474894758947689477894788947989480894818948289483894848948589486894878948889489894908949189492894938949489495894968949789498894998950089501895028950389504895058950689507895088950989510895118951289513895148951589516895178951889519895208952189522895238952489525895268952789528895298953089531895328953389534895358953689537895388953989540895418954289543895448954589546895478954889549895508955189552895538955489555895568955789558895598956089561895628956389564895658956689567895688956989570895718957289573895748957589576895778957889579895808958189582895838958489585895868958789588895898959089591895928959389594895958959689597895988959989600896018960289603896048960589606896078960889609896108961189612896138961489615896168961789618896198962089621896228962389624896258962689627896288962989630896318963289633896348963589636896378963889639896408964189642896438964489645896468964789648896498965089651896528965389654896558965689657896588965989660896618966289663896648966589666896678966889669896708967189672896738967489675896768967789678896798968089681896828968389684896858968689687896888968989690896918969289693896948969589696896978969889699897008970189702897038970489705897068970789708897098971089711897128971389714897158971689717897188971989720897218972289723897248972589726897278972889729897308973189732897338973489735897368973789738897398974089741897428974389744897458974689747897488974989750897518975289753897548975589756897578975889759897608976189762897638976489765897668976789768897698977089771897728977389774897758977689777897788977989780897818978289783897848978589786897878978889789897908979189792897938979489795897968979789798897998980089801898028980389804898058980689807898088980989810898118981289813898148981589816898178981889819898208982189822898238982489825898268982789828898298983089831898328983389834898358983689837898388983989840898418984289843898448984589846898478984889849898508985189852898538985489855898568985789858898598986089861898628986389864898658986689867898688986989870898718987289873898748987589876898778987889879898808988189882898838988489885898868988789888898898989089891898928989389894898958989689897898988989989900899018990289903899048990589906899078990889909899108991189912899138991489915899168991789918899198992089921899228992389924899258992689927899288992989930899318993289933899348993589936899378993889939899408994189942899438994489945899468994789948899498995089951899528995389954899558995689957899588995989960899618996289963899648996589966899678996889969899708997189972899738997489975899768997789978899798998089981899828998389984899858998689987899888998989990899918999289993899948999589996899978999889999900009000190002900039000490005900069000790008900099001090011900129001390014900159001690017900189001990020900219002290023900249002590026900279002890029900309003190032900339003490035900369003790038900399004090041900429004390044900459004690047900489004990050900519005290053900549005590056900579005890059900609006190062900639006490065900669006790068900699007090071900729007390074900759007690077900789007990080900819008290083900849008590086900879008890089900909009190092900939009490095900969009790098900999010090101901029010390104901059010690107901089010990110901119011290113901149011590116901179011890119901209012190122901239012490125901269012790128901299013090131901329013390134901359013690137901389013990140901419014290143901449014590146901479014890149901509015190152901539015490155901569015790158901599016090161901629016390164901659016690167901689016990170901719017290173901749017590176901779017890179901809018190182901839018490185901869018790188901899019090191901929019390194901959019690197901989019990200902019020290203902049020590206902079020890209902109021190212902139021490215902169021790218902199022090221902229022390224902259022690227902289022990230902319023290233902349023590236902379023890239902409024190242902439024490245902469024790248902499025090251902529025390254902559025690257902589025990260902619026290263902649026590266902679026890269902709027190272902739027490275902769027790278902799028090281902829028390284902859028690287902889028990290902919029290293902949029590296902979029890299903009030190302903039030490305903069030790308903099031090311903129031390314903159031690317903189031990320903219032290323903249032590326903279032890329903309033190332903339033490335903369033790338903399034090341903429034390344903459034690347903489034990350903519035290353903549035590356903579035890359903609036190362903639036490365903669036790368903699037090371903729037390374903759037690377903789037990380903819038290383903849038590386903879038890389903909039190392903939039490395903969039790398903999040090401904029040390404904059040690407904089040990410904119041290413904149041590416904179041890419904209042190422904239042490425904269042790428904299043090431904329043390434904359043690437904389043990440904419044290443904449044590446904479044890449904509045190452904539045490455904569045790458904599046090461904629046390464904659046690467904689046990470904719047290473904749047590476904779047890479904809048190482904839048490485904869048790488904899049090491904929049390494904959049690497904989049990500905019050290503905049050590506905079050890509905109051190512905139051490515905169051790518905199052090521905229052390524905259052690527905289052990530905319053290533905349053590536905379053890539905409054190542905439054490545905469054790548905499055090551905529055390554905559055690557905589055990560905619056290563905649056590566905679056890569905709057190572905739057490575905769057790578905799058090581905829058390584905859058690587905889058990590905919059290593905949059590596905979059890599906009060190602906039060490605906069060790608906099061090611906129061390614906159061690617906189061990620906219062290623906249062590626906279062890629906309063190632906339063490635906369063790638906399064090641906429064390644906459064690647906489064990650906519065290653906549065590656906579065890659906609066190662906639066490665906669066790668906699067090671906729067390674906759067690677906789067990680906819068290683906849068590686906879068890689906909069190692906939069490695906969069790698906999070090701907029070390704907059070690707907089070990710907119071290713907149071590716907179071890719907209072190722907239072490725907269072790728907299073090731907329073390734907359073690737907389073990740907419074290743907449074590746907479074890749907509075190752907539075490755907569075790758907599076090761907629076390764907659076690767907689076990770907719077290773907749077590776907779077890779907809078190782907839078490785907869078790788907899079090791907929079390794907959079690797907989079990800908019080290803908049080590806908079080890809908109081190812908139081490815908169081790818908199082090821908229082390824908259082690827908289082990830908319083290833908349083590836908379083890839908409084190842908439084490845908469084790848908499085090851908529085390854908559085690857908589085990860908619086290863908649086590866908679086890869908709087190872908739087490875908769087790878908799088090881908829088390884908859088690887908889088990890908919089290893908949089590896908979089890899909009090190902909039090490905909069090790908909099091090911909129091390914909159091690917909189091990920909219092290923909249092590926909279092890929909309093190932909339093490935909369093790938909399094090941909429094390944909459094690947909489094990950909519095290953909549095590956909579095890959909609096190962909639096490965909669096790968909699097090971909729097390974909759097690977909789097990980909819098290983909849098590986909879098890989909909099190992909939099490995909969099790998909999100091001910029100391004910059100691007910089100991010910119101291013910149101591016910179101891019910209102191022910239102491025910269102791028910299103091031910329103391034910359103691037910389103991040910419104291043910449104591046910479104891049910509105191052910539105491055910569105791058910599106091061910629106391064910659106691067910689106991070910719107291073910749107591076910779107891079910809108191082910839108491085910869108791088910899109091091910929109391094910959109691097910989109991100911019110291103911049110591106911079110891109911109111191112911139111491115911169111791118911199112091121911229112391124911259112691127911289112991130911319113291133911349113591136911379113891139911409114191142911439114491145911469114791148911499115091151911529115391154911559115691157911589115991160911619116291163911649116591166911679116891169911709117191172911739117491175911769117791178911799118091181911829118391184911859118691187911889118991190911919119291193911949119591196911979119891199912009120191202912039120491205912069120791208912099121091211912129121391214912159121691217912189121991220912219122291223912249122591226912279122891229912309123191232912339123491235912369123791238912399124091241912429124391244912459124691247912489124991250912519125291253912549125591256912579125891259912609126191262912639126491265912669126791268912699127091271912729127391274912759127691277912789127991280912819128291283912849128591286912879128891289912909129191292912939129491295912969129791298912999130091301913029130391304913059130691307913089130991310913119131291313913149131591316913179131891319913209132191322913239132491325913269132791328913299133091331913329133391334913359133691337913389133991340913419134291343913449134591346913479134891349913509135191352913539135491355913569135791358913599136091361913629136391364913659136691367913689136991370913719137291373913749137591376913779137891379913809138191382913839138491385913869138791388913899139091391913929139391394913959139691397913989139991400914019140291403914049140591406914079140891409914109141191412914139141491415914169141791418914199142091421914229142391424914259142691427914289142991430914319143291433914349143591436914379143891439914409144191442914439144491445914469144791448914499145091451914529145391454914559145691457914589145991460914619146291463914649146591466914679146891469914709147191472914739147491475914769147791478914799148091481914829148391484914859148691487914889148991490914919149291493914949149591496914979149891499915009150191502915039150491505915069150791508915099151091511915129151391514915159151691517915189151991520915219152291523915249152591526915279152891529915309153191532915339153491535915369153791538915399154091541915429154391544915459154691547915489154991550915519155291553915549155591556915579155891559915609156191562915639156491565915669156791568915699157091571915729157391574915759157691577915789157991580915819158291583915849158591586915879158891589915909159191592915939159491595915969159791598915999160091601916029160391604916059160691607916089160991610916119161291613916149161591616916179161891619916209162191622916239162491625916269162791628916299163091631916329163391634916359163691637916389163991640916419164291643916449164591646916479164891649916509165191652916539165491655916569165791658916599166091661916629166391664916659166691667916689166991670916719167291673916749167591676916779167891679916809168191682916839168491685916869168791688916899169091691916929169391694916959169691697916989169991700917019170291703917049170591706917079170891709917109171191712917139171491715917169171791718917199172091721917229172391724917259172691727917289172991730917319173291733917349173591736917379173891739917409174191742917439174491745917469174791748917499175091751917529175391754917559175691757917589175991760917619176291763917649176591766917679176891769917709177191772917739177491775917769177791778917799178091781917829178391784917859178691787917889178991790917919179291793917949179591796917979179891799918009180191802918039180491805918069180791808918099181091811918129181391814918159181691817918189181991820918219182291823918249182591826918279182891829918309183191832918339183491835918369183791838918399184091841918429184391844918459184691847918489184991850918519185291853918549185591856918579185891859918609186191862918639186491865918669186791868918699187091871918729187391874918759187691877918789187991880918819188291883918849188591886918879188891889918909189191892918939189491895918969189791898918999190091901919029190391904919059190691907919089190991910919119191291913919149191591916919179191891919919209192191922919239192491925919269192791928919299193091931919329193391934919359193691937919389193991940919419194291943919449194591946919479194891949919509195191952919539195491955919569195791958919599196091961919629196391964919659196691967919689196991970919719197291973919749197591976919779197891979919809198191982919839198491985919869198791988919899199091991919929199391994919959199691997919989199992000920019200292003920049200592006920079200892009920109201192012920139201492015920169201792018920199202092021920229202392024920259202692027920289202992030920319203292033920349203592036920379203892039920409204192042920439204492045920469204792048920499205092051920529205392054920559205692057920589205992060920619206292063920649206592066920679206892069920709207192072920739207492075920769207792078920799208092081920829208392084920859208692087920889208992090920919209292093920949209592096920979209892099921009210192102921039210492105921069210792108921099211092111921129211392114921159211692117921189211992120921219212292123921249212592126921279212892129921309213192132921339213492135921369213792138921399214092141921429214392144921459214692147921489214992150921519215292153921549215592156921579215892159921609216192162921639216492165921669216792168921699217092171921729217392174921759217692177921789217992180921819218292183921849218592186921879218892189921909219192192921939219492195921969219792198921999220092201922029220392204922059220692207922089220992210922119221292213922149221592216922179221892219922209222192222922239222492225922269222792228922299223092231922329223392234922359223692237922389223992240922419224292243922449224592246922479224892249922509225192252922539225492255922569225792258922599226092261922629226392264922659226692267922689226992270922719227292273922749227592276922779227892279922809228192282922839228492285922869228792288922899229092291922929229392294922959229692297922989229992300923019230292303923049230592306923079230892309923109231192312923139231492315923169231792318923199232092321923229232392324923259232692327923289232992330923319233292333923349233592336923379233892339923409234192342923439234492345923469234792348923499235092351923529235392354923559235692357923589235992360923619236292363923649236592366923679236892369923709237192372923739237492375923769237792378923799238092381923829238392384923859238692387923889238992390923919239292393923949239592396923979239892399924009240192402924039240492405924069240792408924099241092411924129241392414924159241692417924189241992420924219242292423924249242592426924279242892429924309243192432924339243492435924369243792438924399244092441924429244392444924459244692447924489244992450924519245292453924549245592456924579245892459924609246192462924639246492465924669246792468924699247092471924729247392474924759247692477924789247992480924819248292483924849248592486924879248892489924909249192492924939249492495924969249792498924999250092501925029250392504925059250692507925089250992510925119251292513925149251592516925179251892519925209252192522925239252492525925269252792528925299253092531925329253392534925359253692537925389253992540925419254292543925449254592546925479254892549925509255192552925539255492555925569255792558925599256092561925629256392564925659256692567925689256992570925719257292573925749257592576925779257892579925809258192582925839258492585925869258792588925899259092591925929259392594925959259692597925989259992600926019260292603926049260592606926079260892609926109261192612926139261492615926169261792618926199262092621926229262392624926259262692627926289262992630926319263292633926349263592636926379263892639926409264192642926439264492645926469264792648926499265092651926529265392654926559265692657926589265992660926619266292663926649266592666926679266892669926709267192672926739267492675926769267792678926799268092681926829268392684926859268692687926889268992690926919269292693926949269592696926979269892699927009270192702927039270492705927069270792708927099271092711927129271392714927159271692717927189271992720927219272292723927249272592726927279272892729927309273192732927339273492735927369273792738927399274092741927429274392744927459274692747927489274992750927519275292753927549275592756927579275892759927609276192762927639276492765927669276792768927699277092771927729277392774927759277692777927789277992780927819278292783927849278592786927879278892789927909279192792927939279492795927969279792798927999280092801928029280392804928059280692807928089280992810928119281292813928149281592816928179281892819928209282192822928239282492825928269282792828928299283092831928329283392834928359283692837928389283992840928419284292843928449284592846928479284892849928509285192852928539285492855928569285792858928599286092861928629286392864928659286692867928689286992870928719287292873928749287592876928779287892879928809288192882928839288492885928869288792888928899289092891928929289392894928959289692897928989289992900929019290292903929049290592906929079290892909929109291192912929139291492915929169291792918929199292092921929229292392924929259292692927929289292992930929319293292933929349293592936929379293892939929409294192942929439294492945929469294792948929499295092951929529295392954929559295692957929589295992960929619296292963929649296592966929679296892969929709297192972929739297492975929769297792978929799298092981929829298392984929859298692987929889298992990929919299292993929949299592996929979299892999930009300193002930039300493005930069300793008930099301093011930129301393014930159301693017930189301993020930219302293023930249302593026930279302893029930309303193032930339303493035930369303793038930399304093041930429304393044930459304693047930489304993050930519305293053930549305593056930579305893059930609306193062930639306493065930669306793068930699307093071930729307393074930759307693077930789307993080930819308293083930849308593086930879308893089930909309193092930939309493095930969309793098930999310093101931029310393104931059310693107931089310993110931119311293113931149311593116931179311893119931209312193122931239312493125931269312793128931299313093131931329313393134931359313693137931389313993140931419314293143931449314593146931479314893149931509315193152931539315493155931569315793158931599316093161931629316393164931659316693167931689316993170931719317293173931749317593176931779317893179931809318193182931839318493185931869318793188931899319093191931929319393194931959319693197931989319993200932019320293203932049320593206932079320893209932109321193212932139321493215932169321793218932199322093221932229322393224932259322693227932289322993230932319323293233932349323593236932379323893239932409324193242932439324493245932469324793248932499325093251932529325393254932559325693257932589325993260932619326293263932649326593266932679326893269932709327193272932739327493275932769327793278932799328093281932829328393284932859328693287932889328993290932919329293293932949329593296932979329893299933009330193302933039330493305933069330793308933099331093311933129331393314933159331693317933189331993320933219332293323933249332593326933279332893329933309333193332933339333493335933369333793338933399334093341933429334393344933459334693347933489334993350933519335293353933549335593356933579335893359933609336193362933639336493365933669336793368933699337093371933729337393374933759337693377933789337993380933819338293383933849338593386933879338893389933909339193392933939339493395933969339793398933999340093401934029340393404934059340693407934089340993410934119341293413934149341593416934179341893419934209342193422934239342493425934269342793428934299343093431934329343393434934359343693437934389343993440934419344293443934449344593446934479344893449934509345193452934539345493455934569345793458934599346093461934629346393464934659346693467934689346993470934719347293473934749347593476934779347893479934809348193482934839348493485934869348793488934899349093491934929349393494934959349693497934989349993500935019350293503935049350593506935079350893509935109351193512935139351493515935169351793518935199352093521935229352393524935259352693527935289352993530935319353293533935349353593536935379353893539935409354193542935439354493545935469354793548935499355093551935529355393554935559355693557935589355993560935619356293563935649356593566935679356893569935709357193572935739357493575935769357793578935799358093581935829358393584935859358693587935889358993590935919359293593935949359593596935979359893599936009360193602936039360493605936069360793608936099361093611936129361393614936159361693617936189361993620936219362293623936249362593626936279362893629936309363193632936339363493635936369363793638936399364093641936429364393644936459364693647936489364993650936519365293653936549365593656936579365893659936609366193662936639366493665936669366793668936699367093671936729367393674936759367693677936789367993680936819368293683936849368593686936879368893689936909369193692936939369493695936969369793698936999370093701937029370393704937059370693707937089370993710937119371293713937149371593716937179371893719937209372193722937239372493725937269372793728937299373093731937329373393734937359373693737937389373993740937419374293743937449374593746937479374893749937509375193752937539375493755937569375793758937599376093761937629376393764937659376693767937689376993770937719377293773937749377593776937779377893779937809378193782937839378493785937869378793788937899379093791937929379393794937959379693797937989379993800938019380293803938049380593806938079380893809938109381193812938139381493815938169381793818938199382093821938229382393824938259382693827938289382993830938319383293833938349383593836938379383893839938409384193842938439384493845938469384793848938499385093851938529385393854938559385693857938589385993860938619386293863938649386593866938679386893869938709387193872938739387493875938769387793878938799388093881938829388393884938859388693887938889388993890938919389293893938949389593896938979389893899939009390193902939039390493905939069390793908939099391093911939129391393914939159391693917939189391993920939219392293923939249392593926939279392893929939309393193932939339393493935939369393793938
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.echarts = {})));
  5. }(this, (function (exports) { 'use strict';
  6. /*
  7. * Licensed to the Apache Software Foundation (ASF) under one
  8. * or more contributor license agreements. See the NOTICE file
  9. * distributed with this work for additional information
  10. * regarding copyright ownership. The ASF licenses this file
  11. * to you under the Apache License, Version 2.0 (the
  12. * "License"); you may not use this file except in compliance
  13. * with the License. You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing,
  18. * software distributed under the License is distributed on an
  19. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20. * KIND, either express or implied. See the License for the
  21. * specific language governing permissions and limitations
  22. * under the License.
  23. */
  24. // (1) The code `if (__DEV__) ...` can be removed by build tool.
  25. // (2) If intend to use `__DEV__`, this module should be imported. Use a global
  26. // variable `__DEV__` may cause that miss the declaration (see #6535), or the
  27. // declaration is behind of the using position (for example in `Model.extent`,
  28. // And tools like rollup can not analysis the dependency if not import).
  29. var dev;
  30. // In browser
  31. if (typeof window !== 'undefined') {
  32. dev = window.__DEV__;
  33. }
  34. // In node
  35. else if (typeof global !== 'undefined') {
  36. dev = global.__DEV__;
  37. }
  38. if (typeof dev === 'undefined') {
  39. dev = true;
  40. }
  41. var __DEV__ = dev;
  42. /**
  43. * zrender: 生成唯一id
  44. *
  45. * @author errorrik (errorrik@gmail.com)
  46. */
  47. var idStart = 0x0907;
  48. var guid = function () {
  49. return idStart++;
  50. };
  51. /**
  52. * echarts设备环境识别
  53. *
  54. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  55. * @author firede[firede@firede.us]
  56. * @desc thanks zepto.
  57. */
  58. var env = {};
  59. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  60. // In Weixin Application
  61. env = {
  62. browser: {},
  63. os: {},
  64. node: false,
  65. wxa: true, // Weixin Application
  66. canvasSupported: true,
  67. svgSupported: false,
  68. touchEventsSupported: true,
  69. domSupported: false
  70. };
  71. }
  72. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  73. // In worker
  74. env = {
  75. browser: {},
  76. os: {},
  77. node: false,
  78. worker: true,
  79. canvasSupported: true,
  80. domSupported: false
  81. };
  82. }
  83. else if (typeof navigator === 'undefined') {
  84. // In node
  85. env = {
  86. browser: {},
  87. os: {},
  88. node: true,
  89. worker: false,
  90. // Assume canvas is supported
  91. canvasSupported: true,
  92. svgSupported: true,
  93. domSupported: false
  94. };
  95. }
  96. else {
  97. env = detect(navigator.userAgent);
  98. }
  99. var env$1 = env;
  100. // Zepto.js
  101. // (c) 2010-2013 Thomas Fuchs
  102. // Zepto.js may be freely distributed under the MIT license.
  103. function detect(ua) {
  104. var os = {};
  105. var browser = {};
  106. // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  107. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  108. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  109. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  110. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  111. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  112. // var touchpad = webos && ua.match(/TouchPad/);
  113. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  114. // var silk = ua.match(/Silk\/([\d._]+)/);
  115. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  116. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  117. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  118. // var playbook = ua.match(/PlayBook/);
  119. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  120. var firefox = ua.match(/Firefox\/([\d.]+)/);
  121. // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  122. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  123. var ie = ua.match(/MSIE\s([\d.]+)/)
  124. // IE 11 Trident/7.0; rv:11.0
  125. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  126. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  127. var weChat = (/micromessenger/i).test(ua);
  128. // Todo: clean this up with a better OS/browser seperation:
  129. // - discern (more) between multiple browsers on android
  130. // - decide if kindle fire in silk mode is android or not
  131. // - Firefox on Android doesn't specify the Android version
  132. // - possibly devide in os, device and browser hashes
  133. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  134. // if (android) os.android = true, os.version = android[2];
  135. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  136. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  137. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  138. // if (webos) os.webos = true, os.version = webos[2];
  139. // if (touchpad) os.touchpad = true;
  140. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  141. // if (bb10) os.bb10 = true, os.version = bb10[2];
  142. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  143. // if (playbook) browser.playbook = true;
  144. // if (kindle) os.kindle = true, os.version = kindle[1];
  145. // if (silk) browser.silk = true, browser.version = silk[1];
  146. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  147. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  148. if (firefox) {
  149. browser.firefox = true;
  150. browser.version = firefox[1];
  151. }
  152. // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  153. // if (webview) browser.webview = true;
  154. if (ie) {
  155. browser.ie = true;
  156. browser.version = ie[1];
  157. }
  158. if (edge) {
  159. browser.edge = true;
  160. browser.version = edge[1];
  161. }
  162. // It is difficult to detect WeChat in Win Phone precisely, because ua can
  163. // not be set on win phone. So we do not consider Win Phone.
  164. if (weChat) {
  165. browser.weChat = true;
  166. }
  167. // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  168. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  169. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  170. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  171. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  172. return {
  173. browser: browser,
  174. os: os,
  175. node: false,
  176. // 原生canvas支持,改极端点了
  177. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  178. canvasSupported: !!document.createElement('canvas').getContext,
  179. svgSupported: typeof SVGRect !== 'undefined',
  180. // works on most browsers
  181. // IE10/11 does not support touch event, and MS Edge supports them but not by
  182. // default, so we dont check navigator.maxTouchPoints for them here.
  183. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  184. // <http://caniuse.com/#search=pointer%20event>.
  185. pointerEventsSupported: 'onpointerdown' in window
  186. // Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  187. // events currently. So we dont use that on other browsers unless tested sufficiently.
  188. // Although IE 10 supports pointer event, it use old style and is different from the
  189. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  190. && (browser.edge || (browser.ie && browser.version >= 11)),
  191. // passiveSupported: detectPassiveSupport()
  192. domSupported: typeof document !== 'undefined'
  193. };
  194. }
  195. // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
  196. // function detectPassiveSupport() {
  197. // // Test via a getter in the options object to see if the passive property is accessed
  198. // var supportsPassive = false;
  199. // try {
  200. // var opts = Object.defineProperty({}, 'passive', {
  201. // get: function() {
  202. // supportsPassive = true;
  203. // }
  204. // });
  205. // window.addEventListener('testPassive', function() {}, opts);
  206. // } catch (e) {
  207. // }
  208. // return supportsPassive;
  209. // }
  210. /**
  211. * @module zrender/core/util
  212. */
  213. // 用于处理merge时无法遍历Date等对象的问题
  214. var BUILTIN_OBJECT = {
  215. '[object Function]': 1,
  216. '[object RegExp]': 1,
  217. '[object Date]': 1,
  218. '[object Error]': 1,
  219. '[object CanvasGradient]': 1,
  220. '[object CanvasPattern]': 1,
  221. // For node-canvas
  222. '[object Image]': 1,
  223. '[object Canvas]': 1
  224. };
  225. var TYPED_ARRAY = {
  226. '[object Int8Array]': 1,
  227. '[object Uint8Array]': 1,
  228. '[object Uint8ClampedArray]': 1,
  229. '[object Int16Array]': 1,
  230. '[object Uint16Array]': 1,
  231. '[object Int32Array]': 1,
  232. '[object Uint32Array]': 1,
  233. '[object Float32Array]': 1,
  234. '[object Float64Array]': 1
  235. };
  236. var objToString = Object.prototype.toString;
  237. var arrayProto = Array.prototype;
  238. var nativeForEach = arrayProto.forEach;
  239. var nativeFilter = arrayProto.filter;
  240. var nativeSlice = arrayProto.slice;
  241. var nativeMap = arrayProto.map;
  242. var nativeReduce = arrayProto.reduce;
  243. // Avoid assign to an exported variable, for transforming to cjs.
  244. var methods = {};
  245. function $override(name, fn) {
  246. // Clear ctx instance for different environment
  247. if (name === 'createCanvas') {
  248. _ctx = null;
  249. }
  250. methods[name] = fn;
  251. }
  252. /**
  253. * Those data types can be cloned:
  254. * Plain object, Array, TypedArray, number, string, null, undefined.
  255. * Those data types will be assgined using the orginal data:
  256. * BUILTIN_OBJECT
  257. * Instance of user defined class will be cloned to a plain object, without
  258. * properties in prototype.
  259. * Other data types is not supported (not sure what will happen).
  260. *
  261. * Caution: do not support clone Date, for performance consideration.
  262. * (There might be a large number of date in `series.data`).
  263. * So date should not be modified in and out of echarts.
  264. *
  265. * @param {*} source
  266. * @return {*} new
  267. */
  268. function clone(source) {
  269. if (source == null || typeof source !== 'object') {
  270. return source;
  271. }
  272. var result = source;
  273. var typeStr = objToString.call(source);
  274. if (typeStr === '[object Array]') {
  275. if (!isPrimitive(source)) {
  276. result = [];
  277. for (var i = 0, len = source.length; i < len; i++) {
  278. result[i] = clone(source[i]);
  279. }
  280. }
  281. }
  282. else if (TYPED_ARRAY[typeStr]) {
  283. if (!isPrimitive(source)) {
  284. var Ctor = source.constructor;
  285. if (source.constructor.from) {
  286. result = Ctor.from(source);
  287. }
  288. else {
  289. result = new Ctor(source.length);
  290. for (var i = 0, len = source.length; i < len; i++) {
  291. result[i] = clone(source[i]);
  292. }
  293. }
  294. }
  295. }
  296. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  297. result = {};
  298. for (var key in source) {
  299. if (source.hasOwnProperty(key)) {
  300. result[key] = clone(source[key]);
  301. }
  302. }
  303. }
  304. return result;
  305. }
  306. /**
  307. * @memberOf module:zrender/core/util
  308. * @param {*} target
  309. * @param {*} source
  310. * @param {boolean} [overwrite=false]
  311. */
  312. function merge(target, source, overwrite) {
  313. // We should escapse that source is string
  314. // and enter for ... in ...
  315. if (!isObject$1(source) || !isObject$1(target)) {
  316. return overwrite ? clone(source) : target;
  317. }
  318. for (var key in source) {
  319. if (source.hasOwnProperty(key)) {
  320. var targetProp = target[key];
  321. var sourceProp = source[key];
  322. if (isObject$1(sourceProp)
  323. && isObject$1(targetProp)
  324. && !isArray(sourceProp)
  325. && !isArray(targetProp)
  326. && !isDom(sourceProp)
  327. && !isDom(targetProp)
  328. && !isBuiltInObject(sourceProp)
  329. && !isBuiltInObject(targetProp)
  330. && !isPrimitive(sourceProp)
  331. && !isPrimitive(targetProp)
  332. ) {
  333. // 如果需要递归覆盖,就递归调用merge
  334. merge(targetProp, sourceProp, overwrite);
  335. }
  336. else if (overwrite || !(key in target)) {
  337. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  338. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  339. target[key] = clone(source[key], true);
  340. }
  341. }
  342. }
  343. return target;
  344. }
  345. /**
  346. * @param {Array} targetAndSources The first item is target, and the rests are source.
  347. * @param {boolean} [overwrite=false]
  348. * @return {*} target
  349. */
  350. function mergeAll(targetAndSources, overwrite) {
  351. var result = targetAndSources[0];
  352. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  353. result = merge(result, targetAndSources[i], overwrite);
  354. }
  355. return result;
  356. }
  357. /**
  358. * @param {*} target
  359. * @param {*} source
  360. * @memberOf module:zrender/core/util
  361. */
  362. function extend(target, source) {
  363. for (var key in source) {
  364. if (source.hasOwnProperty(key)) {
  365. target[key] = source[key];
  366. }
  367. }
  368. return target;
  369. }
  370. /**
  371. * @param {*} target
  372. * @param {*} source
  373. * @param {boolean} [overlay=false]
  374. * @memberOf module:zrender/core/util
  375. */
  376. function defaults(target, source, overlay) {
  377. for (var key in source) {
  378. if (source.hasOwnProperty(key)
  379. && (overlay ? source[key] != null : target[key] == null)
  380. ) {
  381. target[key] = source[key];
  382. }
  383. }
  384. return target;
  385. }
  386. var createCanvas = function () {
  387. return methods.createCanvas();
  388. };
  389. methods.createCanvas = function () {
  390. return document.createElement('canvas');
  391. };
  392. // FIXME
  393. var _ctx;
  394. function getContext() {
  395. if (!_ctx) {
  396. // Use util.createCanvas instead of createCanvas
  397. // because createCanvas may be overwritten in different environment
  398. _ctx = createCanvas().getContext('2d');
  399. }
  400. return _ctx;
  401. }
  402. /**
  403. * 查询数组中元素的index
  404. * @memberOf module:zrender/core/util
  405. */
  406. function indexOf(array, value) {
  407. if (array) {
  408. if (array.indexOf) {
  409. return array.indexOf(value);
  410. }
  411. for (var i = 0, len = array.length; i < len; i++) {
  412. if (array[i] === value) {
  413. return i;
  414. }
  415. }
  416. }
  417. return -1;
  418. }
  419. /**
  420. * 构造类继承关系
  421. *
  422. * @memberOf module:zrender/core/util
  423. * @param {Function} clazz 源类
  424. * @param {Function} baseClazz 基类
  425. */
  426. function inherits(clazz, baseClazz) {
  427. var clazzPrototype = clazz.prototype;
  428. function F() {}
  429. F.prototype = baseClazz.prototype;
  430. clazz.prototype = new F();
  431. for (var prop in clazzPrototype) {
  432. clazz.prototype[prop] = clazzPrototype[prop];
  433. }
  434. clazz.prototype.constructor = clazz;
  435. clazz.superClass = baseClazz;
  436. }
  437. /**
  438. * @memberOf module:zrender/core/util
  439. * @param {Object|Function} target
  440. * @param {Object|Function} sorce
  441. * @param {boolean} overlay
  442. */
  443. function mixin(target, source, overlay) {
  444. target = 'prototype' in target ? target.prototype : target;
  445. source = 'prototype' in source ? source.prototype : source;
  446. defaults(target, source, overlay);
  447. }
  448. /**
  449. * Consider typed array.
  450. * @param {Array|TypedArray} data
  451. */
  452. function isArrayLike(data) {
  453. if (!data) {
  454. return;
  455. }
  456. if (typeof data === 'string') {
  457. return false;
  458. }
  459. return typeof data.length === 'number';
  460. }
  461. /**
  462. * 数组或对象遍历
  463. * @memberOf module:zrender/core/util
  464. * @param {Object|Array} obj
  465. * @param {Function} cb
  466. * @param {*} [context]
  467. */
  468. function each$1(obj, cb, context) {
  469. if (!(obj && cb)) {
  470. return;
  471. }
  472. if (obj.forEach && obj.forEach === nativeForEach) {
  473. obj.forEach(cb, context);
  474. }
  475. else if (obj.length === +obj.length) {
  476. for (var i = 0, len = obj.length; i < len; i++) {
  477. cb.call(context, obj[i], i, obj);
  478. }
  479. }
  480. else {
  481. for (var key in obj) {
  482. if (obj.hasOwnProperty(key)) {
  483. cb.call(context, obj[key], key, obj);
  484. }
  485. }
  486. }
  487. }
  488. /**
  489. * 数组映射
  490. * @memberOf module:zrender/core/util
  491. * @param {Array} obj
  492. * @param {Function} cb
  493. * @param {*} [context]
  494. * @return {Array}
  495. */
  496. function map(obj, cb, context) {
  497. if (!(obj && cb)) {
  498. return;
  499. }
  500. if (obj.map && obj.map === nativeMap) {
  501. return obj.map(cb, context);
  502. }
  503. else {
  504. var result = [];
  505. for (var i = 0, len = obj.length; i < len; i++) {
  506. result.push(cb.call(context, obj[i], i, obj));
  507. }
  508. return result;
  509. }
  510. }
  511. /**
  512. * @memberOf module:zrender/core/util
  513. * @param {Array} obj
  514. * @param {Function} cb
  515. * @param {Object} [memo]
  516. * @param {*} [context]
  517. * @return {Array}
  518. */
  519. function reduce(obj, cb, memo, context) {
  520. if (!(obj && cb)) {
  521. return;
  522. }
  523. if (obj.reduce && obj.reduce === nativeReduce) {
  524. return obj.reduce(cb, memo, context);
  525. }
  526. else {
  527. for (var i = 0, len = obj.length; i < len; i++) {
  528. memo = cb.call(context, memo, obj[i], i, obj);
  529. }
  530. return memo;
  531. }
  532. }
  533. /**
  534. * 数组过滤
  535. * @memberOf module:zrender/core/util
  536. * @param {Array} obj
  537. * @param {Function} cb
  538. * @param {*} [context]
  539. * @return {Array}
  540. */
  541. function filter(obj, cb, context) {
  542. if (!(obj && cb)) {
  543. return;
  544. }
  545. if (obj.filter && obj.filter === nativeFilter) {
  546. return obj.filter(cb, context);
  547. }
  548. else {
  549. var result = [];
  550. for (var i = 0, len = obj.length; i < len; i++) {
  551. if (cb.call(context, obj[i], i, obj)) {
  552. result.push(obj[i]);
  553. }
  554. }
  555. return result;
  556. }
  557. }
  558. /**
  559. * 数组项查找
  560. * @memberOf module:zrender/core/util
  561. * @param {Array} obj
  562. * @param {Function} cb
  563. * @param {*} [context]
  564. * @return {*}
  565. */
  566. function find(obj, cb, context) {
  567. if (!(obj && cb)) {
  568. return;
  569. }
  570. for (var i = 0, len = obj.length; i < len; i++) {
  571. if (cb.call(context, obj[i], i, obj)) {
  572. return obj[i];
  573. }
  574. }
  575. }
  576. /**
  577. * @memberOf module:zrender/core/util
  578. * @param {Function} func
  579. * @param {*} context
  580. * @return {Function}
  581. */
  582. function bind(func, context) {
  583. var args = nativeSlice.call(arguments, 2);
  584. return function () {
  585. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  586. };
  587. }
  588. /**
  589. * @memberOf module:zrender/core/util
  590. * @param {Function} func
  591. * @return {Function}
  592. */
  593. function curry(func) {
  594. var args = nativeSlice.call(arguments, 1);
  595. return function () {
  596. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  597. };
  598. }
  599. /**
  600. * @memberOf module:zrender/core/util
  601. * @param {*} value
  602. * @return {boolean}
  603. */
  604. function isArray(value) {
  605. return objToString.call(value) === '[object Array]';
  606. }
  607. /**
  608. * @memberOf module:zrender/core/util
  609. * @param {*} value
  610. * @return {boolean}
  611. */
  612. function isFunction$1(value) {
  613. return typeof value === 'function';
  614. }
  615. /**
  616. * @memberOf module:zrender/core/util
  617. * @param {*} value
  618. * @return {boolean}
  619. */
  620. function isString(value) {
  621. return objToString.call(value) === '[object String]';
  622. }
  623. /**
  624. * @memberOf module:zrender/core/util
  625. * @param {*} value
  626. * @return {boolean}
  627. */
  628. function isObject$1(value) {
  629. // Avoid a V8 JIT bug in Chrome 19-20.
  630. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  631. var type = typeof value;
  632. return type === 'function' || (!!value && type === 'object');
  633. }
  634. /**
  635. * @memberOf module:zrender/core/util
  636. * @param {*} value
  637. * @return {boolean}
  638. */
  639. function isBuiltInObject(value) {
  640. return !!BUILTIN_OBJECT[objToString.call(value)];
  641. }
  642. /**
  643. * @memberOf module:zrender/core/util
  644. * @param {*} value
  645. * @return {boolean}
  646. */
  647. function isTypedArray(value) {
  648. return !!TYPED_ARRAY[objToString.call(value)];
  649. }
  650. /**
  651. * @memberOf module:zrender/core/util
  652. * @param {*} value
  653. * @return {boolean}
  654. */
  655. function isDom(value) {
  656. return typeof value === 'object'
  657. && typeof value.nodeType === 'number'
  658. && typeof value.ownerDocument === 'object';
  659. }
  660. /**
  661. * Whether is exactly NaN. Notice isNaN('a') returns true.
  662. * @param {*} value
  663. * @return {boolean}
  664. */
  665. function eqNaN(value) {
  666. return value !== value;
  667. }
  668. /**
  669. * If value1 is not null, then return value1, otherwise judget rest of values.
  670. * Low performance.
  671. * @memberOf module:zrender/core/util
  672. * @return {*} Final value
  673. */
  674. function retrieve(values) {
  675. for (var i = 0, len = arguments.length; i < len; i++) {
  676. if (arguments[i] != null) {
  677. return arguments[i];
  678. }
  679. }
  680. }
  681. function retrieve2(value0, value1) {
  682. return value0 != null
  683. ? value0
  684. : value1;
  685. }
  686. function retrieve3(value0, value1, value2) {
  687. return value0 != null
  688. ? value0
  689. : value1 != null
  690. ? value1
  691. : value2;
  692. }
  693. /**
  694. * @memberOf module:zrender/core/util
  695. * @param {Array} arr
  696. * @param {number} startIndex
  697. * @param {number} endIndex
  698. * @return {Array}
  699. */
  700. function slice() {
  701. return Function.call.apply(nativeSlice, arguments);
  702. }
  703. /**
  704. * Normalize css liked array configuration
  705. * e.g.
  706. * 3 => [3, 3, 3, 3]
  707. * [4, 2] => [4, 2, 4, 2]
  708. * [4, 3, 2] => [4, 3, 2, 3]
  709. * @param {number|Array.<number>} val
  710. * @return {Array.<number>}
  711. */
  712. function normalizeCssArray(val) {
  713. if (typeof (val) === 'number') {
  714. return [val, val, val, val];
  715. }
  716. var len = val.length;
  717. if (len === 2) {
  718. // vertical | horizontal
  719. return [val[0], val[1], val[0], val[1]];
  720. }
  721. else if (len === 3) {
  722. // top | horizontal | bottom
  723. return [val[0], val[1], val[2], val[1]];
  724. }
  725. return val;
  726. }
  727. /**
  728. * @memberOf module:zrender/core/util
  729. * @param {boolean} condition
  730. * @param {string} message
  731. */
  732. function assert$1(condition, message) {
  733. if (!condition) {
  734. throw new Error(message);
  735. }
  736. }
  737. /**
  738. * @memberOf module:zrender/core/util
  739. * @param {string} str string to be trimed
  740. * @return {string} trimed string
  741. */
  742. function trim(str) {
  743. if (str == null) {
  744. return null;
  745. }
  746. else if (typeof str.trim === 'function') {
  747. return str.trim();
  748. }
  749. else {
  750. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  751. }
  752. }
  753. var primitiveKey = '__ec_primitive__';
  754. /**
  755. * Set an object as primitive to be ignored traversing children in clone or merge
  756. */
  757. function setAsPrimitive(obj) {
  758. obj[primitiveKey] = true;
  759. }
  760. function isPrimitive(obj) {
  761. return obj[primitiveKey];
  762. }
  763. /**
  764. * @constructor
  765. * @param {Object} obj Only apply `ownProperty`.
  766. */
  767. function HashMap(obj) {
  768. var isArr = isArray(obj);
  769. // Key should not be set on this, otherwise
  770. // methods get/set/... may be overrided.
  771. this.data = {};
  772. var thisMap = this;
  773. (obj instanceof HashMap)
  774. ? obj.each(visit)
  775. : (obj && each$1(obj, visit));
  776. function visit(value, key) {
  777. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  778. }
  779. }
  780. HashMap.prototype = {
  781. constructor: HashMap,
  782. // Do not provide `has` method to avoid defining what is `has`.
  783. // (We usually treat `null` and `undefined` as the same, different
  784. // from ES6 Map).
  785. get: function (key) {
  786. return this.data.hasOwnProperty(key) ? this.data[key] : null;
  787. },
  788. set: function (key, value) {
  789. // Comparing with invocation chaining, `return value` is more commonly
  790. // used in this case: `var someVal = map.set('a', genVal());`
  791. return (this.data[key] = value);
  792. },
  793. // Although util.each can be performed on this hashMap directly, user
  794. // should not use the exposed keys, who are prefixed.
  795. each: function (cb, context) {
  796. context !== void 0 && (cb = bind(cb, context));
  797. for (var key in this.data) {
  798. this.data.hasOwnProperty(key) && cb(this.data[key], key);
  799. }
  800. },
  801. // Do not use this method if performance sensitive.
  802. removeKey: function (key) {
  803. delete this.data[key];
  804. }
  805. };
  806. function createHashMap(obj) {
  807. return new HashMap(obj);
  808. }
  809. function concatArray(a, b) {
  810. var newArray = new a.constructor(a.length + b.length);
  811. for (var i = 0; i < a.length; i++) {
  812. newArray[i] = a[i];
  813. }
  814. var offset = a.length;
  815. for (i = 0; i < b.length; i++) {
  816. newArray[i + offset] = b[i];
  817. }
  818. return newArray;
  819. }
  820. function noop() {}
  821. var zrUtil = (Object.freeze || Object)({
  822. $override: $override,
  823. clone: clone,
  824. merge: merge,
  825. mergeAll: mergeAll,
  826. extend: extend,
  827. defaults: defaults,
  828. createCanvas: createCanvas,
  829. getContext: getContext,
  830. indexOf: indexOf,
  831. inherits: inherits,
  832. mixin: mixin,
  833. isArrayLike: isArrayLike,
  834. each: each$1,
  835. map: map,
  836. reduce: reduce,
  837. filter: filter,
  838. find: find,
  839. bind: bind,
  840. curry: curry,
  841. isArray: isArray,
  842. isFunction: isFunction$1,
  843. isString: isString,
  844. isObject: isObject$1,
  845. isBuiltInObject: isBuiltInObject,
  846. isTypedArray: isTypedArray,
  847. isDom: isDom,
  848. eqNaN: eqNaN,
  849. retrieve: retrieve,
  850. retrieve2: retrieve2,
  851. retrieve3: retrieve3,
  852. slice: slice,
  853. normalizeCssArray: normalizeCssArray,
  854. assert: assert$1,
  855. trim: trim,
  856. setAsPrimitive: setAsPrimitive,
  857. isPrimitive: isPrimitive,
  858. createHashMap: createHashMap,
  859. concatArray: concatArray,
  860. noop: noop
  861. });
  862. var ArrayCtor = typeof Float32Array === 'undefined'
  863. ? Array
  864. : Float32Array;
  865. /**
  866. * 创建一个向量
  867. * @param {number} [x=0]
  868. * @param {number} [y=0]
  869. * @return {Vector2}
  870. */
  871. function create(x, y) {
  872. var out = new ArrayCtor(2);
  873. if (x == null) {
  874. x = 0;
  875. }
  876. if (y == null) {
  877. y = 0;
  878. }
  879. out[0] = x;
  880. out[1] = y;
  881. return out;
  882. }
  883. /**
  884. * 复制向量数据
  885. * @param {Vector2} out
  886. * @param {Vector2} v
  887. * @return {Vector2}
  888. */
  889. function copy(out, v) {
  890. out[0] = v[0];
  891. out[1] = v[1];
  892. return out;
  893. }
  894. /**
  895. * 克隆一个向量
  896. * @param {Vector2} v
  897. * @return {Vector2}
  898. */
  899. function clone$1(v) {
  900. var out = new ArrayCtor(2);
  901. out[0] = v[0];
  902. out[1] = v[1];
  903. return out;
  904. }
  905. /**
  906. * 设置向量的两个项
  907. * @param {Vector2} out
  908. * @param {number} a
  909. * @param {number} b
  910. * @return {Vector2} 结果
  911. */
  912. function set(out, a, b) {
  913. out[0] = a;
  914. out[1] = b;
  915. return out;
  916. }
  917. /**
  918. * 向量相加
  919. * @param {Vector2} out
  920. * @param {Vector2} v1
  921. * @param {Vector2} v2
  922. */
  923. function add(out, v1, v2) {
  924. out[0] = v1[0] + v2[0];
  925. out[1] = v1[1] + v2[1];
  926. return out;
  927. }
  928. /**
  929. * 向量缩放后相加
  930. * @param {Vector2} out
  931. * @param {Vector2} v1
  932. * @param {Vector2} v2
  933. * @param {number} a
  934. */
  935. function scaleAndAdd(out, v1, v2, a) {
  936. out[0] = v1[0] + v2[0] * a;
  937. out[1] = v1[1] + v2[1] * a;
  938. return out;
  939. }
  940. /**
  941. * 向量相减
  942. * @param {Vector2} out
  943. * @param {Vector2} v1
  944. * @param {Vector2} v2
  945. */
  946. function sub(out, v1, v2) {
  947. out[0] = v1[0] - v2[0];
  948. out[1] = v1[1] - v2[1];
  949. return out;
  950. }
  951. /**
  952. * 向量长度
  953. * @param {Vector2} v
  954. * @return {number}
  955. */
  956. function len(v) {
  957. return Math.sqrt(lenSquare(v));
  958. }
  959. var length = len; // jshint ignore:line
  960. /**
  961. * 向量长度平方
  962. * @param {Vector2} v
  963. * @return {number}
  964. */
  965. function lenSquare(v) {
  966. return v[0] * v[0] + v[1] * v[1];
  967. }
  968. var lengthSquare = lenSquare;
  969. /**
  970. * 向量乘法
  971. * @param {Vector2} out
  972. * @param {Vector2} v1
  973. * @param {Vector2} v2
  974. */
  975. function mul(out, v1, v2) {
  976. out[0] = v1[0] * v2[0];
  977. out[1] = v1[1] * v2[1];
  978. return out;
  979. }
  980. /**
  981. * 向量除法
  982. * @param {Vector2} out
  983. * @param {Vector2} v1
  984. * @param {Vector2} v2
  985. */
  986. function div(out, v1, v2) {
  987. out[0] = v1[0] / v2[0];
  988. out[1] = v1[1] / v2[1];
  989. return out;
  990. }
  991. /**
  992. * 向量点乘
  993. * @param {Vector2} v1
  994. * @param {Vector2} v2
  995. * @return {number}
  996. */
  997. function dot(v1, v2) {
  998. return v1[0] * v2[0] + v1[1] * v2[1];
  999. }
  1000. /**
  1001. * 向量缩放
  1002. * @param {Vector2} out
  1003. * @param {Vector2} v
  1004. * @param {number} s
  1005. */
  1006. function scale(out, v, s) {
  1007. out[0] = v[0] * s;
  1008. out[1] = v[1] * s;
  1009. return out;
  1010. }
  1011. /**
  1012. * 向量归一化
  1013. * @param {Vector2} out
  1014. * @param {Vector2} v
  1015. */
  1016. function normalize(out, v) {
  1017. var d = len(v);
  1018. if (d === 0) {
  1019. out[0] = 0;
  1020. out[1] = 0;
  1021. }
  1022. else {
  1023. out[0] = v[0] / d;
  1024. out[1] = v[1] / d;
  1025. }
  1026. return out;
  1027. }
  1028. /**
  1029. * 计算向量间距离
  1030. * @param {Vector2} v1
  1031. * @param {Vector2} v2
  1032. * @return {number}
  1033. */
  1034. function distance(v1, v2) {
  1035. return Math.sqrt(
  1036. (v1[0] - v2[0]) * (v1[0] - v2[0])
  1037. + (v1[1] - v2[1]) * (v1[1] - v2[1])
  1038. );
  1039. }
  1040. var dist = distance;
  1041. /**
  1042. * 向量距离平方
  1043. * @param {Vector2} v1
  1044. * @param {Vector2} v2
  1045. * @return {number}
  1046. */
  1047. function distanceSquare(v1, v2) {
  1048. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  1049. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  1050. }
  1051. var distSquare = distanceSquare;
  1052. /**
  1053. * 求负向量
  1054. * @param {Vector2} out
  1055. * @param {Vector2} v
  1056. */
  1057. function negate(out, v) {
  1058. out[0] = -v[0];
  1059. out[1] = -v[1];
  1060. return out;
  1061. }
  1062. /**
  1063. * 插值两个点
  1064. * @param {Vector2} out
  1065. * @param {Vector2} v1
  1066. * @param {Vector2} v2
  1067. * @param {number} t
  1068. */
  1069. function lerp(out, v1, v2, t) {
  1070. out[0] = v1[0] + t * (v2[0] - v1[0]);
  1071. out[1] = v1[1] + t * (v2[1] - v1[1]);
  1072. return out;
  1073. }
  1074. /**
  1075. * 矩阵左乘向量
  1076. * @param {Vector2} out
  1077. * @param {Vector2} v
  1078. * @param {Vector2} m
  1079. */
  1080. function applyTransform(out, v, m) {
  1081. var x = v[0];
  1082. var y = v[1];
  1083. out[0] = m[0] * x + m[2] * y + m[4];
  1084. out[1] = m[1] * x + m[3] * y + m[5];
  1085. return out;
  1086. }
  1087. /**
  1088. * 求两个向量最小值
  1089. * @param {Vector2} out
  1090. * @param {Vector2} v1
  1091. * @param {Vector2} v2
  1092. */
  1093. function min(out, v1, v2) {
  1094. out[0] = Math.min(v1[0], v2[0]);
  1095. out[1] = Math.min(v1[1], v2[1]);
  1096. return out;
  1097. }
  1098. /**
  1099. * 求两个向量最大值
  1100. * @param {Vector2} out
  1101. * @param {Vector2} v1
  1102. * @param {Vector2} v2
  1103. */
  1104. function max(out, v1, v2) {
  1105. out[0] = Math.max(v1[0], v2[0]);
  1106. out[1] = Math.max(v1[1], v2[1]);
  1107. return out;
  1108. }
  1109. var vector = (Object.freeze || Object)({
  1110. create: create,
  1111. copy: copy,
  1112. clone: clone$1,
  1113. set: set,
  1114. add: add,
  1115. scaleAndAdd: scaleAndAdd,
  1116. sub: sub,
  1117. len: len,
  1118. length: length,
  1119. lenSquare: lenSquare,
  1120. lengthSquare: lengthSquare,
  1121. mul: mul,
  1122. div: div,
  1123. dot: dot,
  1124. scale: scale,
  1125. normalize: normalize,
  1126. distance: distance,
  1127. dist: dist,
  1128. distanceSquare: distanceSquare,
  1129. distSquare: distSquare,
  1130. negate: negate,
  1131. lerp: lerp,
  1132. applyTransform: applyTransform,
  1133. min: min,
  1134. max: max
  1135. });
  1136. // TODO Draggable for group
  1137. // FIXME Draggable on element which has parent rotation or scale
  1138. function Draggable() {
  1139. this.on('mousedown', this._dragStart, this);
  1140. this.on('mousemove', this._drag, this);
  1141. this.on('mouseup', this._dragEnd, this);
  1142. this.on('globalout', this._dragEnd, this);
  1143. // this._dropTarget = null;
  1144. // this._draggingTarget = null;
  1145. // this._x = 0;
  1146. // this._y = 0;
  1147. }
  1148. Draggable.prototype = {
  1149. constructor: Draggable,
  1150. _dragStart: function (e) {
  1151. var draggingTarget = e.target;
  1152. if (draggingTarget && draggingTarget.draggable) {
  1153. this._draggingTarget = draggingTarget;
  1154. draggingTarget.dragging = true;
  1155. this._x = e.offsetX;
  1156. this._y = e.offsetY;
  1157. this.dispatchToElement(param(draggingTarget, e), 'dragstart', e.event);
  1158. }
  1159. },
  1160. _drag: function (e) {
  1161. var draggingTarget = this._draggingTarget;
  1162. if (draggingTarget) {
  1163. var x = e.offsetX;
  1164. var y = e.offsetY;
  1165. var dx = x - this._x;
  1166. var dy = y - this._y;
  1167. this._x = x;
  1168. this._y = y;
  1169. draggingTarget.drift(dx, dy, e);
  1170. this.dispatchToElement(param(draggingTarget, e), 'drag', e.event);
  1171. var dropTarget = this.findHover(x, y, draggingTarget).target;
  1172. var lastDropTarget = this._dropTarget;
  1173. this._dropTarget = dropTarget;
  1174. if (draggingTarget !== dropTarget) {
  1175. if (lastDropTarget && dropTarget !== lastDropTarget) {
  1176. this.dispatchToElement(param(lastDropTarget, e), 'dragleave', e.event);
  1177. }
  1178. if (dropTarget && dropTarget !== lastDropTarget) {
  1179. this.dispatchToElement(param(dropTarget, e), 'dragenter', e.event);
  1180. }
  1181. }
  1182. }
  1183. },
  1184. _dragEnd: function (e) {
  1185. var draggingTarget = this._draggingTarget;
  1186. if (draggingTarget) {
  1187. draggingTarget.dragging = false;
  1188. }
  1189. this.dispatchToElement(param(draggingTarget, e), 'dragend', e.event);
  1190. if (this._dropTarget) {
  1191. this.dispatchToElement(param(this._dropTarget, e), 'drop', e.event);
  1192. }
  1193. this._draggingTarget = null;
  1194. this._dropTarget = null;
  1195. }
  1196. };
  1197. function param(target, e) {
  1198. return {target: target, topTarget: e && e.topTarget};
  1199. }
  1200. /**
  1201. * Event Mixin
  1202. * @module zrender/mixin/Eventful
  1203. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  1204. * pissang (https://www.github.com/pissang)
  1205. */
  1206. var arrySlice = Array.prototype.slice;
  1207. /**
  1208. * Event dispatcher.
  1209. *
  1210. * @alias module:zrender/mixin/Eventful
  1211. * @constructor
  1212. * @param {Object} [eventProcessor] The object eventProcessor is the scope when
  1213. * `eventProcessor.xxx` called.
  1214. * @param {Function} [eventProcessor.normalizeQuery]
  1215. * param: {string|Object} Raw query.
  1216. * return: {string|Object} Normalized query.
  1217. * @param {Function} [eventProcessor.filter] Event will be dispatched only
  1218. * if it returns `true`.
  1219. * param: {string} eventType
  1220. * param: {string|Object} query
  1221. * return: {boolean}
  1222. * @param {Function} [eventProcessor.afterTrigger] Call after all handlers called.
  1223. * param: {string} eventType
  1224. */
  1225. var Eventful = function (eventProcessor) {
  1226. this._$handlers = {};
  1227. this._$eventProcessor = eventProcessor;
  1228. };
  1229. Eventful.prototype = {
  1230. constructor: Eventful,
  1231. /**
  1232. * The handler can only be triggered once, then removed.
  1233. *
  1234. * @param {string} event The event name.
  1235. * @param {string|Object} [query] Condition used on event filter.
  1236. * @param {Function} handler The event handler.
  1237. * @param {Object} context
  1238. */
  1239. one: function (event, query, handler, context) {
  1240. return on(this, event, query, handler, context, true);
  1241. },
  1242. /**
  1243. * Bind a handler.
  1244. *
  1245. * @param {string} event The event name.
  1246. * @param {string|Object} [query] Condition used on event filter.
  1247. * @param {Function} handler The event handler.
  1248. * @param {Object} [context]
  1249. */
  1250. on: function (event, query, handler, context) {
  1251. return on(this, event, query, handler, context, false);
  1252. },
  1253. /**
  1254. * Whether any handler has bound.
  1255. *
  1256. * @param {string} event
  1257. * @return {boolean}
  1258. */
  1259. isSilent: function (event) {
  1260. var _h = this._$handlers;
  1261. return !_h[event] || !_h[event].length;
  1262. },
  1263. /**
  1264. * Unbind a event.
  1265. *
  1266. * @param {string} event The event name.
  1267. * @param {Function} [handler] The event handler.
  1268. */
  1269. off: function (event, handler) {
  1270. var _h = this._$handlers;
  1271. if (!event) {
  1272. this._$handlers = {};
  1273. return this;
  1274. }
  1275. if (handler) {
  1276. if (_h[event]) {
  1277. var newList = [];
  1278. for (var i = 0, l = _h[event].length; i < l; i++) {
  1279. if (_h[event][i].h !== handler) {
  1280. newList.push(_h[event][i]);
  1281. }
  1282. }
  1283. _h[event] = newList;
  1284. }
  1285. if (_h[event] && _h[event].length === 0) {
  1286. delete _h[event];
  1287. }
  1288. }
  1289. else {
  1290. delete _h[event];
  1291. }
  1292. return this;
  1293. },
  1294. /**
  1295. * Dispatch a event.
  1296. *
  1297. * @param {string} type The event name.
  1298. */
  1299. trigger: function (type) {
  1300. var _h = this._$handlers[type];
  1301. var eventProcessor = this._$eventProcessor;
  1302. if (_h) {
  1303. var args = arguments;
  1304. var argLen = args.length;
  1305. if (argLen > 3) {
  1306. args = arrySlice.call(args, 1);
  1307. }
  1308. var len = _h.length;
  1309. for (var i = 0; i < len;) {
  1310. var hItem = _h[i];
  1311. if (eventProcessor
  1312. && eventProcessor.filter
  1313. && hItem.query != null
  1314. && !eventProcessor.filter(type, hItem.query)
  1315. ) {
  1316. i++;
  1317. continue;
  1318. }
  1319. // Optimize advise from backbone
  1320. switch (argLen) {
  1321. case 1:
  1322. hItem.h.call(hItem.ctx);
  1323. break;
  1324. case 2:
  1325. hItem.h.call(hItem.ctx, args[1]);
  1326. break;
  1327. case 3:
  1328. hItem.h.call(hItem.ctx, args[1], args[2]);
  1329. break;
  1330. default:
  1331. // have more than 2 given arguments
  1332. hItem.h.apply(hItem.ctx, args);
  1333. break;
  1334. }
  1335. if (hItem.one) {
  1336. _h.splice(i, 1);
  1337. len--;
  1338. }
  1339. else {
  1340. i++;
  1341. }
  1342. }
  1343. }
  1344. eventProcessor && eventProcessor.afterTrigger
  1345. && eventProcessor.afterTrigger(type);
  1346. return this;
  1347. },
  1348. /**
  1349. * Dispatch a event with context, which is specified at the last parameter.
  1350. *
  1351. * @param {string} type The event name.
  1352. */
  1353. triggerWithContext: function (type) {
  1354. var _h = this._$handlers[type];
  1355. var eventProcessor = this._$eventProcessor;
  1356. if (_h) {
  1357. var args = arguments;
  1358. var argLen = args.length;
  1359. if (argLen > 4) {
  1360. args = arrySlice.call(args, 1, args.length - 1);
  1361. }
  1362. var ctx = args[args.length - 1];
  1363. var len = _h.length;
  1364. for (var i = 0; i < len;) {
  1365. var hItem = _h[i];
  1366. if (eventProcessor
  1367. && eventProcessor.filter
  1368. && hItem.query != null
  1369. && !eventProcessor.filter(type, hItem.query)
  1370. ) {
  1371. i++;
  1372. continue;
  1373. }
  1374. // Optimize advise from backbone
  1375. switch (argLen) {
  1376. case 1:
  1377. hItem.h.call(ctx);
  1378. break;
  1379. case 2:
  1380. hItem.h.call(ctx, args[1]);
  1381. break;
  1382. case 3:
  1383. hItem.h.call(ctx, args[1], args[2]);
  1384. break;
  1385. default:
  1386. // have more than 2 given arguments
  1387. hItem.h.apply(ctx, args);
  1388. break;
  1389. }
  1390. if (hItem.one) {
  1391. _h.splice(i, 1);
  1392. len--;
  1393. }
  1394. else {
  1395. i++;
  1396. }
  1397. }
  1398. }
  1399. eventProcessor && eventProcessor.afterTrigger
  1400. && eventProcessor.afterTrigger(type);
  1401. return this;
  1402. }
  1403. };
  1404. function normalizeQuery(host, query) {
  1405. var eventProcessor = host._$eventProcessor;
  1406. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  1407. query = eventProcessor.normalizeQuery(query);
  1408. }
  1409. return query;
  1410. }
  1411. function on(eventful, event, query, handler, context, isOnce) {
  1412. var _h = eventful._$handlers;
  1413. if (typeof query === 'function') {
  1414. context = handler;
  1415. handler = query;
  1416. query = null;
  1417. }
  1418. if (!handler || !event) {
  1419. return eventful;
  1420. }
  1421. query = normalizeQuery(eventful, query);
  1422. if (!_h[event]) {
  1423. _h[event] = [];
  1424. }
  1425. for (var i = 0; i < _h[event].length; i++) {
  1426. if (_h[event][i].h === handler) {
  1427. return eventful;
  1428. }
  1429. }
  1430. var wrap = {
  1431. h: handler,
  1432. one: isOnce,
  1433. query: query,
  1434. ctx: context || eventful,
  1435. // FIXME
  1436. // Do not publish this feature util it is proved that it makes sense.
  1437. callAtLast: handler.zrEventfulCallAtLast
  1438. };
  1439. var lastIndex = _h[event].length - 1;
  1440. var lastWrap = _h[event][lastIndex];
  1441. (lastWrap && lastWrap.callAtLast)
  1442. ? _h[event].splice(lastIndex, 0, wrap)
  1443. : _h[event].push(wrap);
  1444. return eventful;
  1445. }
  1446. /**
  1447. * 事件辅助类
  1448. * @module zrender/core/event
  1449. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  1450. */
  1451. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  1452. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1453. function getBoundingClientRect(el) {
  1454. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect
  1455. return el.getBoundingClientRect ? el.getBoundingClientRect() : {left: 0, top: 0};
  1456. }
  1457. // `calculate` is optional, default false
  1458. function clientToLocal(el, e, out, calculate) {
  1459. out = out || {};
  1460. // According to the W3C Working Draft, offsetX and offsetY should be relative
  1461. // to the padding edge of the target element. The only browser using this convention
  1462. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  1463. // not support the properties.
  1464. // (see http://www.jacklmoore.com/notes/mouse-position/)
  1465. // In zr painter.dom, padding edge equals to border edge.
  1466. // FIXME
  1467. // When mousemove event triggered on ec tooltip, target is not zr painter.dom, and
  1468. // offsetX/Y is relative to e.target, where the calculation of zrX/Y via offsetX/Y
  1469. // is too complex. So css-transfrom dont support in this case temporarily.
  1470. if (calculate || !env$1.canvasSupported) {
  1471. defaultGetZrXY(el, e, out);
  1472. }
  1473. // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  1474. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  1475. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  1476. // zoom-factor, overflow / opacity layers, transforms ...)
  1477. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  1478. // <https://bugs.jquery.com/ticket/8523#comment:14>
  1479. // BTW3, In ff, offsetX/offsetY is always 0.
  1480. else if (env$1.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  1481. out.zrX = e.layerX;
  1482. out.zrY = e.layerY;
  1483. }
  1484. // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  1485. else if (e.offsetX != null) {
  1486. out.zrX = e.offsetX;
  1487. out.zrY = e.offsetY;
  1488. }
  1489. // For some other device, e.g., IOS safari.
  1490. else {
  1491. defaultGetZrXY(el, e, out);
  1492. }
  1493. return out;
  1494. }
  1495. function defaultGetZrXY(el, e, out) {
  1496. // This well-known method below does not support css transform.
  1497. var box = getBoundingClientRect(el);
  1498. out.zrX = e.clientX - box.left;
  1499. out.zrY = e.clientY - box.top;
  1500. }
  1501. /**
  1502. * 如果存在第三方嵌入的一些dom触发的事件,或touch事件,需要转换一下事件坐标.
  1503. * `calculate` is optional, default false.
  1504. */
  1505. function normalizeEvent(el, e, calculate) {
  1506. e = e || window.event;
  1507. if (e.zrX != null) {
  1508. return e;
  1509. }
  1510. var eventType = e.type;
  1511. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1512. if (!isTouch) {
  1513. clientToLocal(el, e, e, calculate);
  1514. e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  1515. }
  1516. else {
  1517. var touch = eventType !== 'touchend'
  1518. ? e.targetTouches[0]
  1519. : e.changedTouches[0];
  1520. touch && clientToLocal(el, touch, e, calculate);
  1521. }
  1522. // Add which for click: 1 === left; 2 === middle; 3 === right; otherwise: 0;
  1523. // See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js
  1524. // If e.which has been defined, if may be readonly,
  1525. // see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
  1526. var button = e.button;
  1527. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1528. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1529. }
  1530. // [Caution]: `e.which` from browser is not always reliable. For example,
  1531. // when press left button and `mousemove (pointermove)` in Edge, the `e.which`
  1532. // is 65536 and the `e.button` is -1. But the `mouseup (pointerup)` and
  1533. // `mousedown (pointerdown)` is the same as Chrome does.
  1534. return e;
  1535. }
  1536. /**
  1537. * @param {HTMLElement} el
  1538. * @param {string} name
  1539. * @param {Function} handler
  1540. */
  1541. function addEventListener(el, name, handler) {
  1542. if (isDomLevel2) {
  1543. // Reproduct the console warning:
  1544. // [Violation] Added non-passive event listener to a scroll-blocking <some> event.
  1545. // Consider marking event handler as 'passive' to make the page more responsive.
  1546. // Just set console log level: verbose in chrome dev tool.
  1547. // then the warning log will be printed when addEventListener called.
  1548. // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  1549. // We have not yet found a neat way to using passive. Because in zrender the dom event
  1550. // listener delegate all of the upper events of element. Some of those events need
  1551. // to prevent default. For example, the feature `preventDefaultMouseMove` of echarts.
  1552. // Before passive can be adopted, these issues should be considered:
  1553. // (1) Whether and how a zrender user specifies an event listener passive. And by default,
  1554. // passive or not.
  1555. // (2) How to tread that some zrender event listener is passive, and some is not. If
  1556. // we use other way but not preventDefault of mousewheel and touchmove, browser
  1557. // compatibility should be handled.
  1558. // var opts = (env.passiveSupported && name === 'mousewheel')
  1559. // ? {passive: true}
  1560. // // By default, the third param of el.addEventListener is `capture: false`.
  1561. // : void 0;
  1562. // el.addEventListener(name, handler /* , opts */);
  1563. el.addEventListener(name, handler);
  1564. }
  1565. else {
  1566. el.attachEvent('on' + name, handler);
  1567. }
  1568. }
  1569. function removeEventListener(el, name, handler) {
  1570. if (isDomLevel2) {
  1571. el.removeEventListener(name, handler);
  1572. }
  1573. else {
  1574. el.detachEvent('on' + name, handler);
  1575. }
  1576. }
  1577. /**
  1578. * preventDefault and stopPropagation.
  1579. * Notice: do not do that in zrender. Upper application
  1580. * do that if necessary.
  1581. *
  1582. * @memberOf module:zrender/core/event
  1583. * @method
  1584. * @param {Event} e : event对象
  1585. */
  1586. var stop = isDomLevel2
  1587. ? function (e) {
  1588. e.preventDefault();
  1589. e.stopPropagation();
  1590. e.cancelBubble = true;
  1591. }
  1592. : function (e) {
  1593. e.returnValue = false;
  1594. e.cancelBubble = true;
  1595. };
  1596. /**
  1597. * This method only works for mouseup and mousedown. The functionality is restricted
  1598. * for fault tolerance, See the `e.which` compatibility above.
  1599. *
  1600. * @param {MouseEvent} e
  1601. * @return {boolean}
  1602. */
  1603. function isMiddleOrRightButtonOnMouseUpDown(e) {
  1604. return e.which === 2 || e.which === 3;
  1605. }
  1606. /**
  1607. * To be removed.
  1608. * @deprecated
  1609. */
  1610. /**
  1611. * Only implements needed gestures for mobile.
  1612. */
  1613. var GestureMgr = function () {
  1614. /**
  1615. * @private
  1616. * @type {Array.<Object>}
  1617. */
  1618. this._track = [];
  1619. };
  1620. GestureMgr.prototype = {
  1621. constructor: GestureMgr,
  1622. recognize: function (event, target, root) {
  1623. this._doTrack(event, target, root);
  1624. return this._recognize(event);
  1625. },
  1626. clear: function () {
  1627. this._track.length = 0;
  1628. return this;
  1629. },
  1630. _doTrack: function (event, target, root) {
  1631. var touches = event.touches;
  1632. if (!touches) {
  1633. return;
  1634. }
  1635. var trackItem = {
  1636. points: [],
  1637. touches: [],
  1638. target: target,
  1639. event: event
  1640. };
  1641. for (var i = 0, len = touches.length; i < len; i++) {
  1642. var touch = touches[i];
  1643. var pos = clientToLocal(root, touch, {});
  1644. trackItem.points.push([pos.zrX, pos.zrY]);
  1645. trackItem.touches.push(touch);
  1646. }
  1647. this._track.push(trackItem);
  1648. },
  1649. _recognize: function (event) {
  1650. for (var eventName in recognizers) {
  1651. if (recognizers.hasOwnProperty(eventName)) {
  1652. var gestureInfo = recognizers[eventName](this._track, event);
  1653. if (gestureInfo) {
  1654. return gestureInfo;
  1655. }
  1656. }
  1657. }
  1658. }
  1659. };
  1660. function dist$1(pointPair) {
  1661. var dx = pointPair[1][0] - pointPair[0][0];
  1662. var dy = pointPair[1][1] - pointPair[0][1];
  1663. return Math.sqrt(dx * dx + dy * dy);
  1664. }
  1665. function center(pointPair) {
  1666. return [
  1667. (pointPair[0][0] + pointPair[1][0]) / 2,
  1668. (pointPair[0][1] + pointPair[1][1]) / 2
  1669. ];
  1670. }
  1671. var recognizers = {
  1672. pinch: function (track, event) {
  1673. var trackLen = track.length;
  1674. if (!trackLen) {
  1675. return;
  1676. }
  1677. var pinchEnd = (track[trackLen - 1] || {}).points;
  1678. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  1679. if (pinchPre
  1680. && pinchPre.length > 1
  1681. && pinchEnd
  1682. && pinchEnd.length > 1
  1683. ) {
  1684. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1685. !isFinite(pinchScale) && (pinchScale = 1);
  1686. event.pinchScale = pinchScale;
  1687. var pinchCenter = center(pinchEnd);
  1688. event.pinchX = pinchCenter[0];
  1689. event.pinchY = pinchCenter[1];
  1690. return {
  1691. type: 'pinch',
  1692. target: track[0].target,
  1693. event: event
  1694. };
  1695. }
  1696. }
  1697. // Only pinch currently.
  1698. };
  1699. var SILENT = 'silent';
  1700. function makeEventPacket(eveType, targetInfo, event) {
  1701. return {
  1702. type: eveType,
  1703. event: event,
  1704. // target can only be an element that is not silent.
  1705. target: targetInfo.target,
  1706. // topTarget can be a silent element.
  1707. topTarget: targetInfo.topTarget,
  1708. cancelBubble: false,
  1709. offsetX: event.zrX,
  1710. offsetY: event.zrY,
  1711. gestureEvent: event.gestureEvent,
  1712. pinchX: event.pinchX,
  1713. pinchY: event.pinchY,
  1714. pinchScale: event.pinchScale,
  1715. wheelDelta: event.zrDelta,
  1716. zrByTouch: event.zrByTouch,
  1717. which: event.which,
  1718. stop: stopEvent
  1719. };
  1720. }
  1721. function stopEvent(event) {
  1722. stop(this.event);
  1723. }
  1724. function EmptyProxy() {}
  1725. EmptyProxy.prototype.dispose = function () {};
  1726. var handlerNames = [
  1727. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1728. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1729. ];
  1730. /**
  1731. * @alias module:zrender/Handler
  1732. * @constructor
  1733. * @extends module:zrender/mixin/Eventful
  1734. * @param {module:zrender/Storage} storage Storage instance.
  1735. * @param {module:zrender/Painter} painter Painter instance.
  1736. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  1737. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  1738. */
  1739. var Handler = function (storage, painter, proxy, painterRoot) {
  1740. Eventful.call(this);
  1741. this.storage = storage;
  1742. this.painter = painter;
  1743. this.painterRoot = painterRoot;
  1744. proxy = proxy || new EmptyProxy();
  1745. /**
  1746. * Proxy of event. can be Dom, WebGLSurface, etc.
  1747. */
  1748. this.proxy = null;
  1749. /**
  1750. * {target, topTarget, x, y}
  1751. * @private
  1752. * @type {Object}
  1753. */
  1754. this._hovered = {};
  1755. /**
  1756. * @private
  1757. * @type {Date}
  1758. */
  1759. this._lastTouchMoment;
  1760. /**
  1761. * @private
  1762. * @type {number}
  1763. */
  1764. this._lastX;
  1765. /**
  1766. * @private
  1767. * @type {number}
  1768. */
  1769. this._lastY;
  1770. /**
  1771. * @private
  1772. * @type {module:zrender/core/GestureMgr}
  1773. */
  1774. this._gestureMgr;
  1775. Draggable.call(this);
  1776. this.setHandlerProxy(proxy);
  1777. };
  1778. Handler.prototype = {
  1779. constructor: Handler,
  1780. setHandlerProxy: function (proxy) {
  1781. if (this.proxy) {
  1782. this.proxy.dispose();
  1783. }
  1784. if (proxy) {
  1785. each$1(handlerNames, function (name) {
  1786. proxy.on && proxy.on(name, this[name], this);
  1787. }, this);
  1788. // Attach handler
  1789. proxy.handler = this;
  1790. }
  1791. this.proxy = proxy;
  1792. },
  1793. mousemove: function (event) {
  1794. var x = event.zrX;
  1795. var y = event.zrY;
  1796. var lastHovered = this._hovered;
  1797. var lastHoveredTarget = lastHovered.target;
  1798. // If lastHoveredTarget is removed from zr (detected by '__zr') by some API call
  1799. // (like 'setOption' or 'dispatchAction') in event handlers, we should find
  1800. // lastHovered again here. Otherwise 'mouseout' can not be triggered normally.
  1801. // See #6198.
  1802. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1803. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1804. lastHoveredTarget = lastHovered.target;
  1805. }
  1806. var hovered = this._hovered = this.findHover(x, y);
  1807. var hoveredTarget = hovered.target;
  1808. var proxy = this.proxy;
  1809. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  1810. // Mouse out on previous hovered element
  1811. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  1812. this.dispatchToElement(lastHovered, 'mouseout', event);
  1813. }
  1814. // Mouse moving on one element
  1815. this.dispatchToElement(hovered, 'mousemove', event);
  1816. // Mouse over on a new element
  1817. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  1818. this.dispatchToElement(hovered, 'mouseover', event);
  1819. }
  1820. },
  1821. mouseout: function (event) {
  1822. this.dispatchToElement(this._hovered, 'mouseout', event);
  1823. // There might be some doms created by upper layer application
  1824. // at the same level of painter.getViewportRoot() (e.g., tooltip
  1825. // dom created by echarts), where 'globalout' event should not
  1826. // be triggered when mouse enters these doms. (But 'mouseout'
  1827. // should be triggered at the original hovered element as usual).
  1828. var element = event.toElement || event.relatedTarget;
  1829. var innerDom;
  1830. do {
  1831. element = element && element.parentNode;
  1832. }
  1833. while (element && element.nodeType !== 9 && !(
  1834. innerDom = element === this.painterRoot
  1835. ));
  1836. !innerDom && this.trigger('globalout', {event: event});
  1837. },
  1838. /**
  1839. * Resize
  1840. */
  1841. resize: function (event) {
  1842. this._hovered = {};
  1843. },
  1844. /**
  1845. * Dispatch event
  1846. * @param {string} eventName
  1847. * @param {event=} eventArgs
  1848. */
  1849. dispatch: function (eventName, eventArgs) {
  1850. var handler = this[eventName];
  1851. handler && handler.call(this, eventArgs);
  1852. },
  1853. /**
  1854. * Dispose
  1855. */
  1856. dispose: function () {
  1857. this.proxy.dispose();
  1858. this.storage =
  1859. this.proxy =
  1860. this.painter = null;
  1861. },
  1862. /**
  1863. * 设置默认的cursor style
  1864. * @param {string} [cursorStyle='default'] 例如 crosshair
  1865. */
  1866. setCursorStyle: function (cursorStyle) {
  1867. var proxy = this.proxy;
  1868. proxy.setCursor && proxy.setCursor(cursorStyle);
  1869. },
  1870. /**
  1871. * 事件分发代理
  1872. *
  1873. * @private
  1874. * @param {Object} targetInfo {target, topTarget} 目标图形元素
  1875. * @param {string} eventName 事件名称
  1876. * @param {Object} event 事件对象
  1877. */
  1878. dispatchToElement: function (targetInfo, eventName, event) {
  1879. targetInfo = targetInfo || {};
  1880. var el = targetInfo.target;
  1881. if (el && el.silent) {
  1882. return;
  1883. }
  1884. var eventHandler = 'on' + eventName;
  1885. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  1886. while (el) {
  1887. el[eventHandler]
  1888. && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  1889. el.trigger(eventName, eventPacket);
  1890. el = el.parent;
  1891. if (eventPacket.cancelBubble) {
  1892. break;
  1893. }
  1894. }
  1895. if (!eventPacket.cancelBubble) {
  1896. // 冒泡到顶级 zrender 对象
  1897. this.trigger(eventName, eventPacket);
  1898. // 分发事件到用户自定义层
  1899. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  1900. this.painter && this.painter.eachOtherLayer(function (layer) {
  1901. if (typeof (layer[eventHandler]) === 'function') {
  1902. layer[eventHandler].call(layer, eventPacket);
  1903. }
  1904. if (layer.trigger) {
  1905. layer.trigger(eventName, eventPacket);
  1906. }
  1907. });
  1908. }
  1909. },
  1910. /**
  1911. * @private
  1912. * @param {number} x
  1913. * @param {number} y
  1914. * @param {module:zrender/graphic/Displayable} exclude
  1915. * @return {model:zrender/Element}
  1916. * @method
  1917. */
  1918. findHover: function (x, y, exclude) {
  1919. var list = this.storage.getDisplayList();
  1920. var out = {x: x, y: y};
  1921. for (var i = list.length - 1; i >= 0; i--) {
  1922. var hoverCheckResult;
  1923. if (list[i] !== exclude
  1924. // getDisplayList may include ignored item in VML mode
  1925. && !list[i].ignore
  1926. && (hoverCheckResult = isHover(list[i], x, y))
  1927. ) {
  1928. !out.topTarget && (out.topTarget = list[i]);
  1929. if (hoverCheckResult !== SILENT) {
  1930. out.target = list[i];
  1931. break;
  1932. }
  1933. }
  1934. }
  1935. return out;
  1936. },
  1937. processGesture: function (event, stage) {
  1938. if (!this._gestureMgr) {
  1939. this._gestureMgr = new GestureMgr();
  1940. }
  1941. var gestureMgr = this._gestureMgr;
  1942. stage === 'start' && gestureMgr.clear();
  1943. var gestureInfo = gestureMgr.recognize(
  1944. event,
  1945. this.findHover(event.zrX, event.zrY, null).target,
  1946. this.proxy.dom
  1947. );
  1948. stage === 'end' && gestureMgr.clear();
  1949. // Do not do any preventDefault here. Upper application do that if necessary.
  1950. if (gestureInfo) {
  1951. var type = gestureInfo.type;
  1952. event.gestureEvent = type;
  1953. this.dispatchToElement({target: gestureInfo.target}, type, gestureInfo.event);
  1954. }
  1955. }
  1956. };
  1957. // Common handlers
  1958. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  1959. Handler.prototype[name] = function (event) {
  1960. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  1961. var hovered = this.findHover(event.zrX, event.zrY);
  1962. var hoveredTarget = hovered.target;
  1963. if (name === 'mousedown') {
  1964. this._downEl = hoveredTarget;
  1965. this._downPoint = [event.zrX, event.zrY];
  1966. // In case click triggered before mouseup
  1967. this._upEl = hoveredTarget;
  1968. }
  1969. else if (name === 'mouseup') {
  1970. this._upEl = hoveredTarget;
  1971. }
  1972. else if (name === 'click') {
  1973. if (this._downEl !== this._upEl
  1974. // Original click event is triggered on the whole canvas element,
  1975. // including the case that `mousedown` - `mousemove` - `mouseup`,
  1976. // which should be filtered, otherwise it will bring trouble to
  1977. // pan and zoom.
  1978. || !this._downPoint
  1979. // Arbitrary value
  1980. || dist(this._downPoint, [event.zrX, event.zrY]) > 4
  1981. ) {
  1982. return;
  1983. }
  1984. this._downPoint = null;
  1985. }
  1986. this.dispatchToElement(hovered, name, event);
  1987. };
  1988. });
  1989. function isHover(displayable, x, y) {
  1990. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  1991. var el = displayable;
  1992. var isSilent;
  1993. while (el) {
  1994. // If clipped by ancestor.
  1995. // FIXME: If clipPath has neither stroke nor fill,
  1996. // el.clipPath.contain(x, y) will always return false.
  1997. if (el.clipPath && !el.clipPath.contain(x, y)) {
  1998. return false;
  1999. }
  2000. if (el.silent) {
  2001. isSilent = true;
  2002. }
  2003. el = el.parent;
  2004. }
  2005. return isSilent ? SILENT : true;
  2006. }
  2007. return false;
  2008. }
  2009. mixin(Handler, Eventful);
  2010. mixin(Handler, Draggable);
  2011. /**
  2012. * 3x2矩阵操作类
  2013. * @exports zrender/tool/matrix
  2014. */
  2015. var ArrayCtor$1 = typeof Float32Array === 'undefined'
  2016. ? Array
  2017. : Float32Array;
  2018. /**
  2019. * Create a identity matrix.
  2020. * @return {Float32Array|Array.<number>}
  2021. */
  2022. function create$1() {
  2023. var out = new ArrayCtor$1(6);
  2024. identity(out);
  2025. return out;
  2026. }
  2027. /**
  2028. * 设置矩阵为单位矩阵
  2029. * @param {Float32Array|Array.<number>} out
  2030. */
  2031. function identity(out) {
  2032. out[0] = 1;
  2033. out[1] = 0;
  2034. out[2] = 0;
  2035. out[3] = 1;
  2036. out[4] = 0;
  2037. out[5] = 0;
  2038. return out;
  2039. }
  2040. /**
  2041. * 复制矩阵
  2042. * @param {Float32Array|Array.<number>} out
  2043. * @param {Float32Array|Array.<number>} m
  2044. */
  2045. function copy$1(out, m) {
  2046. out[0] = m[0];
  2047. out[1] = m[1];
  2048. out[2] = m[2];
  2049. out[3] = m[3];
  2050. out[4] = m[4];
  2051. out[5] = m[5];
  2052. return out;
  2053. }
  2054. /**
  2055. * 矩阵相乘
  2056. * @param {Float32Array|Array.<number>} out
  2057. * @param {Float32Array|Array.<number>} m1
  2058. * @param {Float32Array|Array.<number>} m2
  2059. */
  2060. function mul$1(out, m1, m2) {
  2061. // Consider matrix.mul(m, m2, m);
  2062. // where out is the same as m2.
  2063. // So use temp variable to escape error.
  2064. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  2065. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  2066. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  2067. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  2068. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  2069. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  2070. out[0] = out0;
  2071. out[1] = out1;
  2072. out[2] = out2;
  2073. out[3] = out3;
  2074. out[4] = out4;
  2075. out[5] = out5;
  2076. return out;
  2077. }
  2078. /**
  2079. * 平移变换
  2080. * @param {Float32Array|Array.<number>} out
  2081. * @param {Float32Array|Array.<number>} a
  2082. * @param {Float32Array|Array.<number>} v
  2083. */
  2084. function translate(out, a, v) {
  2085. out[0] = a[0];
  2086. out[1] = a[1];
  2087. out[2] = a[2];
  2088. out[3] = a[3];
  2089. out[4] = a[4] + v[0];
  2090. out[5] = a[5] + v[1];
  2091. return out;
  2092. }
  2093. /**
  2094. * 旋转变换
  2095. * @param {Float32Array|Array.<number>} out
  2096. * @param {Float32Array|Array.<number>} a
  2097. * @param {number} rad
  2098. */
  2099. function rotate(out, a, rad) {
  2100. var aa = a[0];
  2101. var ac = a[2];
  2102. var atx = a[4];
  2103. var ab = a[1];
  2104. var ad = a[3];
  2105. var aty = a[5];
  2106. var st = Math.sin(rad);
  2107. var ct = Math.cos(rad);
  2108. out[0] = aa * ct + ab * st;
  2109. out[1] = -aa * st + ab * ct;
  2110. out[2] = ac * ct + ad * st;
  2111. out[3] = -ac * st + ct * ad;
  2112. out[4] = ct * atx + st * aty;
  2113. out[5] = ct * aty - st * atx;
  2114. return out;
  2115. }
  2116. /**
  2117. * 缩放变换
  2118. * @param {Float32Array|Array.<number>} out
  2119. * @param {Float32Array|Array.<number>} a
  2120. * @param {Float32Array|Array.<number>} v
  2121. */
  2122. function scale$1(out, a, v) {
  2123. var vx = v[0];
  2124. var vy = v[1];
  2125. out[0] = a[0] * vx;
  2126. out[1] = a[1] * vy;
  2127. out[2] = a[2] * vx;
  2128. out[3] = a[3] * vy;
  2129. out[4] = a[4] * vx;
  2130. out[5] = a[5] * vy;
  2131. return out;
  2132. }
  2133. /**
  2134. * 求逆矩阵
  2135. * @param {Float32Array|Array.<number>} out
  2136. * @param {Float32Array|Array.<number>} a
  2137. */
  2138. function invert(out, a) {
  2139. var aa = a[0];
  2140. var ac = a[2];
  2141. var atx = a[4];
  2142. var ab = a[1];
  2143. var ad = a[3];
  2144. var aty = a[5];
  2145. var det = aa * ad - ab * ac;
  2146. if (!det) {
  2147. return null;
  2148. }
  2149. det = 1.0 / det;
  2150. out[0] = ad * det;
  2151. out[1] = -ab * det;
  2152. out[2] = -ac * det;
  2153. out[3] = aa * det;
  2154. out[4] = (ac * aty - ad * atx) * det;
  2155. out[5] = (ab * atx - aa * aty) * det;
  2156. return out;
  2157. }
  2158. /**
  2159. * Clone a new matrix.
  2160. * @param {Float32Array|Array.<number>} a
  2161. */
  2162. function clone$2(a) {
  2163. var b = create$1();
  2164. copy$1(b, a);
  2165. return b;
  2166. }
  2167. var matrix = (Object.freeze || Object)({
  2168. create: create$1,
  2169. identity: identity,
  2170. copy: copy$1,
  2171. mul: mul$1,
  2172. translate: translate,
  2173. rotate: rotate,
  2174. scale: scale$1,
  2175. invert: invert,
  2176. clone: clone$2
  2177. });
  2178. /**
  2179. * 提供变换扩展
  2180. * @module zrender/mixin/Transformable
  2181. * @author pissang (https://www.github.com/pissang)
  2182. */
  2183. var mIdentity = identity;
  2184. var EPSILON = 5e-5;
  2185. function isNotAroundZero(val) {
  2186. return val > EPSILON || val < -EPSILON;
  2187. }
  2188. /**
  2189. * @alias module:zrender/mixin/Transformable
  2190. * @constructor
  2191. */
  2192. var Transformable = function (opts) {
  2193. opts = opts || {};
  2194. // If there are no given position, rotation, scale
  2195. if (!opts.position) {
  2196. /**
  2197. * 平移
  2198. * @type {Array.<number>}
  2199. * @default [0, 0]
  2200. */
  2201. this.position = [0, 0];
  2202. }
  2203. if (opts.rotation == null) {
  2204. /**
  2205. * 旋转
  2206. * @type {Array.<number>}
  2207. * @default 0
  2208. */
  2209. this.rotation = 0;
  2210. }
  2211. if (!opts.scale) {
  2212. /**
  2213. * 缩放
  2214. * @type {Array.<number>}
  2215. * @default [1, 1]
  2216. */
  2217. this.scale = [1, 1];
  2218. }
  2219. /**
  2220. * 旋转和缩放的原点
  2221. * @type {Array.<number>}
  2222. * @default null
  2223. */
  2224. this.origin = this.origin || null;
  2225. };
  2226. var transformableProto = Transformable.prototype;
  2227. transformableProto.transform = null;
  2228. /**
  2229. * 判断是否需要有坐标变换
  2230. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  2231. */
  2232. transformableProto.needLocalTransform = function () {
  2233. return isNotAroundZero(this.rotation)
  2234. || isNotAroundZero(this.position[0])
  2235. || isNotAroundZero(this.position[1])
  2236. || isNotAroundZero(this.scale[0] - 1)
  2237. || isNotAroundZero(this.scale[1] - 1);
  2238. };
  2239. var scaleTmp = [];
  2240. transformableProto.updateTransform = function () {
  2241. var parent = this.parent;
  2242. var parentHasTransform = parent && parent.transform;
  2243. var needLocalTransform = this.needLocalTransform();
  2244. var m = this.transform;
  2245. if (!(needLocalTransform || parentHasTransform)) {
  2246. m && mIdentity(m);
  2247. return;
  2248. }
  2249. m = m || create$1();
  2250. if (needLocalTransform) {
  2251. this.getLocalTransform(m);
  2252. }
  2253. else {
  2254. mIdentity(m);
  2255. }
  2256. // 应用父节点变换
  2257. if (parentHasTransform) {
  2258. if (needLocalTransform) {
  2259. mul$1(m, parent.transform, m);
  2260. }
  2261. else {
  2262. copy$1(m, parent.transform);
  2263. }
  2264. }
  2265. // 保存这个变换矩阵
  2266. this.transform = m;
  2267. var globalScaleRatio = this.globalScaleRatio;
  2268. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  2269. this.getGlobalScale(scaleTmp);
  2270. var relX = scaleTmp[0] < 0 ? -1 : 1;
  2271. var relY = scaleTmp[1] < 0 ? -1 : 1;
  2272. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  2273. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  2274. m[0] *= sx;
  2275. m[1] *= sx;
  2276. m[2] *= sy;
  2277. m[3] *= sy;
  2278. }
  2279. this.invTransform = this.invTransform || create$1();
  2280. invert(this.invTransform, m);
  2281. };
  2282. transformableProto.getLocalTransform = function (m) {
  2283. return Transformable.getLocalTransform(this, m);
  2284. };
  2285. /**
  2286. * 将自己的transform应用到context上
  2287. * @param {CanvasRenderingContext2D} ctx
  2288. */
  2289. transformableProto.setTransform = function (ctx) {
  2290. var m = this.transform;
  2291. var dpr = ctx.dpr || 1;
  2292. if (m) {
  2293. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  2294. }
  2295. else {
  2296. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2297. }
  2298. };
  2299. transformableProto.restoreTransform = function (ctx) {
  2300. var dpr = ctx.dpr || 1;
  2301. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2302. };
  2303. var tmpTransform = [];
  2304. var originTransform = create$1();
  2305. transformableProto.setLocalTransform = function (m) {
  2306. if (!m) {
  2307. // TODO return or set identity?
  2308. return;
  2309. }
  2310. var sx = m[0] * m[0] + m[1] * m[1];
  2311. var sy = m[2] * m[2] + m[3] * m[3];
  2312. var position = this.position;
  2313. var scale$$1 = this.scale;
  2314. if (isNotAroundZero(sx - 1)) {
  2315. sx = Math.sqrt(sx);
  2316. }
  2317. if (isNotAroundZero(sy - 1)) {
  2318. sy = Math.sqrt(sy);
  2319. }
  2320. if (m[0] < 0) {
  2321. sx = -sx;
  2322. }
  2323. if (m[3] < 0) {
  2324. sy = -sy;
  2325. }
  2326. position[0] = m[4];
  2327. position[1] = m[5];
  2328. scale$$1[0] = sx;
  2329. scale$$1[1] = sy;
  2330. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  2331. };
  2332. /**
  2333. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  2334. */
  2335. transformableProto.decomposeTransform = function () {
  2336. if (!this.transform) {
  2337. return;
  2338. }
  2339. var parent = this.parent;
  2340. var m = this.transform;
  2341. if (parent && parent.transform) {
  2342. // Get local transform and decompose them to position, scale, rotation
  2343. mul$1(tmpTransform, parent.invTransform, m);
  2344. m = tmpTransform;
  2345. }
  2346. var origin = this.origin;
  2347. if (origin && (origin[0] || origin[1])) {
  2348. originTransform[4] = origin[0];
  2349. originTransform[5] = origin[1];
  2350. mul$1(tmpTransform, m, originTransform);
  2351. tmpTransform[4] -= origin[0];
  2352. tmpTransform[5] -= origin[1];
  2353. m = tmpTransform;
  2354. }
  2355. this.setLocalTransform(m);
  2356. };
  2357. /**
  2358. * Get global scale
  2359. * @return {Array.<number>}
  2360. */
  2361. transformableProto.getGlobalScale = function (out) {
  2362. var m = this.transform;
  2363. out = out || [];
  2364. if (!m) {
  2365. out[0] = 1;
  2366. out[1] = 1;
  2367. return out;
  2368. }
  2369. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  2370. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  2371. if (m[0] < 0) {
  2372. out[0] = -out[0];
  2373. }
  2374. if (m[3] < 0) {
  2375. out[1] = -out[1];
  2376. }
  2377. return out;
  2378. };
  2379. /**
  2380. * 变换坐标位置到 shape 的局部坐标空间
  2381. * @method
  2382. * @param {number} x
  2383. * @param {number} y
  2384. * @return {Array.<number>}
  2385. */
  2386. transformableProto.transformCoordToLocal = function (x, y) {
  2387. var v2 = [x, y];
  2388. var invTransform = this.invTransform;
  2389. if (invTransform) {
  2390. applyTransform(v2, v2, invTransform);
  2391. }
  2392. return v2;
  2393. };
  2394. /**
  2395. * 变换局部坐标位置到全局坐标空间
  2396. * @method
  2397. * @param {number} x
  2398. * @param {number} y
  2399. * @return {Array.<number>}
  2400. */
  2401. transformableProto.transformCoordToGlobal = function (x, y) {
  2402. var v2 = [x, y];
  2403. var transform = this.transform;
  2404. if (transform) {
  2405. applyTransform(v2, v2, transform);
  2406. }
  2407. return v2;
  2408. };
  2409. /**
  2410. * @static
  2411. * @param {Object} target
  2412. * @param {Array.<number>} target.origin
  2413. * @param {number} target.rotation
  2414. * @param {Array.<number>} target.position
  2415. * @param {Array.<number>} [m]
  2416. */
  2417. Transformable.getLocalTransform = function (target, m) {
  2418. m = m || [];
  2419. mIdentity(m);
  2420. var origin = target.origin;
  2421. var scale$$1 = target.scale || [1, 1];
  2422. var rotation = target.rotation || 0;
  2423. var position = target.position || [0, 0];
  2424. if (origin) {
  2425. // Translate to origin
  2426. m[4] -= origin[0];
  2427. m[5] -= origin[1];
  2428. }
  2429. scale$1(m, m, scale$$1);
  2430. if (rotation) {
  2431. rotate(m, m, rotation);
  2432. }
  2433. if (origin) {
  2434. // Translate back from origin
  2435. m[4] += origin[0];
  2436. m[5] += origin[1];
  2437. }
  2438. m[4] += position[0];
  2439. m[5] += position[1];
  2440. return m;
  2441. };
  2442. /**
  2443. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  2444. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  2445. * @exports zrender/animation/easing
  2446. */
  2447. var easing = {
  2448. /**
  2449. * @param {number} k
  2450. * @return {number}
  2451. */
  2452. linear: function (k) {
  2453. return k;
  2454. },
  2455. /**
  2456. * @param {number} k
  2457. * @return {number}
  2458. */
  2459. quadraticIn: function (k) {
  2460. return k * k;
  2461. },
  2462. /**
  2463. * @param {number} k
  2464. * @return {number}
  2465. */
  2466. quadraticOut: function (k) {
  2467. return k * (2 - k);
  2468. },
  2469. /**
  2470. * @param {number} k
  2471. * @return {number}
  2472. */
  2473. quadraticInOut: function (k) {
  2474. if ((k *= 2) < 1) {
  2475. return 0.5 * k * k;
  2476. }
  2477. return -0.5 * (--k * (k - 2) - 1);
  2478. },
  2479. // 三次方的缓动(t^3)
  2480. /**
  2481. * @param {number} k
  2482. * @return {number}
  2483. */
  2484. cubicIn: function (k) {
  2485. return k * k * k;
  2486. },
  2487. /**
  2488. * @param {number} k
  2489. * @return {number}
  2490. */
  2491. cubicOut: function (k) {
  2492. return --k * k * k + 1;
  2493. },
  2494. /**
  2495. * @param {number} k
  2496. * @return {number}
  2497. */
  2498. cubicInOut: function (k) {
  2499. if ((k *= 2) < 1) {
  2500. return 0.5 * k * k * k;
  2501. }
  2502. return 0.5 * ((k -= 2) * k * k + 2);
  2503. },
  2504. // 四次方的缓动(t^4)
  2505. /**
  2506. * @param {number} k
  2507. * @return {number}
  2508. */
  2509. quarticIn: function (k) {
  2510. return k * k * k * k;
  2511. },
  2512. /**
  2513. * @param {number} k
  2514. * @return {number}
  2515. */
  2516. quarticOut: function (k) {
  2517. return 1 - (--k * k * k * k);
  2518. },
  2519. /**
  2520. * @param {number} k
  2521. * @return {number}
  2522. */
  2523. quarticInOut: function (k) {
  2524. if ((k *= 2) < 1) {
  2525. return 0.5 * k * k * k * k;
  2526. }
  2527. return -0.5 * ((k -= 2) * k * k * k - 2);
  2528. },
  2529. // 五次方的缓动(t^5)
  2530. /**
  2531. * @param {number} k
  2532. * @return {number}
  2533. */
  2534. quinticIn: function (k) {
  2535. return k * k * k * k * k;
  2536. },
  2537. /**
  2538. * @param {number} k
  2539. * @return {number}
  2540. */
  2541. quinticOut: function (k) {
  2542. return --k * k * k * k * k + 1;
  2543. },
  2544. /**
  2545. * @param {number} k
  2546. * @return {number}
  2547. */
  2548. quinticInOut: function (k) {
  2549. if ((k *= 2) < 1) {
  2550. return 0.5 * k * k * k * k * k;
  2551. }
  2552. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2553. },
  2554. // 正弦曲线的缓动(sin(t))
  2555. /**
  2556. * @param {number} k
  2557. * @return {number}
  2558. */
  2559. sinusoidalIn: function (k) {
  2560. return 1 - Math.cos(k * Math.PI / 2);
  2561. },
  2562. /**
  2563. * @param {number} k
  2564. * @return {number}
  2565. */
  2566. sinusoidalOut: function (k) {
  2567. return Math.sin(k * Math.PI / 2);
  2568. },
  2569. /**
  2570. * @param {number} k
  2571. * @return {number}
  2572. */
  2573. sinusoidalInOut: function (k) {
  2574. return 0.5 * (1 - Math.cos(Math.PI * k));
  2575. },
  2576. // 指数曲线的缓动(2^t)
  2577. /**
  2578. * @param {number} k
  2579. * @return {number}
  2580. */
  2581. exponentialIn: function (k) {
  2582. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2583. },
  2584. /**
  2585. * @param {number} k
  2586. * @return {number}
  2587. */
  2588. exponentialOut: function (k) {
  2589. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2590. },
  2591. /**
  2592. * @param {number} k
  2593. * @return {number}
  2594. */
  2595. exponentialInOut: function (k) {
  2596. if (k === 0) {
  2597. return 0;
  2598. }
  2599. if (k === 1) {
  2600. return 1;
  2601. }
  2602. if ((k *= 2) < 1) {
  2603. return 0.5 * Math.pow(1024, k - 1);
  2604. }
  2605. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2606. },
  2607. // 圆形曲线的缓动(sqrt(1-t^2))
  2608. /**
  2609. * @param {number} k
  2610. * @return {number}
  2611. */
  2612. circularIn: function (k) {
  2613. return 1 - Math.sqrt(1 - k * k);
  2614. },
  2615. /**
  2616. * @param {number} k
  2617. * @return {number}
  2618. */
  2619. circularOut: function (k) {
  2620. return Math.sqrt(1 - (--k * k));
  2621. },
  2622. /**
  2623. * @param {number} k
  2624. * @return {number}
  2625. */
  2626. circularInOut: function (k) {
  2627. if ((k *= 2) < 1) {
  2628. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2629. }
  2630. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2631. },
  2632. // 创建类似于弹簧在停止前来回振荡的动画
  2633. /**
  2634. * @param {number} k
  2635. * @return {number}
  2636. */
  2637. elasticIn: function (k) {
  2638. var s;
  2639. var a = 0.1;
  2640. var p = 0.4;
  2641. if (k === 0) {
  2642. return 0;
  2643. }
  2644. if (k === 1) {
  2645. return 1;
  2646. }
  2647. if (!a || a < 1) {
  2648. a = 1;
  2649. s = p / 4;
  2650. }
  2651. else {
  2652. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2653. }
  2654. return -(a * Math.pow(2, 10 * (k -= 1))
  2655. * Math.sin((k - s) * (2 * Math.PI) / p));
  2656. },
  2657. /**
  2658. * @param {number} k
  2659. * @return {number}
  2660. */
  2661. elasticOut: function (k) {
  2662. var s;
  2663. var a = 0.1;
  2664. var p = 0.4;
  2665. if (k === 0) {
  2666. return 0;
  2667. }
  2668. if (k === 1) {
  2669. return 1;
  2670. }
  2671. if (!a || a < 1) {
  2672. a = 1;
  2673. s = p / 4;
  2674. }
  2675. else {
  2676. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2677. }
  2678. return (a * Math.pow(2, -10 * k)
  2679. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  2680. },
  2681. /**
  2682. * @param {number} k
  2683. * @return {number}
  2684. */
  2685. elasticInOut: function (k) {
  2686. var s;
  2687. var a = 0.1;
  2688. var p = 0.4;
  2689. if (k === 0) {
  2690. return 0;
  2691. }
  2692. if (k === 1) {
  2693. return 1;
  2694. }
  2695. if (!a || a < 1) {
  2696. a = 1;
  2697. s = p / 4;
  2698. }
  2699. else {
  2700. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2701. }
  2702. if ((k *= 2) < 1) {
  2703. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  2704. * Math.sin((k - s) * (2 * Math.PI) / p));
  2705. }
  2706. return a * Math.pow(2, -10 * (k -= 1))
  2707. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  2708. },
  2709. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  2710. /**
  2711. * @param {number} k
  2712. * @return {number}
  2713. */
  2714. backIn: function (k) {
  2715. var s = 1.70158;
  2716. return k * k * ((s + 1) * k - s);
  2717. },
  2718. /**
  2719. * @param {number} k
  2720. * @return {number}
  2721. */
  2722. backOut: function (k) {
  2723. var s = 1.70158;
  2724. return --k * k * ((s + 1) * k + s) + 1;
  2725. },
  2726. /**
  2727. * @param {number} k
  2728. * @return {number}
  2729. */
  2730. backInOut: function (k) {
  2731. var s = 1.70158 * 1.525;
  2732. if ((k *= 2) < 1) {
  2733. return 0.5 * (k * k * ((s + 1) * k - s));
  2734. }
  2735. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2736. },
  2737. // 创建弹跳效果
  2738. /**
  2739. * @param {number} k
  2740. * @return {number}
  2741. */
  2742. bounceIn: function (k) {
  2743. return 1 - easing.bounceOut(1 - k);
  2744. },
  2745. /**
  2746. * @param {number} k
  2747. * @return {number}
  2748. */
  2749. bounceOut: function (k) {
  2750. if (k < (1 / 2.75)) {
  2751. return 7.5625 * k * k;
  2752. }
  2753. else if (k < (2 / 2.75)) {
  2754. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  2755. }
  2756. else if (k < (2.5 / 2.75)) {
  2757. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  2758. }
  2759. else {
  2760. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  2761. }
  2762. },
  2763. /**
  2764. * @param {number} k
  2765. * @return {number}
  2766. */
  2767. bounceInOut: function (k) {
  2768. if (k < 0.5) {
  2769. return easing.bounceIn(k * 2) * 0.5;
  2770. }
  2771. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  2772. }
  2773. };
  2774. /**
  2775. * 动画主控制器
  2776. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  2777. * @config life(1000) 动画时长
  2778. * @config delay(0) 动画延迟时间
  2779. * @config loop(true)
  2780. * @config gap(0) 循环的间隔时间
  2781. * @config onframe
  2782. * @config easing(optional)
  2783. * @config ondestroy(optional)
  2784. * @config onrestart(optional)
  2785. *
  2786. * TODO pause
  2787. */
  2788. function Clip(options) {
  2789. this._target = options.target;
  2790. // 生命周期
  2791. this._life = options.life || 1000;
  2792. // 延时
  2793. this._delay = options.delay || 0;
  2794. // 开始时间
  2795. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  2796. this._initialized = false;
  2797. // 是否循环
  2798. this.loop = options.loop == null ? false : options.loop;
  2799. this.gap = options.gap || 0;
  2800. this.easing = options.easing || 'Linear';
  2801. this.onframe = options.onframe;
  2802. this.ondestroy = options.ondestroy;
  2803. this.onrestart = options.onrestart;
  2804. this._pausedTime = 0;
  2805. this._paused = false;
  2806. }
  2807. Clip.prototype = {
  2808. constructor: Clip,
  2809. step: function (globalTime, deltaTime) {
  2810. // Set startTime on first step, or _startTime may has milleseconds different between clips
  2811. // PENDING
  2812. if (!this._initialized) {
  2813. this._startTime = globalTime + this._delay;
  2814. this._initialized = true;
  2815. }
  2816. if (this._paused) {
  2817. this._pausedTime += deltaTime;
  2818. return;
  2819. }
  2820. var percent = (globalTime - this._startTime - this._pausedTime) / this._life;
  2821. // 还没开始
  2822. if (percent < 0) {
  2823. return;
  2824. }
  2825. percent = Math.min(percent, 1);
  2826. var easing$$1 = this.easing;
  2827. var easingFunc = typeof easing$$1 === 'string' ? easing[easing$$1] : easing$$1;
  2828. var schedule = typeof easingFunc === 'function'
  2829. ? easingFunc(percent)
  2830. : percent;
  2831. this.fire('frame', schedule);
  2832. // 结束
  2833. if (percent === 1) {
  2834. if (this.loop) {
  2835. this.restart(globalTime);
  2836. // 重新开始周期
  2837. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  2838. return 'restart';
  2839. }
  2840. // 动画完成将这个控制器标识为待删除
  2841. // 在Animation.update中进行批量删除
  2842. this._needsRemove = true;
  2843. return 'destroy';
  2844. }
  2845. return null;
  2846. },
  2847. restart: function (globalTime) {
  2848. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  2849. this._startTime = globalTime - remainder + this.gap;
  2850. this._pausedTime = 0;
  2851. this._needsRemove = false;
  2852. },
  2853. fire: function (eventType, arg) {
  2854. eventType = 'on' + eventType;
  2855. if (this[eventType]) {
  2856. this[eventType](this._target, arg);
  2857. }
  2858. },
  2859. pause: function () {
  2860. this._paused = true;
  2861. },
  2862. resume: function () {
  2863. this._paused = false;
  2864. }
  2865. };
  2866. // Simple LRU cache use doubly linked list
  2867. // @module zrender/core/LRU
  2868. /**
  2869. * Simple double linked list. Compared with array, it has O(1) remove operation.
  2870. * @constructor
  2871. */
  2872. var LinkedList = function () {
  2873. /**
  2874. * @type {module:zrender/core/LRU~Entry}
  2875. */
  2876. this.head = null;
  2877. /**
  2878. * @type {module:zrender/core/LRU~Entry}
  2879. */
  2880. this.tail = null;
  2881. this._len = 0;
  2882. };
  2883. var linkedListProto = LinkedList.prototype;
  2884. /**
  2885. * Insert a new value at the tail
  2886. * @param {} val
  2887. * @return {module:zrender/core/LRU~Entry}
  2888. */
  2889. linkedListProto.insert = function (val) {
  2890. var entry = new Entry(val);
  2891. this.insertEntry(entry);
  2892. return entry;
  2893. };
  2894. /**
  2895. * Insert an entry at the tail
  2896. * @param {module:zrender/core/LRU~Entry} entry
  2897. */
  2898. linkedListProto.insertEntry = function (entry) {
  2899. if (!this.head) {
  2900. this.head = this.tail = entry;
  2901. }
  2902. else {
  2903. this.tail.next = entry;
  2904. entry.prev = this.tail;
  2905. entry.next = null;
  2906. this.tail = entry;
  2907. }
  2908. this._len++;
  2909. };
  2910. /**
  2911. * Remove entry.
  2912. * @param {module:zrender/core/LRU~Entry} entry
  2913. */
  2914. linkedListProto.remove = function (entry) {
  2915. var prev = entry.prev;
  2916. var next = entry.next;
  2917. if (prev) {
  2918. prev.next = next;
  2919. }
  2920. else {
  2921. // Is head
  2922. this.head = next;
  2923. }
  2924. if (next) {
  2925. next.prev = prev;
  2926. }
  2927. else {
  2928. // Is tail
  2929. this.tail = prev;
  2930. }
  2931. entry.next = entry.prev = null;
  2932. this._len--;
  2933. };
  2934. /**
  2935. * @return {number}
  2936. */
  2937. linkedListProto.len = function () {
  2938. return this._len;
  2939. };
  2940. /**
  2941. * Clear list
  2942. */
  2943. linkedListProto.clear = function () {
  2944. this.head = this.tail = null;
  2945. this._len = 0;
  2946. };
  2947. /**
  2948. * @constructor
  2949. * @param {} val
  2950. */
  2951. var Entry = function (val) {
  2952. /**
  2953. * @type {}
  2954. */
  2955. this.value = val;
  2956. /**
  2957. * @type {module:zrender/core/LRU~Entry}
  2958. */
  2959. this.next;
  2960. /**
  2961. * @type {module:zrender/core/LRU~Entry}
  2962. */
  2963. this.prev;
  2964. };
  2965. /**
  2966. * LRU Cache
  2967. * @constructor
  2968. * @alias module:zrender/core/LRU
  2969. */
  2970. var LRU = function (maxSize) {
  2971. this._list = new LinkedList();
  2972. this._map = {};
  2973. this._maxSize = maxSize || 10;
  2974. this._lastRemovedEntry = null;
  2975. };
  2976. var LRUProto = LRU.prototype;
  2977. /**
  2978. * @param {string} key
  2979. * @param {} value
  2980. * @return {} Removed value
  2981. */
  2982. LRUProto.put = function (key, value) {
  2983. var list = this._list;
  2984. var map = this._map;
  2985. var removed = null;
  2986. if (map[key] == null) {
  2987. var len = list.len();
  2988. // Reuse last removed entry
  2989. var entry = this._lastRemovedEntry;
  2990. if (len >= this._maxSize && len > 0) {
  2991. // Remove the least recently used
  2992. var leastUsedEntry = list.head;
  2993. list.remove(leastUsedEntry);
  2994. delete map[leastUsedEntry.key];
  2995. removed = leastUsedEntry.value;
  2996. this._lastRemovedEntry = leastUsedEntry;
  2997. }
  2998. if (entry) {
  2999. entry.value = value;
  3000. }
  3001. else {
  3002. entry = new Entry(value);
  3003. }
  3004. entry.key = key;
  3005. list.insertEntry(entry);
  3006. map[key] = entry;
  3007. }
  3008. return removed;
  3009. };
  3010. /**
  3011. * @param {string} key
  3012. * @return {}
  3013. */
  3014. LRUProto.get = function (key) {
  3015. var entry = this._map[key];
  3016. var list = this._list;
  3017. if (entry != null) {
  3018. // Put the latest used entry in the tail
  3019. if (entry !== list.tail) {
  3020. list.remove(entry);
  3021. list.insertEntry(entry);
  3022. }
  3023. return entry.value;
  3024. }
  3025. };
  3026. /**
  3027. * Clear the cache
  3028. */
  3029. LRUProto.clear = function () {
  3030. this._list.clear();
  3031. this._map = {};
  3032. };
  3033. var kCSSColorTable = {
  3034. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3035. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3036. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3037. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3038. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3039. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3040. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3041. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3042. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3043. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3044. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3045. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3046. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3047. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3048. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3049. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3050. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3051. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3052. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3053. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3054. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3055. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3056. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3057. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3058. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3059. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3060. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3061. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3062. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3063. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3064. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3065. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3066. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3067. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3068. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3069. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3070. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3071. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3072. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3073. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3074. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3075. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3076. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3077. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3078. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3079. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3080. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3081. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3082. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3083. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3084. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3085. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3086. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3087. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3088. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3089. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3090. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3091. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3092. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3093. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3094. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3095. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3096. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3097. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3098. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3099. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3100. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3101. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3102. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3103. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3104. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3105. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3106. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3107. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3108. };
  3109. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  3110. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3111. return i < 0 ? 0 : i > 255 ? 255 : i;
  3112. }
  3113. function clampCssAngle(i) { // Clamp to integer 0 .. 360.
  3114. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3115. return i < 0 ? 0 : i > 360 ? 360 : i;
  3116. }
  3117. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  3118. return f < 0 ? 0 : f > 1 ? 1 : f;
  3119. }
  3120. function parseCssInt(str) { // int or percentage.
  3121. if (str.length && str.charAt(str.length - 1) === '%') {
  3122. return clampCssByte(parseFloat(str) / 100 * 255);
  3123. }
  3124. return clampCssByte(parseInt(str, 10));
  3125. }
  3126. function parseCssFloat(str) { // float or percentage.
  3127. if (str.length && str.charAt(str.length - 1) === '%') {
  3128. return clampCssFloat(parseFloat(str) / 100);
  3129. }
  3130. return clampCssFloat(parseFloat(str));
  3131. }
  3132. function cssHueToRgb(m1, m2, h) {
  3133. if (h < 0) {
  3134. h += 1;
  3135. }
  3136. else if (h > 1) {
  3137. h -= 1;
  3138. }
  3139. if (h * 6 < 1) {
  3140. return m1 + (m2 - m1) * h * 6;
  3141. }
  3142. if (h * 2 < 1) {
  3143. return m2;
  3144. }
  3145. if (h * 3 < 2) {
  3146. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3147. }
  3148. return m1;
  3149. }
  3150. function lerpNumber(a, b, p) {
  3151. return a + (b - a) * p;
  3152. }
  3153. function setRgba(out, r, g, b, a) {
  3154. out[0] = r; out[1] = g; out[2] = b; out[3] = a;
  3155. return out;
  3156. }
  3157. function copyRgba(out, a) {
  3158. out[0] = a[0]; out[1] = a[1]; out[2] = a[2]; out[3] = a[3];
  3159. return out;
  3160. }
  3161. var colorCache = new LRU(20);
  3162. var lastRemovedArr = null;
  3163. function putToCache(colorStr, rgbaArr) {
  3164. // Reuse removed array
  3165. if (lastRemovedArr) {
  3166. copyRgba(lastRemovedArr, rgbaArr);
  3167. }
  3168. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3169. }
  3170. /**
  3171. * @param {string} colorStr
  3172. * @param {Array.<number>} out
  3173. * @return {Array.<number>}
  3174. * @memberOf module:zrender/util/color
  3175. */
  3176. function parse(colorStr, rgbaArr) {
  3177. if (!colorStr) {
  3178. return;
  3179. }
  3180. rgbaArr = rgbaArr || [];
  3181. var cached = colorCache.get(colorStr);
  3182. if (cached) {
  3183. return copyRgba(rgbaArr, cached);
  3184. }
  3185. // colorStr may be not string
  3186. colorStr = colorStr + '';
  3187. // Remove all whitespace, not compliant, but should just be more accepting.
  3188. var str = colorStr.replace(/ /g, '').toLowerCase();
  3189. // Color keywords (and transparent) lookup.
  3190. if (str in kCSSColorTable) {
  3191. copyRgba(rgbaArr, kCSSColorTable[str]);
  3192. putToCache(colorStr, rgbaArr);
  3193. return rgbaArr;
  3194. }
  3195. // #abc and #abc123 syntax.
  3196. if (str.charAt(0) === '#') {
  3197. if (str.length === 4) {
  3198. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3199. if (!(iv >= 0 && iv <= 0xfff)) {
  3200. setRgba(rgbaArr, 0, 0, 0, 1);
  3201. return; // Covers NaN.
  3202. }
  3203. setRgba(rgbaArr,
  3204. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  3205. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  3206. (iv & 0xf) | ((iv & 0xf) << 4),
  3207. 1
  3208. );
  3209. putToCache(colorStr, rgbaArr);
  3210. return rgbaArr;
  3211. }
  3212. else if (str.length === 7) {
  3213. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3214. if (!(iv >= 0 && iv <= 0xffffff)) {
  3215. setRgba(rgbaArr, 0, 0, 0, 1);
  3216. return; // Covers NaN.
  3217. }
  3218. setRgba(rgbaArr,
  3219. (iv & 0xff0000) >> 16,
  3220. (iv & 0xff00) >> 8,
  3221. iv & 0xff,
  3222. 1
  3223. );
  3224. putToCache(colorStr, rgbaArr);
  3225. return rgbaArr;
  3226. }
  3227. return;
  3228. }
  3229. var op = str.indexOf('(');
  3230. var ep = str.indexOf(')');
  3231. if (op !== -1 && ep + 1 === str.length) {
  3232. var fname = str.substr(0, op);
  3233. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3234. var alpha = 1; // To allow case fallthrough.
  3235. switch (fname) {
  3236. case 'rgba':
  3237. if (params.length !== 4) {
  3238. setRgba(rgbaArr, 0, 0, 0, 1);
  3239. return;
  3240. }
  3241. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  3242. // Fall through.
  3243. case 'rgb':
  3244. if (params.length !== 3) {
  3245. setRgba(rgbaArr, 0, 0, 0, 1);
  3246. return;
  3247. }
  3248. setRgba(rgbaArr,
  3249. parseCssInt(params[0]),
  3250. parseCssInt(params[1]),
  3251. parseCssInt(params[2]),
  3252. alpha
  3253. );
  3254. putToCache(colorStr, rgbaArr);
  3255. return rgbaArr;
  3256. case 'hsla':
  3257. if (params.length !== 4) {
  3258. setRgba(rgbaArr, 0, 0, 0, 1);
  3259. return;
  3260. }
  3261. params[3] = parseCssFloat(params[3]);
  3262. hsla2rgba(params, rgbaArr);
  3263. putToCache(colorStr, rgbaArr);
  3264. return rgbaArr;
  3265. case 'hsl':
  3266. if (params.length !== 3) {
  3267. setRgba(rgbaArr, 0, 0, 0, 1);
  3268. return;
  3269. }
  3270. hsla2rgba(params, rgbaArr);
  3271. putToCache(colorStr, rgbaArr);
  3272. return rgbaArr;
  3273. default:
  3274. return;
  3275. }
  3276. }
  3277. setRgba(rgbaArr, 0, 0, 0, 1);
  3278. return;
  3279. }
  3280. /**
  3281. * @param {Array.<number>} hsla
  3282. * @param {Array.<number>} rgba
  3283. * @return {Array.<number>} rgba
  3284. */
  3285. function hsla2rgba(hsla, rgba) {
  3286. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  3287. // NOTE(deanm): According to the CSS spec s/l should only be
  3288. // percentages, but we don't bother and let float or percentage.
  3289. var s = parseCssFloat(hsla[1]);
  3290. var l = parseCssFloat(hsla[2]);
  3291. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3292. var m1 = l * 2 - m2;
  3293. rgba = rgba || [];
  3294. setRgba(rgba,
  3295. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  3296. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  3297. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255),
  3298. 1
  3299. );
  3300. if (hsla.length === 4) {
  3301. rgba[3] = hsla[3];
  3302. }
  3303. return rgba;
  3304. }
  3305. /**
  3306. * @param {Array.<number>} rgba
  3307. * @return {Array.<number>} hsla
  3308. */
  3309. function rgba2hsla(rgba) {
  3310. if (!rgba) {
  3311. return;
  3312. }
  3313. // RGB from 0 to 255
  3314. var R = rgba[0] / 255;
  3315. var G = rgba[1] / 255;
  3316. var B = rgba[2] / 255;
  3317. var vMin = Math.min(R, G, B); // Min. value of RGB
  3318. var vMax = Math.max(R, G, B); // Max. value of RGB
  3319. var delta = vMax - vMin; // Delta RGB value
  3320. var L = (vMax + vMin) / 2;
  3321. var H;
  3322. var S;
  3323. // HSL results from 0 to 1
  3324. if (delta === 0) {
  3325. H = 0;
  3326. S = 0;
  3327. }
  3328. else {
  3329. if (L < 0.5) {
  3330. S = delta / (vMax + vMin);
  3331. }
  3332. else {
  3333. S = delta / (2 - vMax - vMin);
  3334. }
  3335. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  3336. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  3337. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  3338. if (R === vMax) {
  3339. H = deltaB - deltaG;
  3340. }
  3341. else if (G === vMax) {
  3342. H = (1 / 3) + deltaR - deltaB;
  3343. }
  3344. else if (B === vMax) {
  3345. H = (2 / 3) + deltaG - deltaR;
  3346. }
  3347. if (H < 0) {
  3348. H += 1;
  3349. }
  3350. if (H > 1) {
  3351. H -= 1;
  3352. }
  3353. }
  3354. var hsla = [H * 360, S, L];
  3355. if (rgba[3] != null) {
  3356. hsla.push(rgba[3]);
  3357. }
  3358. return hsla;
  3359. }
  3360. /**
  3361. * @param {string} color
  3362. * @param {number} level
  3363. * @return {string}
  3364. * @memberOf module:zrender/util/color
  3365. */
  3366. function lift(color, level) {
  3367. var colorArr = parse(color);
  3368. if (colorArr) {
  3369. for (var i = 0; i < 3; i++) {
  3370. if (level < 0) {
  3371. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3372. }
  3373. else {
  3374. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  3375. }
  3376. if (colorArr[i] > 255) {
  3377. colorArr[i] = 255;
  3378. }
  3379. else if (color[i] < 0) {
  3380. colorArr[i] = 0;
  3381. }
  3382. }
  3383. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3384. }
  3385. }
  3386. /**
  3387. * @param {string} color
  3388. * @return {string}
  3389. * @memberOf module:zrender/util/color
  3390. */
  3391. function toHex(color) {
  3392. var colorArr = parse(color);
  3393. if (colorArr) {
  3394. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  3395. }
  3396. }
  3397. /**
  3398. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  3399. * @param {number} normalizedValue A float between 0 and 1.
  3400. * @param {Array.<Array.<number>>} colors List of rgba color array
  3401. * @param {Array.<number>} [out] Mapped gba color array
  3402. * @return {Array.<number>} will be null/undefined if input illegal.
  3403. */
  3404. function fastLerp(normalizedValue, colors, out) {
  3405. if (!(colors && colors.length)
  3406. || !(normalizedValue >= 0 && normalizedValue <= 1)
  3407. ) {
  3408. return;
  3409. }
  3410. out = out || [];
  3411. var value = normalizedValue * (colors.length - 1);
  3412. var leftIndex = Math.floor(value);
  3413. var rightIndex = Math.ceil(value);
  3414. var leftColor = colors[leftIndex];
  3415. var rightColor = colors[rightIndex];
  3416. var dv = value - leftIndex;
  3417. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3418. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3419. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3420. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3421. return out;
  3422. }
  3423. /**
  3424. * @deprecated
  3425. */
  3426. var fastMapToColor = fastLerp;
  3427. /**
  3428. * @param {number} normalizedValue A float between 0 and 1.
  3429. * @param {Array.<string>} colors Color list.
  3430. * @param {boolean=} fullOutput Default false.
  3431. * @return {(string|Object)} Result color. If fullOutput,
  3432. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  3433. * @memberOf module:zrender/util/color
  3434. */
  3435. function lerp$1(normalizedValue, colors, fullOutput) {
  3436. if (!(colors && colors.length)
  3437. || !(normalizedValue >= 0 && normalizedValue <= 1)
  3438. ) {
  3439. return;
  3440. }
  3441. var value = normalizedValue * (colors.length - 1);
  3442. var leftIndex = Math.floor(value);
  3443. var rightIndex = Math.ceil(value);
  3444. var leftColor = parse(colors[leftIndex]);
  3445. var rightColor = parse(colors[rightIndex]);
  3446. var dv = value - leftIndex;
  3447. var color = stringify(
  3448. [
  3449. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  3450. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  3451. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  3452. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  3453. ],
  3454. 'rgba'
  3455. );
  3456. return fullOutput
  3457. ? {
  3458. color: color,
  3459. leftIndex: leftIndex,
  3460. rightIndex: rightIndex,
  3461. value: value
  3462. }
  3463. : color;
  3464. }
  3465. /**
  3466. * @deprecated
  3467. */
  3468. var mapToColor = lerp$1;
  3469. /**
  3470. * @param {string} color
  3471. * @param {number=} h 0 ~ 360, ignore when null.
  3472. * @param {number=} s 0 ~ 1, ignore when null.
  3473. * @param {number=} l 0 ~ 1, ignore when null.
  3474. * @return {string} Color string in rgba format.
  3475. * @memberOf module:zrender/util/color
  3476. */
  3477. function modifyHSL(color, h, s, l) {
  3478. color = parse(color);
  3479. if (color) {
  3480. color = rgba2hsla(color);
  3481. h != null && (color[0] = clampCssAngle(h));
  3482. s != null && (color[1] = parseCssFloat(s));
  3483. l != null && (color[2] = parseCssFloat(l));
  3484. return stringify(hsla2rgba(color), 'rgba');
  3485. }
  3486. }
  3487. /**
  3488. * @param {string} color
  3489. * @param {number=} alpha 0 ~ 1
  3490. * @return {string} Color string in rgba format.
  3491. * @memberOf module:zrender/util/color
  3492. */
  3493. function modifyAlpha(color, alpha) {
  3494. color = parse(color);
  3495. if (color && alpha != null) {
  3496. color[3] = clampCssFloat(alpha);
  3497. return stringify(color, 'rgba');
  3498. }
  3499. }
  3500. /**
  3501. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  3502. * @param {string} type 'rgba', 'hsva', ...
  3503. * @return {string} Result color. (If input illegal, return undefined).
  3504. */
  3505. function stringify(arrColor, type) {
  3506. if (!arrColor || !arrColor.length) {
  3507. return;
  3508. }
  3509. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  3510. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  3511. colorStr += ',' + arrColor[3];
  3512. }
  3513. return type + '(' + colorStr + ')';
  3514. }
  3515. var color = (Object.freeze || Object)({
  3516. parse: parse,
  3517. lift: lift,
  3518. toHex: toHex,
  3519. fastLerp: fastLerp,
  3520. fastMapToColor: fastMapToColor,
  3521. lerp: lerp$1,
  3522. mapToColor: mapToColor,
  3523. modifyHSL: modifyHSL,
  3524. modifyAlpha: modifyAlpha,
  3525. stringify: stringify
  3526. });
  3527. /**
  3528. * @module echarts/animation/Animator
  3529. */
  3530. var arraySlice = Array.prototype.slice;
  3531. function defaultGetter(target, key) {
  3532. return target[key];
  3533. }
  3534. function defaultSetter(target, key, value) {
  3535. target[key] = value;
  3536. }
  3537. /**
  3538. * @param {number} p0
  3539. * @param {number} p1
  3540. * @param {number} percent
  3541. * @return {number}
  3542. */
  3543. function interpolateNumber(p0, p1, percent) {
  3544. return (p1 - p0) * percent + p0;
  3545. }
  3546. /**
  3547. * @param {string} p0
  3548. * @param {string} p1
  3549. * @param {number} percent
  3550. * @return {string}
  3551. */
  3552. function interpolateString(p0, p1, percent) {
  3553. return percent > 0.5 ? p1 : p0;
  3554. }
  3555. /**
  3556. * @param {Array} p0
  3557. * @param {Array} p1
  3558. * @param {number} percent
  3559. * @param {Array} out
  3560. * @param {number} arrDim
  3561. */
  3562. function interpolateArray(p0, p1, percent, out, arrDim) {
  3563. var len = p0.length;
  3564. if (arrDim === 1) {
  3565. for (var i = 0; i < len; i++) {
  3566. out[i] = interpolateNumber(p0[i], p1[i], percent);
  3567. }
  3568. }
  3569. else {
  3570. var len2 = len && p0[0].length;
  3571. for (var i = 0; i < len; i++) {
  3572. for (var j = 0; j < len2; j++) {
  3573. out[i][j] = interpolateNumber(
  3574. p0[i][j], p1[i][j], percent
  3575. );
  3576. }
  3577. }
  3578. }
  3579. }
  3580. // arr0 is source array, arr1 is target array.
  3581. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  3582. function fillArr(arr0, arr1, arrDim) {
  3583. var arr0Len = arr0.length;
  3584. var arr1Len = arr1.length;
  3585. if (arr0Len !== arr1Len) {
  3586. // FIXME Not work for TypedArray
  3587. var isPreviousLarger = arr0Len > arr1Len;
  3588. if (isPreviousLarger) {
  3589. // Cut the previous
  3590. arr0.length = arr1Len;
  3591. }
  3592. else {
  3593. // Fill the previous
  3594. for (var i = arr0Len; i < arr1Len; i++) {
  3595. arr0.push(
  3596. arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])
  3597. );
  3598. }
  3599. }
  3600. }
  3601. // Handling NaN value
  3602. var len2 = arr0[0] && arr0[0].length;
  3603. for (var i = 0; i < arr0.length; i++) {
  3604. if (arrDim === 1) {
  3605. if (isNaN(arr0[i])) {
  3606. arr0[i] = arr1[i];
  3607. }
  3608. }
  3609. else {
  3610. for (var j = 0; j < len2; j++) {
  3611. if (isNaN(arr0[i][j])) {
  3612. arr0[i][j] = arr1[i][j];
  3613. }
  3614. }
  3615. }
  3616. }
  3617. }
  3618. /**
  3619. * @param {Array} arr0
  3620. * @param {Array} arr1
  3621. * @param {number} arrDim
  3622. * @return {boolean}
  3623. */
  3624. function isArraySame(arr0, arr1, arrDim) {
  3625. if (arr0 === arr1) {
  3626. return true;
  3627. }
  3628. var len = arr0.length;
  3629. if (len !== arr1.length) {
  3630. return false;
  3631. }
  3632. if (arrDim === 1) {
  3633. for (var i = 0; i < len; i++) {
  3634. if (arr0[i] !== arr1[i]) {
  3635. return false;
  3636. }
  3637. }
  3638. }
  3639. else {
  3640. var len2 = arr0[0].length;
  3641. for (var i = 0; i < len; i++) {
  3642. for (var j = 0; j < len2; j++) {
  3643. if (arr0[i][j] !== arr1[i][j]) {
  3644. return false;
  3645. }
  3646. }
  3647. }
  3648. }
  3649. return true;
  3650. }
  3651. /**
  3652. * Catmull Rom interpolate array
  3653. * @param {Array} p0
  3654. * @param {Array} p1
  3655. * @param {Array} p2
  3656. * @param {Array} p3
  3657. * @param {number} t
  3658. * @param {number} t2
  3659. * @param {number} t3
  3660. * @param {Array} out
  3661. * @param {number} arrDim
  3662. */
  3663. function catmullRomInterpolateArray(
  3664. p0, p1, p2, p3, t, t2, t3, out, arrDim
  3665. ) {
  3666. var len = p0.length;
  3667. if (arrDim === 1) {
  3668. for (var i = 0; i < len; i++) {
  3669. out[i] = catmullRomInterpolate(
  3670. p0[i], p1[i], p2[i], p3[i], t, t2, t3
  3671. );
  3672. }
  3673. }
  3674. else {
  3675. var len2 = p0[0].length;
  3676. for (var i = 0; i < len; i++) {
  3677. for (var j = 0; j < len2; j++) {
  3678. out[i][j] = catmullRomInterpolate(
  3679. p0[i][j], p1[i][j], p2[i][j], p3[i][j],
  3680. t, t2, t3
  3681. );
  3682. }
  3683. }
  3684. }
  3685. }
  3686. /**
  3687. * Catmull Rom interpolate number
  3688. * @param {number} p0
  3689. * @param {number} p1
  3690. * @param {number} p2
  3691. * @param {number} p3
  3692. * @param {number} t
  3693. * @param {number} t2
  3694. * @param {number} t3
  3695. * @return {number}
  3696. */
  3697. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  3698. var v0 = (p2 - p0) * 0.5;
  3699. var v1 = (p3 - p1) * 0.5;
  3700. return (2 * (p1 - p2) + v0 + v1) * t3
  3701. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  3702. + v0 * t + p1;
  3703. }
  3704. function cloneValue(value) {
  3705. if (isArrayLike(value)) {
  3706. var len = value.length;
  3707. if (isArrayLike(value[0])) {
  3708. var ret = [];
  3709. for (var i = 0; i < len; i++) {
  3710. ret.push(arraySlice.call(value[i]));
  3711. }
  3712. return ret;
  3713. }
  3714. return arraySlice.call(value);
  3715. }
  3716. return value;
  3717. }
  3718. function rgba2String(rgba) {
  3719. rgba[0] = Math.floor(rgba[0]);
  3720. rgba[1] = Math.floor(rgba[1]);
  3721. rgba[2] = Math.floor(rgba[2]);
  3722. return 'rgba(' + rgba.join(',') + ')';
  3723. }
  3724. function getArrayDim(keyframes) {
  3725. var lastValue = keyframes[keyframes.length - 1].value;
  3726. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  3727. }
  3728. function createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {
  3729. var getter = animator._getter;
  3730. var setter = animator._setter;
  3731. var useSpline = easing === 'spline';
  3732. var trackLen = keyframes.length;
  3733. if (!trackLen) {
  3734. return;
  3735. }
  3736. // Guess data type
  3737. var firstVal = keyframes[0].value;
  3738. var isValueArray = isArrayLike(firstVal);
  3739. var isValueColor = false;
  3740. var isValueString = false;
  3741. // For vertices morphing
  3742. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  3743. var trackMaxTime;
  3744. // Sort keyframe as ascending
  3745. keyframes.sort(function (a, b) {
  3746. return a.time - b.time;
  3747. });
  3748. trackMaxTime = keyframes[trackLen - 1].time;
  3749. // Percents of each keyframe
  3750. var kfPercents = [];
  3751. // Value of each keyframe
  3752. var kfValues = [];
  3753. var prevValue = keyframes[0].value;
  3754. var isAllValueEqual = true;
  3755. for (var i = 0; i < trackLen; i++) {
  3756. kfPercents.push(keyframes[i].time / trackMaxTime);
  3757. // Assume value is a color when it is a string
  3758. var value = keyframes[i].value;
  3759. // Check if value is equal, deep check if value is array
  3760. if (!((isValueArray && isArraySame(value, prevValue, arrDim))
  3761. || (!isValueArray && value === prevValue))) {
  3762. isAllValueEqual = false;
  3763. }
  3764. prevValue = value;
  3765. // Try converting a string to a color array
  3766. if (typeof value === 'string') {
  3767. var colorArray = parse(value);
  3768. if (colorArray) {
  3769. value = colorArray;
  3770. isValueColor = true;
  3771. }
  3772. else {
  3773. isValueString = true;
  3774. }
  3775. }
  3776. kfValues.push(value);
  3777. }
  3778. if (!forceAnimate && isAllValueEqual) {
  3779. return;
  3780. }
  3781. var lastValue = kfValues[trackLen - 1];
  3782. // Polyfill array and NaN value
  3783. for (var i = 0; i < trackLen - 1; i++) {
  3784. if (isValueArray) {
  3785. fillArr(kfValues[i], lastValue, arrDim);
  3786. }
  3787. else {
  3788. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  3789. kfValues[i] = lastValue;
  3790. }
  3791. }
  3792. }
  3793. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);
  3794. // Cache the key of last frame to speed up when
  3795. // animation playback is sequency
  3796. var lastFrame = 0;
  3797. var lastFramePercent = 0;
  3798. var start;
  3799. var w;
  3800. var p0;
  3801. var p1;
  3802. var p2;
  3803. var p3;
  3804. if (isValueColor) {
  3805. var rgba = [0, 0, 0, 0];
  3806. }
  3807. var onframe = function (target, percent) {
  3808. // Find the range keyframes
  3809. // kf1-----kf2---------current--------kf3
  3810. // find kf2 and kf3 and do interpolation
  3811. var frame;
  3812. // In the easing function like elasticOut, percent may less than 0
  3813. if (percent < 0) {
  3814. frame = 0;
  3815. }
  3816. else if (percent < lastFramePercent) {
  3817. // Start from next key
  3818. // PENDING start from lastFrame ?
  3819. start = Math.min(lastFrame + 1, trackLen - 1);
  3820. for (frame = start; frame >= 0; frame--) {
  3821. if (kfPercents[frame] <= percent) {
  3822. break;
  3823. }
  3824. }
  3825. // PENDING really need to do this ?
  3826. frame = Math.min(frame, trackLen - 2);
  3827. }
  3828. else {
  3829. for (frame = lastFrame; frame < trackLen; frame++) {
  3830. if (kfPercents[frame] > percent) {
  3831. break;
  3832. }
  3833. }
  3834. frame = Math.min(frame - 1, trackLen - 2);
  3835. }
  3836. lastFrame = frame;
  3837. lastFramePercent = percent;
  3838. var range = (kfPercents[frame + 1] - kfPercents[frame]);
  3839. if (range === 0) {
  3840. return;
  3841. }
  3842. else {
  3843. w = (percent - kfPercents[frame]) / range;
  3844. }
  3845. if (useSpline) {
  3846. p1 = kfValues[frame];
  3847. p0 = kfValues[frame === 0 ? frame : frame - 1];
  3848. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  3849. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  3850. if (isValueArray) {
  3851. catmullRomInterpolateArray(
  3852. p0, p1, p2, p3, w, w * w, w * w * w,
  3853. getter(target, propName),
  3854. arrDim
  3855. );
  3856. }
  3857. else {
  3858. var value;
  3859. if (isValueColor) {
  3860. value = catmullRomInterpolateArray(
  3861. p0, p1, p2, p3, w, w * w, w * w * w,
  3862. rgba, 1
  3863. );
  3864. value = rgba2String(rgba);
  3865. }
  3866. else if (isValueString) {
  3867. // String is step(0.5)
  3868. return interpolateString(p1, p2, w);
  3869. }
  3870. else {
  3871. value = catmullRomInterpolate(
  3872. p0, p1, p2, p3, w, w * w, w * w * w
  3873. );
  3874. }
  3875. setter(
  3876. target,
  3877. propName,
  3878. value
  3879. );
  3880. }
  3881. }
  3882. else {
  3883. if (isValueArray) {
  3884. interpolateArray(
  3885. kfValues[frame], kfValues[frame + 1], w,
  3886. getter(target, propName),
  3887. arrDim
  3888. );
  3889. }
  3890. else {
  3891. var value;
  3892. if (isValueColor) {
  3893. interpolateArray(
  3894. kfValues[frame], kfValues[frame + 1], w,
  3895. rgba, 1
  3896. );
  3897. value = rgba2String(rgba);
  3898. }
  3899. else if (isValueString) {
  3900. // String is step(0.5)
  3901. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  3902. }
  3903. else {
  3904. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  3905. }
  3906. setter(
  3907. target,
  3908. propName,
  3909. value
  3910. );
  3911. }
  3912. }
  3913. };
  3914. var clip = new Clip({
  3915. target: animator._target,
  3916. life: trackMaxTime,
  3917. loop: animator._loop,
  3918. delay: animator._delay,
  3919. onframe: onframe,
  3920. ondestroy: oneTrackDone
  3921. });
  3922. if (easing && easing !== 'spline') {
  3923. clip.easing = easing;
  3924. }
  3925. return clip;
  3926. }
  3927. /**
  3928. * @alias module:zrender/animation/Animator
  3929. * @constructor
  3930. * @param {Object} target
  3931. * @param {boolean} loop
  3932. * @param {Function} getter
  3933. * @param {Function} setter
  3934. */
  3935. var Animator = function (target, loop, getter, setter) {
  3936. this._tracks = {};
  3937. this._target = target;
  3938. this._loop = loop || false;
  3939. this._getter = getter || defaultGetter;
  3940. this._setter = setter || defaultSetter;
  3941. this._clipCount = 0;
  3942. this._delay = 0;
  3943. this._doneList = [];
  3944. this._onframeList = [];
  3945. this._clipList = [];
  3946. };
  3947. Animator.prototype = {
  3948. /**
  3949. * 设置动画关键帧
  3950. * @param {number} time 关键帧时间,单位是ms
  3951. * @param {Object} props 关键帧的属性值,key-value表示
  3952. * @return {module:zrender/animation/Animator}
  3953. */
  3954. when: function (time /* ms */, props) {
  3955. var tracks = this._tracks;
  3956. for (var propName in props) {
  3957. if (!props.hasOwnProperty(propName)) {
  3958. continue;
  3959. }
  3960. if (!tracks[propName]) {
  3961. tracks[propName] = [];
  3962. // Invalid value
  3963. var value = this._getter(this._target, propName);
  3964. if (value == null) {
  3965. // zrLog('Invalid property ' + propName);
  3966. continue;
  3967. }
  3968. // If time is 0
  3969. // Then props is given initialize value
  3970. // Else
  3971. // Initialize value from current prop value
  3972. if (time !== 0) {
  3973. tracks[propName].push({
  3974. time: 0,
  3975. value: cloneValue(value)
  3976. });
  3977. }
  3978. }
  3979. tracks[propName].push({
  3980. time: time,
  3981. value: props[propName]
  3982. });
  3983. }
  3984. return this;
  3985. },
  3986. /**
  3987. * 添加动画每一帧的回调函数
  3988. * @param {Function} callback
  3989. * @return {module:zrender/animation/Animator}
  3990. */
  3991. during: function (callback) {
  3992. this._onframeList.push(callback);
  3993. return this;
  3994. },
  3995. pause: function () {
  3996. for (var i = 0; i < this._clipList.length; i++) {
  3997. this._clipList[i].pause();
  3998. }
  3999. this._paused = true;
  4000. },
  4001. resume: function () {
  4002. for (var i = 0; i < this._clipList.length; i++) {
  4003. this._clipList[i].resume();
  4004. }
  4005. this._paused = false;
  4006. },
  4007. isPaused: function () {
  4008. return !!this._paused;
  4009. },
  4010. _doneCallback: function () {
  4011. // Clear all tracks
  4012. this._tracks = {};
  4013. // Clear all clips
  4014. this._clipList.length = 0;
  4015. var doneList = this._doneList;
  4016. var len = doneList.length;
  4017. for (var i = 0; i < len; i++) {
  4018. doneList[i].call(this);
  4019. }
  4020. },
  4021. /**
  4022. * 开始执行动画
  4023. * @param {string|Function} [easing]
  4024. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  4025. * @param {boolean} forceAnimate
  4026. * @return {module:zrender/animation/Animator}
  4027. */
  4028. start: function (easing, forceAnimate) {
  4029. var self = this;
  4030. var clipCount = 0;
  4031. var oneTrackDone = function () {
  4032. clipCount--;
  4033. if (!clipCount) {
  4034. self._doneCallback();
  4035. }
  4036. };
  4037. var lastClip;
  4038. for (var propName in this._tracks) {
  4039. if (!this._tracks.hasOwnProperty(propName)) {
  4040. continue;
  4041. }
  4042. var clip = createTrackClip(
  4043. this, easing, oneTrackDone,
  4044. this._tracks[propName], propName, forceAnimate
  4045. );
  4046. if (clip) {
  4047. this._clipList.push(clip);
  4048. clipCount++;
  4049. // If start after added to animation
  4050. if (this.animation) {
  4051. this.animation.addClip(clip);
  4052. }
  4053. lastClip = clip;
  4054. }
  4055. }
  4056. // Add during callback on the last clip
  4057. if (lastClip) {
  4058. var oldOnFrame = lastClip.onframe;
  4059. lastClip.onframe = function (target, percent) {
  4060. oldOnFrame(target, percent);
  4061. for (var i = 0; i < self._onframeList.length; i++) {
  4062. self._onframeList[i](target, percent);
  4063. }
  4064. };
  4065. }
  4066. // This optimization will help the case that in the upper application
  4067. // the view may be refreshed frequently, where animation will be
  4068. // called repeatly but nothing changed.
  4069. if (!clipCount) {
  4070. this._doneCallback();
  4071. }
  4072. return this;
  4073. },
  4074. /**
  4075. * 停止动画
  4076. * @param {boolean} forwardToLast If move to last frame before stop
  4077. */
  4078. stop: function (forwardToLast) {
  4079. var clipList = this._clipList;
  4080. var animation = this.animation;
  4081. for (var i = 0; i < clipList.length; i++) {
  4082. var clip = clipList[i];
  4083. if (forwardToLast) {
  4084. // Move to last frame before stop
  4085. clip.onframe(this._target, 1);
  4086. }
  4087. animation && animation.removeClip(clip);
  4088. }
  4089. clipList.length = 0;
  4090. },
  4091. /**
  4092. * 设置动画延迟开始的时间
  4093. * @param {number} time 单位ms
  4094. * @return {module:zrender/animation/Animator}
  4095. */
  4096. delay: function (time) {
  4097. this._delay = time;
  4098. return this;
  4099. },
  4100. /**
  4101. * 添加动画结束的回调
  4102. * @param {Function} cb
  4103. * @return {module:zrender/animation/Animator}
  4104. */
  4105. done: function (cb) {
  4106. if (cb) {
  4107. this._doneList.push(cb);
  4108. }
  4109. return this;
  4110. },
  4111. /**
  4112. * @return {Array.<module:zrender/animation/Clip>}
  4113. */
  4114. getClips: function () {
  4115. return this._clipList;
  4116. }
  4117. };
  4118. var dpr = 1;
  4119. // If in browser environment
  4120. if (typeof window !== 'undefined') {
  4121. dpr = Math.max(window.devicePixelRatio || 1, 1);
  4122. }
  4123. /**
  4124. * config默认配置项
  4125. * @exports zrender/config
  4126. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  4127. */
  4128. /**
  4129. * debug日志选项:catchBrushException为true下有效
  4130. * 0 : 不生成debug数据,发布用
  4131. * 1 : 异常抛出,调试用
  4132. * 2 : 控制台输出,调试用
  4133. */
  4134. var debugMode = 0;
  4135. // retina 屏幕优化
  4136. var devicePixelRatio = dpr;
  4137. var log = function () {
  4138. };
  4139. if (debugMode === 1) {
  4140. log = function () {
  4141. for (var k in arguments) {
  4142. throw new Error(arguments[k]);
  4143. }
  4144. };
  4145. }
  4146. else if (debugMode > 1) {
  4147. log = function () {
  4148. for (var k in arguments) {
  4149. console.log(arguments[k]);
  4150. }
  4151. };
  4152. }
  4153. var zrLog = log;
  4154. /**
  4155. * @alias modue:zrender/mixin/Animatable
  4156. * @constructor
  4157. */
  4158. var Animatable = function () {
  4159. /**
  4160. * @type {Array.<module:zrender/animation/Animator>}
  4161. * @readOnly
  4162. */
  4163. this.animators = [];
  4164. };
  4165. Animatable.prototype = {
  4166. constructor: Animatable,
  4167. /**
  4168. * 动画
  4169. *
  4170. * @param {string} path The path to fetch value from object, like 'a.b.c'.
  4171. * @param {boolean} [loop] Whether to loop animation.
  4172. * @return {module:zrender/animation/Animator}
  4173. * @example:
  4174. * el.animate('style', false)
  4175. * .when(1000, {x: 10} )
  4176. * .done(function(){ // Animation done })
  4177. * .start()
  4178. */
  4179. animate: function (path, loop) {
  4180. var target;
  4181. var animatingShape = false;
  4182. var el = this;
  4183. var zr = this.__zr;
  4184. if (path) {
  4185. var pathSplitted = path.split('.');
  4186. var prop = el;
  4187. // If animating shape
  4188. animatingShape = pathSplitted[0] === 'shape';
  4189. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  4190. if (!prop) {
  4191. continue;
  4192. }
  4193. prop = prop[pathSplitted[i]];
  4194. }
  4195. if (prop) {
  4196. target = prop;
  4197. }
  4198. }
  4199. else {
  4200. target = el;
  4201. }
  4202. if (!target) {
  4203. zrLog(
  4204. 'Property "'
  4205. + path
  4206. + '" is not existed in element '
  4207. + el.id
  4208. );
  4209. return;
  4210. }
  4211. var animators = el.animators;
  4212. var animator = new Animator(target, loop);
  4213. animator.during(function (target) {
  4214. el.dirty(animatingShape);
  4215. })
  4216. .done(function () {
  4217. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  4218. animators.splice(indexOf(animators, animator), 1);
  4219. });
  4220. animators.push(animator);
  4221. // If animate after added to the zrender
  4222. if (zr) {
  4223. zr.animation.addAnimator(animator);
  4224. }
  4225. return animator;
  4226. },
  4227. /**
  4228. * 停止动画
  4229. * @param {boolean} forwardToLast If move to last frame before stop
  4230. */
  4231. stopAnimation: function (forwardToLast) {
  4232. var animators = this.animators;
  4233. var len = animators.length;
  4234. for (var i = 0; i < len; i++) {
  4235. animators[i].stop(forwardToLast);
  4236. }
  4237. animators.length = 0;
  4238. return this;
  4239. },
  4240. /**
  4241. * Caution: this method will stop previous animation.
  4242. * So do not use this method to one element twice before
  4243. * animation starts, unless you know what you are doing.
  4244. * @param {Object} target
  4245. * @param {number} [time=500] Time in ms
  4246. * @param {string} [easing='linear']
  4247. * @param {number} [delay=0]
  4248. * @param {Function} [callback]
  4249. * @param {Function} [forceAnimate] Prevent stop animation and callback
  4250. * immediently when target values are the same as current values.
  4251. *
  4252. * @example
  4253. * // Animate position
  4254. * el.animateTo({
  4255. * position: [10, 10]
  4256. * }, function () { // done })
  4257. *
  4258. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  4259. * el.animateTo({
  4260. * shape: {
  4261. * width: 500
  4262. * },
  4263. * style: {
  4264. * fill: 'red'
  4265. * }
  4266. * position: [10, 10]
  4267. * }, 100, 100, 'cubicOut', function () { // done })
  4268. */
  4269. // TODO Return animation key
  4270. animateTo: function (target, time, delay, easing, callback, forceAnimate) {
  4271. animateTo(this, target, time, delay, easing, callback, forceAnimate);
  4272. },
  4273. /**
  4274. * Animate from the target state to current state.
  4275. * The params and the return value are the same as `this.animateTo`.
  4276. */
  4277. animateFrom: function (target, time, delay, easing, callback, forceAnimate) {
  4278. animateTo(this, target, time, delay, easing, callback, forceAnimate, true);
  4279. }
  4280. };
  4281. function animateTo(animatable, target, time, delay, easing, callback, forceAnimate, reverse) {
  4282. // animateTo(target, time, easing, callback);
  4283. if (isString(delay)) {
  4284. callback = easing;
  4285. easing = delay;
  4286. delay = 0;
  4287. }
  4288. // animateTo(target, time, delay, callback);
  4289. else if (isFunction$1(easing)) {
  4290. callback = easing;
  4291. easing = 'linear';
  4292. delay = 0;
  4293. }
  4294. // animateTo(target, time, callback);
  4295. else if (isFunction$1(delay)) {
  4296. callback = delay;
  4297. delay = 0;
  4298. }
  4299. // animateTo(target, callback)
  4300. else if (isFunction$1(time)) {
  4301. callback = time;
  4302. time = 500;
  4303. }
  4304. // animateTo(target)
  4305. else if (!time) {
  4306. time = 500;
  4307. }
  4308. // Stop all previous animations
  4309. animatable.stopAnimation();
  4310. animateToShallow(animatable, '', animatable, target, time, delay, reverse);
  4311. // Animators may be removed immediately after start
  4312. // if there is nothing to animate
  4313. var animators = animatable.animators.slice();
  4314. var count = animators.length;
  4315. function done() {
  4316. count--;
  4317. if (!count) {
  4318. callback && callback();
  4319. }
  4320. }
  4321. // No animators. This should be checked before animators[i].start(),
  4322. // because 'done' may be executed immediately if no need to animate.
  4323. if (!count) {
  4324. callback && callback();
  4325. }
  4326. // Start after all animators created
  4327. // Incase any animator is done immediately when all animation properties are not changed
  4328. for (var i = 0; i < animators.length; i++) {
  4329. animators[i]
  4330. .done(done)
  4331. .start(easing, forceAnimate);
  4332. }
  4333. }
  4334. /**
  4335. * @param {string} path=''
  4336. * @param {Object} source=animatable
  4337. * @param {Object} target
  4338. * @param {number} [time=500]
  4339. * @param {number} [delay=0]
  4340. * @param {boolean} [reverse] If `true`, animate
  4341. * from the `target` to current state.
  4342. *
  4343. * @example
  4344. * // Animate position
  4345. * el._animateToShallow({
  4346. * position: [10, 10]
  4347. * })
  4348. *
  4349. * // Animate shape, style and position in 100ms, delayed 100ms
  4350. * el._animateToShallow({
  4351. * shape: {
  4352. * width: 500
  4353. * },
  4354. * style: {
  4355. * fill: 'red'
  4356. * }
  4357. * position: [10, 10]
  4358. * }, 100, 100)
  4359. */
  4360. function animateToShallow(animatable, path, source, target, time, delay, reverse) {
  4361. var objShallow = {};
  4362. var propertyCount = 0;
  4363. for (var name in target) {
  4364. if (!target.hasOwnProperty(name)) {
  4365. continue;
  4366. }
  4367. if (source[name] != null) {
  4368. if (isObject$1(target[name]) && !isArrayLike(target[name])) {
  4369. animateToShallow(
  4370. animatable,
  4371. path ? path + '.' + name : name,
  4372. source[name],
  4373. target[name],
  4374. time,
  4375. delay,
  4376. reverse
  4377. );
  4378. }
  4379. else {
  4380. if (reverse) {
  4381. objShallow[name] = source[name];
  4382. setAttrByPath(animatable, path, name, target[name]);
  4383. }
  4384. else {
  4385. objShallow[name] = target[name];
  4386. }
  4387. propertyCount++;
  4388. }
  4389. }
  4390. else if (target[name] != null && !reverse) {
  4391. setAttrByPath(animatable, path, name, target[name]);
  4392. }
  4393. }
  4394. if (propertyCount > 0) {
  4395. animatable.animate(path, false)
  4396. .when(time == null ? 500 : time, objShallow)
  4397. .delay(delay || 0);
  4398. }
  4399. }
  4400. function setAttrByPath(el, path, name, value) {
  4401. // Attr directly if not has property
  4402. // FIXME, if some property not needed for element ?
  4403. if (!path) {
  4404. el.attr(name, value);
  4405. }
  4406. else {
  4407. // Only support set shape or style
  4408. var props = {};
  4409. props[path] = {};
  4410. props[path][name] = value;
  4411. el.attr(props);
  4412. }
  4413. }
  4414. /**
  4415. * @alias module:zrender/Element
  4416. * @constructor
  4417. * @extends {module:zrender/mixin/Animatable}
  4418. * @extends {module:zrender/mixin/Transformable}
  4419. * @extends {module:zrender/mixin/Eventful}
  4420. */
  4421. var Element = function (opts) { // jshint ignore:line
  4422. Transformable.call(this, opts);
  4423. Eventful.call(this, opts);
  4424. Animatable.call(this, opts);
  4425. /**
  4426. * 画布元素ID
  4427. * @type {string}
  4428. */
  4429. this.id = opts.id || guid();
  4430. };
  4431. Element.prototype = {
  4432. /**
  4433. * 元素类型
  4434. * Element type
  4435. * @type {string}
  4436. */
  4437. type: 'element',
  4438. /**
  4439. * 元素名字
  4440. * Element name
  4441. * @type {string}
  4442. */
  4443. name: '',
  4444. /**
  4445. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  4446. * ZRender instance will be assigned when element is associated with zrender
  4447. * @name module:/zrender/Element#__zr
  4448. * @type {module:zrender/ZRender}
  4449. */
  4450. __zr: null,
  4451. /**
  4452. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  4453. * If ignore drawing and events of the element object
  4454. * @name module:/zrender/Element#ignore
  4455. * @type {boolean}
  4456. * @default false
  4457. */
  4458. ignore: false,
  4459. /**
  4460. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  4461. * 该路径会继承被裁减对象的变换
  4462. * @type {module:zrender/graphic/Path}
  4463. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  4464. * @readOnly
  4465. */
  4466. clipPath: null,
  4467. /**
  4468. * 是否是 Group
  4469. * @type {boolean}
  4470. */
  4471. isGroup: false,
  4472. /**
  4473. * Drift element
  4474. * @param {number} dx dx on the global space
  4475. * @param {number} dy dy on the global space
  4476. */
  4477. drift: function (dx, dy) {
  4478. switch (this.draggable) {
  4479. case 'horizontal':
  4480. dy = 0;
  4481. break;
  4482. case 'vertical':
  4483. dx = 0;
  4484. break;
  4485. }
  4486. var m = this.transform;
  4487. if (!m) {
  4488. m = this.transform = [1, 0, 0, 1, 0, 0];
  4489. }
  4490. m[4] += dx;
  4491. m[5] += dy;
  4492. this.decomposeTransform();
  4493. this.dirty(false);
  4494. },
  4495. /**
  4496. * Hook before update
  4497. */
  4498. beforeUpdate: function () {},
  4499. /**
  4500. * Hook after update
  4501. */
  4502. afterUpdate: function () {},
  4503. /**
  4504. * Update each frame
  4505. */
  4506. update: function () {
  4507. this.updateTransform();
  4508. },
  4509. /**
  4510. * @param {Function} cb
  4511. * @param {} context
  4512. */
  4513. traverse: function (cb, context) {},
  4514. /**
  4515. * @protected
  4516. */
  4517. attrKV: function (key, value) {
  4518. if (key === 'position' || key === 'scale' || key === 'origin') {
  4519. // Copy the array
  4520. if (value) {
  4521. var target = this[key];
  4522. if (!target) {
  4523. target = this[key] = [];
  4524. }
  4525. target[0] = value[0];
  4526. target[1] = value[1];
  4527. }
  4528. }
  4529. else {
  4530. this[key] = value;
  4531. }
  4532. },
  4533. /**
  4534. * Hide the element
  4535. */
  4536. hide: function () {
  4537. this.ignore = true;
  4538. this.__zr && this.__zr.refresh();
  4539. },
  4540. /**
  4541. * Show the element
  4542. */
  4543. show: function () {
  4544. this.ignore = false;
  4545. this.__zr && this.__zr.refresh();
  4546. },
  4547. /**
  4548. * @param {string|Object} key
  4549. * @param {*} value
  4550. */
  4551. attr: function (key, value) {
  4552. if (typeof key === 'string') {
  4553. this.attrKV(key, value);
  4554. }
  4555. else if (isObject$1(key)) {
  4556. for (var name in key) {
  4557. if (key.hasOwnProperty(name)) {
  4558. this.attrKV(name, key[name]);
  4559. }
  4560. }
  4561. }
  4562. this.dirty(false);
  4563. return this;
  4564. },
  4565. /**
  4566. * @param {module:zrender/graphic/Path} clipPath
  4567. */
  4568. setClipPath: function (clipPath) {
  4569. var zr = this.__zr;
  4570. if (zr) {
  4571. clipPath.addSelfToZr(zr);
  4572. }
  4573. // Remove previous clip path
  4574. if (this.clipPath && this.clipPath !== clipPath) {
  4575. this.removeClipPath();
  4576. }
  4577. this.clipPath = clipPath;
  4578. clipPath.__zr = zr;
  4579. clipPath.__clipTarget = this;
  4580. this.dirty(false);
  4581. },
  4582. /**
  4583. */
  4584. removeClipPath: function () {
  4585. var clipPath = this.clipPath;
  4586. if (clipPath) {
  4587. if (clipPath.__zr) {
  4588. clipPath.removeSelfFromZr(clipPath.__zr);
  4589. }
  4590. clipPath.__zr = null;
  4591. clipPath.__clipTarget = null;
  4592. this.clipPath = null;
  4593. this.dirty(false);
  4594. }
  4595. },
  4596. /**
  4597. * Add self from zrender instance.
  4598. * Not recursively because it will be invoked when element added to storage.
  4599. * @param {module:zrender/ZRender} zr
  4600. */
  4601. addSelfToZr: function (zr) {
  4602. this.__zr = zr;
  4603. // 添加动画
  4604. var animators = this.animators;
  4605. if (animators) {
  4606. for (var i = 0; i < animators.length; i++) {
  4607. zr.animation.addAnimator(animators[i]);
  4608. }
  4609. }
  4610. if (this.clipPath) {
  4611. this.clipPath.addSelfToZr(zr);
  4612. }
  4613. },
  4614. /**
  4615. * Remove self from zrender instance.
  4616. * Not recursively because it will be invoked when element added to storage.
  4617. * @param {module:zrender/ZRender} zr
  4618. */
  4619. removeSelfFromZr: function (zr) {
  4620. this.__zr = null;
  4621. // 移除动画
  4622. var animators = this.animators;
  4623. if (animators) {
  4624. for (var i = 0; i < animators.length; i++) {
  4625. zr.animation.removeAnimator(animators[i]);
  4626. }
  4627. }
  4628. if (this.clipPath) {
  4629. this.clipPath.removeSelfFromZr(zr);
  4630. }
  4631. }
  4632. };
  4633. mixin(Element, Animatable);
  4634. mixin(Element, Transformable);
  4635. mixin(Element, Eventful);
  4636. /**
  4637. * @module echarts/core/BoundingRect
  4638. */
  4639. var v2ApplyTransform = applyTransform;
  4640. var mathMin = Math.min;
  4641. var mathMax = Math.max;
  4642. /**
  4643. * @alias module:echarts/core/BoundingRect
  4644. */
  4645. function BoundingRect(x, y, width, height) {
  4646. if (width < 0) {
  4647. x = x + width;
  4648. width = -width;
  4649. }
  4650. if (height < 0) {
  4651. y = y + height;
  4652. height = -height;
  4653. }
  4654. /**
  4655. * @type {number}
  4656. */
  4657. this.x = x;
  4658. /**
  4659. * @type {number}
  4660. */
  4661. this.y = y;
  4662. /**
  4663. * @type {number}
  4664. */
  4665. this.width = width;
  4666. /**
  4667. * @type {number}
  4668. */
  4669. this.height = height;
  4670. }
  4671. BoundingRect.prototype = {
  4672. constructor: BoundingRect,
  4673. /**
  4674. * @param {module:echarts/core/BoundingRect} other
  4675. */
  4676. union: function (other) {
  4677. var x = mathMin(other.x, this.x);
  4678. var y = mathMin(other.y, this.y);
  4679. this.width = mathMax(
  4680. other.x + other.width,
  4681. this.x + this.width
  4682. ) - x;
  4683. this.height = mathMax(
  4684. other.y + other.height,
  4685. this.y + this.height
  4686. ) - y;
  4687. this.x = x;
  4688. this.y = y;
  4689. },
  4690. /**
  4691. * @param {Array.<number>} m
  4692. * @methods
  4693. */
  4694. applyTransform: (function () {
  4695. var lt = [];
  4696. var rb = [];
  4697. var lb = [];
  4698. var rt = [];
  4699. return function (m) {
  4700. // In case usage like this
  4701. // el.getBoundingRect().applyTransform(el.transform)
  4702. // And element has no transform
  4703. if (!m) {
  4704. return;
  4705. }
  4706. lt[0] = lb[0] = this.x;
  4707. lt[1] = rt[1] = this.y;
  4708. rb[0] = rt[0] = this.x + this.width;
  4709. rb[1] = lb[1] = this.y + this.height;
  4710. v2ApplyTransform(lt, lt, m);
  4711. v2ApplyTransform(rb, rb, m);
  4712. v2ApplyTransform(lb, lb, m);
  4713. v2ApplyTransform(rt, rt, m);
  4714. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4715. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4716. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4717. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4718. this.width = maxX - this.x;
  4719. this.height = maxY - this.y;
  4720. };
  4721. })(),
  4722. /**
  4723. * Calculate matrix of transforming from self to target rect
  4724. * @param {module:zrender/core/BoundingRect} b
  4725. * @return {Array.<number>}
  4726. */
  4727. calculateTransform: function (b) {
  4728. var a = this;
  4729. var sx = b.width / a.width;
  4730. var sy = b.height / a.height;
  4731. var m = create$1();
  4732. // 矩阵右乘
  4733. translate(m, m, [-a.x, -a.y]);
  4734. scale$1(m, m, [sx, sy]);
  4735. translate(m, m, [b.x, b.y]);
  4736. return m;
  4737. },
  4738. /**
  4739. * @param {(module:echarts/core/BoundingRect|Object)} b
  4740. * @return {boolean}
  4741. */
  4742. intersect: function (b) {
  4743. if (!b) {
  4744. return false;
  4745. }
  4746. if (!(b instanceof BoundingRect)) {
  4747. // Normalize negative width/height.
  4748. b = BoundingRect.create(b);
  4749. }
  4750. var a = this;
  4751. var ax0 = a.x;
  4752. var ax1 = a.x + a.width;
  4753. var ay0 = a.y;
  4754. var ay1 = a.y + a.height;
  4755. var bx0 = b.x;
  4756. var bx1 = b.x + b.width;
  4757. var by0 = b.y;
  4758. var by1 = b.y + b.height;
  4759. return !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4760. },
  4761. contain: function (x, y) {
  4762. var rect = this;
  4763. return x >= rect.x
  4764. && x <= (rect.x + rect.width)
  4765. && y >= rect.y
  4766. && y <= (rect.y + rect.height);
  4767. },
  4768. /**
  4769. * @return {module:echarts/core/BoundingRect}
  4770. */
  4771. clone: function () {
  4772. return new BoundingRect(this.x, this.y, this.width, this.height);
  4773. },
  4774. /**
  4775. * Copy from another rect
  4776. */
  4777. copy: function (other) {
  4778. this.x = other.x;
  4779. this.y = other.y;
  4780. this.width = other.width;
  4781. this.height = other.height;
  4782. },
  4783. plain: function () {
  4784. return {
  4785. x: this.x,
  4786. y: this.y,
  4787. width: this.width,
  4788. height: this.height
  4789. };
  4790. }
  4791. };
  4792. /**
  4793. * @param {Object|module:zrender/core/BoundingRect} rect
  4794. * @param {number} rect.x
  4795. * @param {number} rect.y
  4796. * @param {number} rect.width
  4797. * @param {number} rect.height
  4798. * @return {module:zrender/core/BoundingRect}
  4799. */
  4800. BoundingRect.create = function (rect) {
  4801. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4802. };
  4803. /**
  4804. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  4805. * @module zrender/graphic/Group
  4806. * @example
  4807. * var Group = require('zrender/container/Group');
  4808. * var Circle = require('zrender/graphic/shape/Circle');
  4809. * var g = new Group();
  4810. * g.position[0] = 100;
  4811. * g.position[1] = 100;
  4812. * g.add(new Circle({
  4813. * style: {
  4814. * x: 100,
  4815. * y: 100,
  4816. * r: 20,
  4817. * }
  4818. * }));
  4819. * zr.add(g);
  4820. */
  4821. /**
  4822. * @alias module:zrender/graphic/Group
  4823. * @constructor
  4824. * @extends module:zrender/mixin/Transformable
  4825. * @extends module:zrender/mixin/Eventful
  4826. */
  4827. var Group = function (opts) {
  4828. opts = opts || {};
  4829. Element.call(this, opts);
  4830. for (var key in opts) {
  4831. if (opts.hasOwnProperty(key)) {
  4832. this[key] = opts[key];
  4833. }
  4834. }
  4835. this._children = [];
  4836. this.__storage = null;
  4837. this.__dirty = true;
  4838. };
  4839. Group.prototype = {
  4840. constructor: Group,
  4841. isGroup: true,
  4842. /**
  4843. * @type {string}
  4844. */
  4845. type: 'group',
  4846. /**
  4847. * 所有子孙元素是否响应鼠标事件
  4848. * @name module:/zrender/container/Group#silent
  4849. * @type {boolean}
  4850. * @default false
  4851. */
  4852. silent: false,
  4853. /**
  4854. * @return {Array.<module:zrender/Element>}
  4855. */
  4856. children: function () {
  4857. return this._children.slice();
  4858. },
  4859. /**
  4860. * 获取指定 index 的儿子节点
  4861. * @param {number} idx
  4862. * @return {module:zrender/Element}
  4863. */
  4864. childAt: function (idx) {
  4865. return this._children[idx];
  4866. },
  4867. /**
  4868. * 获取指定名字的儿子节点
  4869. * @param {string} name
  4870. * @return {module:zrender/Element}
  4871. */
  4872. childOfName: function (name) {
  4873. var children = this._children;
  4874. for (var i = 0; i < children.length; i++) {
  4875. if (children[i].name === name) {
  4876. return children[i];
  4877. }
  4878. }
  4879. },
  4880. /**
  4881. * @return {number}
  4882. */
  4883. childCount: function () {
  4884. return this._children.length;
  4885. },
  4886. /**
  4887. * 添加子节点到最后
  4888. * @param {module:zrender/Element} child
  4889. */
  4890. add: function (child) {
  4891. if (child && child !== this && child.parent !== this) {
  4892. this._children.push(child);
  4893. this._doAdd(child);
  4894. }
  4895. return this;
  4896. },
  4897. /**
  4898. * 添加子节点在 nextSibling 之前
  4899. * @param {module:zrender/Element} child
  4900. * @param {module:zrender/Element} nextSibling
  4901. */
  4902. addBefore: function (child, nextSibling) {
  4903. if (child && child !== this && child.parent !== this
  4904. && nextSibling && nextSibling.parent === this) {
  4905. var children = this._children;
  4906. var idx = children.indexOf(nextSibling);
  4907. if (idx >= 0) {
  4908. children.splice(idx, 0, child);
  4909. this._doAdd(child);
  4910. }
  4911. }
  4912. return this;
  4913. },
  4914. _doAdd: function (child) {
  4915. if (child.parent) {
  4916. child.parent.remove(child);
  4917. }
  4918. child.parent = this;
  4919. var storage = this.__storage;
  4920. var zr = this.__zr;
  4921. if (storage && storage !== child.__storage) {
  4922. storage.addToStorage(child);
  4923. if (child instanceof Group) {
  4924. child.addChildrenToStorage(storage);
  4925. }
  4926. }
  4927. zr && zr.refresh();
  4928. },
  4929. /**
  4930. * 移除子节点
  4931. * @param {module:zrender/Element} child
  4932. */
  4933. remove: function (child) {
  4934. var zr = this.__zr;
  4935. var storage = this.__storage;
  4936. var children = this._children;
  4937. var idx = indexOf(children, child);
  4938. if (idx < 0) {
  4939. return this;
  4940. }
  4941. children.splice(idx, 1);
  4942. child.parent = null;
  4943. if (storage) {
  4944. storage.delFromStorage(child);
  4945. if (child instanceof Group) {
  4946. child.delChildrenFromStorage(storage);
  4947. }
  4948. }
  4949. zr && zr.refresh();
  4950. return this;
  4951. },
  4952. /**
  4953. * 移除所有子节点
  4954. */
  4955. removeAll: function () {
  4956. var children = this._children;
  4957. var storage = this.__storage;
  4958. var child;
  4959. var i;
  4960. for (i = 0; i < children.length; i++) {
  4961. child = children[i];
  4962. if (storage) {
  4963. storage.delFromStorage(child);
  4964. if (child instanceof Group) {
  4965. child.delChildrenFromStorage(storage);
  4966. }
  4967. }
  4968. child.parent = null;
  4969. }
  4970. children.length = 0;
  4971. return this;
  4972. },
  4973. /**
  4974. * 遍历所有子节点
  4975. * @param {Function} cb
  4976. * @param {} context
  4977. */
  4978. eachChild: function (cb, context) {
  4979. var children = this._children;
  4980. for (var i = 0; i < children.length; i++) {
  4981. var child = children[i];
  4982. cb.call(context, child, i);
  4983. }
  4984. return this;
  4985. },
  4986. /**
  4987. * 深度优先遍历所有子孙节点
  4988. * @param {Function} cb
  4989. * @param {} context
  4990. */
  4991. traverse: function (cb, context) {
  4992. for (var i = 0; i < this._children.length; i++) {
  4993. var child = this._children[i];
  4994. cb.call(context, child);
  4995. if (child.type === 'group') {
  4996. child.traverse(cb, context);
  4997. }
  4998. }
  4999. return this;
  5000. },
  5001. addChildrenToStorage: function (storage) {
  5002. for (var i = 0; i < this._children.length; i++) {
  5003. var child = this._children[i];
  5004. storage.addToStorage(child);
  5005. if (child instanceof Group) {
  5006. child.addChildrenToStorage(storage);
  5007. }
  5008. }
  5009. },
  5010. delChildrenFromStorage: function (storage) {
  5011. for (var i = 0; i < this._children.length; i++) {
  5012. var child = this._children[i];
  5013. storage.delFromStorage(child);
  5014. if (child instanceof Group) {
  5015. child.delChildrenFromStorage(storage);
  5016. }
  5017. }
  5018. },
  5019. dirty: function () {
  5020. this.__dirty = true;
  5021. this.__zr && this.__zr.refresh();
  5022. return this;
  5023. },
  5024. /**
  5025. * @return {module:zrender/core/BoundingRect}
  5026. */
  5027. getBoundingRect: function (includeChildren) {
  5028. // TODO Caching
  5029. var rect = null;
  5030. var tmpRect = new BoundingRect(0, 0, 0, 0);
  5031. var children = includeChildren || this._children;
  5032. var tmpMat = [];
  5033. for (var i = 0; i < children.length; i++) {
  5034. var child = children[i];
  5035. if (child.ignore || child.invisible) {
  5036. continue;
  5037. }
  5038. var childRect = child.getBoundingRect();
  5039. var transform = child.getLocalTransform(tmpMat);
  5040. // TODO
  5041. // The boundingRect cacluated by transforming original
  5042. // rect may be bigger than the actual bundingRect when rotation
  5043. // is used. (Consider a circle rotated aginst its center, where
  5044. // the actual boundingRect should be the same as that not be
  5045. // rotated.) But we can not find better approach to calculate
  5046. // actual boundingRect yet, considering performance.
  5047. if (transform) {
  5048. tmpRect.copy(childRect);
  5049. tmpRect.applyTransform(transform);
  5050. rect = rect || tmpRect.clone();
  5051. rect.union(tmpRect);
  5052. }
  5053. else {
  5054. rect = rect || childRect.clone();
  5055. rect.union(childRect);
  5056. }
  5057. }
  5058. return rect || tmpRect;
  5059. }
  5060. };
  5061. inherits(Group, Element);
  5062. // https://github.com/mziccard/node-timsort
  5063. var DEFAULT_MIN_MERGE = 32;
  5064. var DEFAULT_MIN_GALLOPING = 7;
  5065. function minRunLength(n) {
  5066. var r = 0;
  5067. while (n >= DEFAULT_MIN_MERGE) {
  5068. r |= n & 1;
  5069. n >>= 1;
  5070. }
  5071. return n + r;
  5072. }
  5073. function makeAscendingRun(array, lo, hi, compare) {
  5074. var runHi = lo + 1;
  5075. if (runHi === hi) {
  5076. return 1;
  5077. }
  5078. if (compare(array[runHi++], array[lo]) < 0) {
  5079. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  5080. runHi++;
  5081. }
  5082. reverseRun(array, lo, runHi);
  5083. }
  5084. else {
  5085. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  5086. runHi++;
  5087. }
  5088. }
  5089. return runHi - lo;
  5090. }
  5091. function reverseRun(array, lo, hi) {
  5092. hi--;
  5093. while (lo < hi) {
  5094. var t = array[lo];
  5095. array[lo++] = array[hi];
  5096. array[hi--] = t;
  5097. }
  5098. }
  5099. function binaryInsertionSort(array, lo, hi, start, compare) {
  5100. if (start === lo) {
  5101. start++;
  5102. }
  5103. for (; start < hi; start++) {
  5104. var pivot = array[start];
  5105. var left = lo;
  5106. var right = start;
  5107. var mid;
  5108. while (left < right) {
  5109. mid = left + right >>> 1;
  5110. if (compare(pivot, array[mid]) < 0) {
  5111. right = mid;
  5112. }
  5113. else {
  5114. left = mid + 1;
  5115. }
  5116. }
  5117. var n = start - left;
  5118. switch (n) {
  5119. case 3:
  5120. array[left + 3] = array[left + 2];
  5121. case 2:
  5122. array[left + 2] = array[left + 1];
  5123. case 1:
  5124. array[left + 1] = array[left];
  5125. break;
  5126. default:
  5127. while (n > 0) {
  5128. array[left + n] = array[left + n - 1];
  5129. n--;
  5130. }
  5131. }
  5132. array[left] = pivot;
  5133. }
  5134. }
  5135. function gallopLeft(value, array, start, length, hint, compare) {
  5136. var lastOffset = 0;
  5137. var maxOffset = 0;
  5138. var offset = 1;
  5139. if (compare(value, array[start + hint]) > 0) {
  5140. maxOffset = length - hint;
  5141. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  5142. lastOffset = offset;
  5143. offset = (offset << 1) + 1;
  5144. if (offset <= 0) {
  5145. offset = maxOffset;
  5146. }
  5147. }
  5148. if (offset > maxOffset) {
  5149. offset = maxOffset;
  5150. }
  5151. lastOffset += hint;
  5152. offset += hint;
  5153. }
  5154. else {
  5155. maxOffset = hint + 1;
  5156. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  5157. lastOffset = offset;
  5158. offset = (offset << 1) + 1;
  5159. if (offset <= 0) {
  5160. offset = maxOffset;
  5161. }
  5162. }
  5163. if (offset > maxOffset) {
  5164. offset = maxOffset;
  5165. }
  5166. var tmp = lastOffset;
  5167. lastOffset = hint - offset;
  5168. offset = hint - tmp;
  5169. }
  5170. lastOffset++;
  5171. while (lastOffset < offset) {
  5172. var m = lastOffset + (offset - lastOffset >>> 1);
  5173. if (compare(value, array[start + m]) > 0) {
  5174. lastOffset = m + 1;
  5175. }
  5176. else {
  5177. offset = m;
  5178. }
  5179. }
  5180. return offset;
  5181. }
  5182. function gallopRight(value, array, start, length, hint, compare) {
  5183. var lastOffset = 0;
  5184. var maxOffset = 0;
  5185. var offset = 1;
  5186. if (compare(value, array[start + hint]) < 0) {
  5187. maxOffset = hint + 1;
  5188. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  5189. lastOffset = offset;
  5190. offset = (offset << 1) + 1;
  5191. if (offset <= 0) {
  5192. offset = maxOffset;
  5193. }
  5194. }
  5195. if (offset > maxOffset) {
  5196. offset = maxOffset;
  5197. }
  5198. var tmp = lastOffset;
  5199. lastOffset = hint - offset;
  5200. offset = hint - tmp;
  5201. }
  5202. else {
  5203. maxOffset = length - hint;
  5204. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  5205. lastOffset = offset;
  5206. offset = (offset << 1) + 1;
  5207. if (offset <= 0) {
  5208. offset = maxOffset;
  5209. }
  5210. }
  5211. if (offset > maxOffset) {
  5212. offset = maxOffset;
  5213. }
  5214. lastOffset += hint;
  5215. offset += hint;
  5216. }
  5217. lastOffset++;
  5218. while (lastOffset < offset) {
  5219. var m = lastOffset + (offset - lastOffset >>> 1);
  5220. if (compare(value, array[start + m]) < 0) {
  5221. offset = m;
  5222. }
  5223. else {
  5224. lastOffset = m + 1;
  5225. }
  5226. }
  5227. return offset;
  5228. }
  5229. function TimSort(array, compare) {
  5230. var minGallop = DEFAULT_MIN_GALLOPING;
  5231. var runStart;
  5232. var runLength;
  5233. var stackSize = 0;
  5234. var tmp = [];
  5235. runStart = [];
  5236. runLength = [];
  5237. function pushRun(_runStart, _runLength) {
  5238. runStart[stackSize] = _runStart;
  5239. runLength[stackSize] = _runLength;
  5240. stackSize += 1;
  5241. }
  5242. function mergeRuns() {
  5243. while (stackSize > 1) {
  5244. var n = stackSize - 2;
  5245. if (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1] || n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1]) {
  5246. if (runLength[n - 1] < runLength[n + 1]) {
  5247. n--;
  5248. }
  5249. }
  5250. else if (runLength[n] > runLength[n + 1]) {
  5251. break;
  5252. }
  5253. mergeAt(n);
  5254. }
  5255. }
  5256. function forceMergeRuns() {
  5257. while (stackSize > 1) {
  5258. var n = stackSize - 2;
  5259. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  5260. n--;
  5261. }
  5262. mergeAt(n);
  5263. }
  5264. }
  5265. function mergeAt(i) {
  5266. var start1 = runStart[i];
  5267. var length1 = runLength[i];
  5268. var start2 = runStart[i + 1];
  5269. var length2 = runLength[i + 1];
  5270. runLength[i] = length1 + length2;
  5271. if (i === stackSize - 3) {
  5272. runStart[i + 1] = runStart[i + 2];
  5273. runLength[i + 1] = runLength[i + 2];
  5274. }
  5275. stackSize--;
  5276. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  5277. start1 += k;
  5278. length1 -= k;
  5279. if (length1 === 0) {
  5280. return;
  5281. }
  5282. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  5283. if (length2 === 0) {
  5284. return;
  5285. }
  5286. if (length1 <= length2) {
  5287. mergeLow(start1, length1, start2, length2);
  5288. }
  5289. else {
  5290. mergeHigh(start1, length1, start2, length2);
  5291. }
  5292. }
  5293. function mergeLow(start1, length1, start2, length2) {
  5294. var i = 0;
  5295. for (i = 0; i < length1; i++) {
  5296. tmp[i] = array[start1 + i];
  5297. }
  5298. var cursor1 = 0;
  5299. var cursor2 = start2;
  5300. var dest = start1;
  5301. array[dest++] = array[cursor2++];
  5302. if (--length2 === 0) {
  5303. for (i = 0; i < length1; i++) {
  5304. array[dest + i] = tmp[cursor1 + i];
  5305. }
  5306. return;
  5307. }
  5308. if (length1 === 1) {
  5309. for (i = 0; i < length2; i++) {
  5310. array[dest + i] = array[cursor2 + i];
  5311. }
  5312. array[dest + length2] = tmp[cursor1];
  5313. return;
  5314. }
  5315. var _minGallop = minGallop;
  5316. var count1, count2, exit;
  5317. while (1) {
  5318. count1 = 0;
  5319. count2 = 0;
  5320. exit = false;
  5321. do {
  5322. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  5323. array[dest++] = array[cursor2++];
  5324. count2++;
  5325. count1 = 0;
  5326. if (--length2 === 0) {
  5327. exit = true;
  5328. break;
  5329. }
  5330. }
  5331. else {
  5332. array[dest++] = tmp[cursor1++];
  5333. count1++;
  5334. count2 = 0;
  5335. if (--length1 === 1) {
  5336. exit = true;
  5337. break;
  5338. }
  5339. }
  5340. } while ((count1 | count2) < _minGallop);
  5341. if (exit) {
  5342. break;
  5343. }
  5344. do {
  5345. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  5346. if (count1 !== 0) {
  5347. for (i = 0; i < count1; i++) {
  5348. array[dest + i] = tmp[cursor1 + i];
  5349. }
  5350. dest += count1;
  5351. cursor1 += count1;
  5352. length1 -= count1;
  5353. if (length1 <= 1) {
  5354. exit = true;
  5355. break;
  5356. }
  5357. }
  5358. array[dest++] = array[cursor2++];
  5359. if (--length2 === 0) {
  5360. exit = true;
  5361. break;
  5362. }
  5363. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  5364. if (count2 !== 0) {
  5365. for (i = 0; i < count2; i++) {
  5366. array[dest + i] = array[cursor2 + i];
  5367. }
  5368. dest += count2;
  5369. cursor2 += count2;
  5370. length2 -= count2;
  5371. if (length2 === 0) {
  5372. exit = true;
  5373. break;
  5374. }
  5375. }
  5376. array[dest++] = tmp[cursor1++];
  5377. if (--length1 === 1) {
  5378. exit = true;
  5379. break;
  5380. }
  5381. _minGallop--;
  5382. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5383. if (exit) {
  5384. break;
  5385. }
  5386. if (_minGallop < 0) {
  5387. _minGallop = 0;
  5388. }
  5389. _minGallop += 2;
  5390. }
  5391. minGallop = _minGallop;
  5392. minGallop < 1 && (minGallop = 1);
  5393. if (length1 === 1) {
  5394. for (i = 0; i < length2; i++) {
  5395. array[dest + i] = array[cursor2 + i];
  5396. }
  5397. array[dest + length2] = tmp[cursor1];
  5398. }
  5399. else if (length1 === 0) {
  5400. throw new Error();
  5401. // throw new Error('mergeLow preconditions were not respected');
  5402. }
  5403. else {
  5404. for (i = 0; i < length1; i++) {
  5405. array[dest + i] = tmp[cursor1 + i];
  5406. }
  5407. }
  5408. }
  5409. function mergeHigh(start1, length1, start2, length2) {
  5410. var i = 0;
  5411. for (i = 0; i < length2; i++) {
  5412. tmp[i] = array[start2 + i];
  5413. }
  5414. var cursor1 = start1 + length1 - 1;
  5415. var cursor2 = length2 - 1;
  5416. var dest = start2 + length2 - 1;
  5417. var customCursor = 0;
  5418. var customDest = 0;
  5419. array[dest--] = array[cursor1--];
  5420. if (--length1 === 0) {
  5421. customCursor = dest - (length2 - 1);
  5422. for (i = 0; i < length2; i++) {
  5423. array[customCursor + i] = tmp[i];
  5424. }
  5425. return;
  5426. }
  5427. if (length2 === 1) {
  5428. dest -= length1;
  5429. cursor1 -= length1;
  5430. customDest = dest + 1;
  5431. customCursor = cursor1 + 1;
  5432. for (i = length1 - 1; i >= 0; i--) {
  5433. array[customDest + i] = array[customCursor + i];
  5434. }
  5435. array[dest] = tmp[cursor2];
  5436. return;
  5437. }
  5438. var _minGallop = minGallop;
  5439. while (true) {
  5440. var count1 = 0;
  5441. var count2 = 0;
  5442. var exit = false;
  5443. do {
  5444. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  5445. array[dest--] = array[cursor1--];
  5446. count1++;
  5447. count2 = 0;
  5448. if (--length1 === 0) {
  5449. exit = true;
  5450. break;
  5451. }
  5452. }
  5453. else {
  5454. array[dest--] = tmp[cursor2--];
  5455. count2++;
  5456. count1 = 0;
  5457. if (--length2 === 1) {
  5458. exit = true;
  5459. break;
  5460. }
  5461. }
  5462. } while ((count1 | count2) < _minGallop);
  5463. if (exit) {
  5464. break;
  5465. }
  5466. do {
  5467. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  5468. if (count1 !== 0) {
  5469. dest -= count1;
  5470. cursor1 -= count1;
  5471. length1 -= count1;
  5472. customDest = dest + 1;
  5473. customCursor = cursor1 + 1;
  5474. for (i = count1 - 1; i >= 0; i--) {
  5475. array[customDest + i] = array[customCursor + i];
  5476. }
  5477. if (length1 === 0) {
  5478. exit = true;
  5479. break;
  5480. }
  5481. }
  5482. array[dest--] = tmp[cursor2--];
  5483. if (--length2 === 1) {
  5484. exit = true;
  5485. break;
  5486. }
  5487. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  5488. if (count2 !== 0) {
  5489. dest -= count2;
  5490. cursor2 -= count2;
  5491. length2 -= count2;
  5492. customDest = dest + 1;
  5493. customCursor = cursor2 + 1;
  5494. for (i = 0; i < count2; i++) {
  5495. array[customDest + i] = tmp[customCursor + i];
  5496. }
  5497. if (length2 <= 1) {
  5498. exit = true;
  5499. break;
  5500. }
  5501. }
  5502. array[dest--] = array[cursor1--];
  5503. if (--length1 === 0) {
  5504. exit = true;
  5505. break;
  5506. }
  5507. _minGallop--;
  5508. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5509. if (exit) {
  5510. break;
  5511. }
  5512. if (_minGallop < 0) {
  5513. _minGallop = 0;
  5514. }
  5515. _minGallop += 2;
  5516. }
  5517. minGallop = _minGallop;
  5518. if (minGallop < 1) {
  5519. minGallop = 1;
  5520. }
  5521. if (length2 === 1) {
  5522. dest -= length1;
  5523. cursor1 -= length1;
  5524. customDest = dest + 1;
  5525. customCursor = cursor1 + 1;
  5526. for (i = length1 - 1; i >= 0; i--) {
  5527. array[customDest + i] = array[customCursor + i];
  5528. }
  5529. array[dest] = tmp[cursor2];
  5530. }
  5531. else if (length2 === 0) {
  5532. throw new Error();
  5533. // throw new Error('mergeHigh preconditions were not respected');
  5534. }
  5535. else {
  5536. customCursor = dest - (length2 - 1);
  5537. for (i = 0; i < length2; i++) {
  5538. array[customCursor + i] = tmp[i];
  5539. }
  5540. }
  5541. }
  5542. this.mergeRuns = mergeRuns;
  5543. this.forceMergeRuns = forceMergeRuns;
  5544. this.pushRun = pushRun;
  5545. }
  5546. function sort(array, compare, lo, hi) {
  5547. if (!lo) {
  5548. lo = 0;
  5549. }
  5550. if (!hi) {
  5551. hi = array.length;
  5552. }
  5553. var remaining = hi - lo;
  5554. if (remaining < 2) {
  5555. return;
  5556. }
  5557. var runLength = 0;
  5558. if (remaining < DEFAULT_MIN_MERGE) {
  5559. runLength = makeAscendingRun(array, lo, hi, compare);
  5560. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  5561. return;
  5562. }
  5563. var ts = new TimSort(array, compare);
  5564. var minRun = minRunLength(remaining);
  5565. do {
  5566. runLength = makeAscendingRun(array, lo, hi, compare);
  5567. if (runLength < minRun) {
  5568. var force = remaining;
  5569. if (force > minRun) {
  5570. force = minRun;
  5571. }
  5572. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  5573. runLength = force;
  5574. }
  5575. ts.pushRun(lo, runLength);
  5576. ts.mergeRuns();
  5577. remaining -= runLength;
  5578. lo += runLength;
  5579. } while (remaining !== 0);
  5580. ts.forceMergeRuns();
  5581. }
  5582. // Use timsort because in most case elements are partially sorted
  5583. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  5584. function shapeCompareFunc(a, b) {
  5585. if (a.zlevel === b.zlevel) {
  5586. if (a.z === b.z) {
  5587. // if (a.z2 === b.z2) {
  5588. // // FIXME Slow has renderidx compare
  5589. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  5590. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  5591. // return a.__renderidx - b.__renderidx;
  5592. // }
  5593. return a.z2 - b.z2;
  5594. }
  5595. return a.z - b.z;
  5596. }
  5597. return a.zlevel - b.zlevel;
  5598. }
  5599. /**
  5600. * 内容仓库 (M)
  5601. * @alias module:zrender/Storage
  5602. * @constructor
  5603. */
  5604. var Storage = function () { // jshint ignore:line
  5605. this._roots = [];
  5606. this._displayList = [];
  5607. this._displayListLen = 0;
  5608. };
  5609. Storage.prototype = {
  5610. constructor: Storage,
  5611. /**
  5612. * @param {Function} cb
  5613. *
  5614. */
  5615. traverse: function (cb, context) {
  5616. for (var i = 0; i < this._roots.length; i++) {
  5617. this._roots[i].traverse(cb, context);
  5618. }
  5619. },
  5620. /**
  5621. * 返回所有图形的绘制队列
  5622. * @param {boolean} [update=false] 是否在返回前更新该数组
  5623. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  5624. *
  5625. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  5626. * @return {Array.<module:zrender/graphic/Displayable>}
  5627. */
  5628. getDisplayList: function (update, includeIgnore) {
  5629. includeIgnore = includeIgnore || false;
  5630. if (update) {
  5631. this.updateDisplayList(includeIgnore);
  5632. }
  5633. return this._displayList;
  5634. },
  5635. /**
  5636. * 更新图形的绘制队列。
  5637. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  5638. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  5639. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  5640. */
  5641. updateDisplayList: function (includeIgnore) {
  5642. this._displayListLen = 0;
  5643. var roots = this._roots;
  5644. var displayList = this._displayList;
  5645. for (var i = 0, len = roots.length; i < len; i++) {
  5646. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  5647. }
  5648. displayList.length = this._displayListLen;
  5649. env$1.canvasSupported && sort(displayList, shapeCompareFunc);
  5650. },
  5651. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  5652. if (el.ignore && !includeIgnore) {
  5653. return;
  5654. }
  5655. el.beforeUpdate();
  5656. if (el.__dirty) {
  5657. el.update();
  5658. }
  5659. el.afterUpdate();
  5660. var userSetClipPath = el.clipPath;
  5661. if (userSetClipPath) {
  5662. // FIXME 效率影响
  5663. if (clipPaths) {
  5664. clipPaths = clipPaths.slice();
  5665. }
  5666. else {
  5667. clipPaths = [];
  5668. }
  5669. var currentClipPath = userSetClipPath;
  5670. var parentClipPath = el;
  5671. // Recursively add clip path
  5672. while (currentClipPath) {
  5673. // clipPath 的变换是基于使用这个 clipPath 的元素
  5674. currentClipPath.parent = parentClipPath;
  5675. currentClipPath.updateTransform();
  5676. clipPaths.push(currentClipPath);
  5677. parentClipPath = currentClipPath;
  5678. currentClipPath = currentClipPath.clipPath;
  5679. }
  5680. }
  5681. if (el.isGroup) {
  5682. var children = el._children;
  5683. for (var i = 0; i < children.length; i++) {
  5684. var child = children[i];
  5685. // Force to mark as dirty if group is dirty
  5686. // FIXME __dirtyPath ?
  5687. if (el.__dirty) {
  5688. child.__dirty = true;
  5689. }
  5690. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  5691. }
  5692. // Mark group clean here
  5693. el.__dirty = false;
  5694. }
  5695. else {
  5696. el.__clipPaths = clipPaths;
  5697. this._displayList[this._displayListLen++] = el;
  5698. }
  5699. },
  5700. /**
  5701. * 添加图形(Shape)或者组(Group)到根节点
  5702. * @param {module:zrender/Element} el
  5703. */
  5704. addRoot: function (el) {
  5705. if (el.__storage === this) {
  5706. return;
  5707. }
  5708. if (el instanceof Group) {
  5709. el.addChildrenToStorage(this);
  5710. }
  5711. this.addToStorage(el);
  5712. this._roots.push(el);
  5713. },
  5714. /**
  5715. * 删除指定的图形(Shape)或者组(Group)
  5716. * @param {string|Array.<string>} [el] 如果为空清空整个Storage
  5717. */
  5718. delRoot: function (el) {
  5719. if (el == null) {
  5720. // 不指定el清空
  5721. for (var i = 0; i < this._roots.length; i++) {
  5722. var root = this._roots[i];
  5723. if (root instanceof Group) {
  5724. root.delChildrenFromStorage(this);
  5725. }
  5726. }
  5727. this._roots = [];
  5728. this._displayList = [];
  5729. this._displayListLen = 0;
  5730. return;
  5731. }
  5732. if (el instanceof Array) {
  5733. for (var i = 0, l = el.length; i < l; i++) {
  5734. this.delRoot(el[i]);
  5735. }
  5736. return;
  5737. }
  5738. var idx = indexOf(this._roots, el);
  5739. if (idx >= 0) {
  5740. this.delFromStorage(el);
  5741. this._roots.splice(idx, 1);
  5742. if (el instanceof Group) {
  5743. el.delChildrenFromStorage(this);
  5744. }
  5745. }
  5746. },
  5747. addToStorage: function (el) {
  5748. if (el) {
  5749. el.__storage = this;
  5750. el.dirty(false);
  5751. }
  5752. return this;
  5753. },
  5754. delFromStorage: function (el) {
  5755. if (el) {
  5756. el.__storage = null;
  5757. }
  5758. return this;
  5759. },
  5760. /**
  5761. * 清空并且释放Storage
  5762. */
  5763. dispose: function () {
  5764. this._renderList =
  5765. this._roots = null;
  5766. },
  5767. displayableSortFunc: shapeCompareFunc
  5768. };
  5769. var SHADOW_PROPS = {
  5770. 'shadowBlur': 1,
  5771. 'shadowOffsetX': 1,
  5772. 'shadowOffsetY': 1,
  5773. 'textShadowBlur': 1,
  5774. 'textShadowOffsetX': 1,
  5775. 'textShadowOffsetY': 1,
  5776. 'textBoxShadowBlur': 1,
  5777. 'textBoxShadowOffsetX': 1,
  5778. 'textBoxShadowOffsetY': 1
  5779. };
  5780. var fixShadow = function (ctx, propName, value) {
  5781. if (SHADOW_PROPS.hasOwnProperty(propName)) {
  5782. return value *= ctx.dpr;
  5783. }
  5784. return value;
  5785. };
  5786. var ContextCachedBy = {
  5787. NONE: 0,
  5788. STYLE_BIND: 1,
  5789. PLAIN_TEXT: 2
  5790. };
  5791. // Avoid confused with 0/false.
  5792. var WILL_BE_RESTORED = 9;
  5793. var STYLE_COMMON_PROPS = [
  5794. ['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],
  5795. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  5796. ];
  5797. // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  5798. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  5799. var Style = function (opts) {
  5800. this.extendFrom(opts, false);
  5801. };
  5802. function createLinearGradient(ctx, obj, rect) {
  5803. var x = obj.x == null ? 0 : obj.x;
  5804. var x2 = obj.x2 == null ? 1 : obj.x2;
  5805. var y = obj.y == null ? 0 : obj.y;
  5806. var y2 = obj.y2 == null ? 0 : obj.y2;
  5807. if (!obj.global) {
  5808. x = x * rect.width + rect.x;
  5809. x2 = x2 * rect.width + rect.x;
  5810. y = y * rect.height + rect.y;
  5811. y2 = y2 * rect.height + rect.y;
  5812. }
  5813. // Fix NaN when rect is Infinity
  5814. x = isNaN(x) ? 0 : x;
  5815. x2 = isNaN(x2) ? 1 : x2;
  5816. y = isNaN(y) ? 0 : y;
  5817. y2 = isNaN(y2) ? 0 : y2;
  5818. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  5819. return canvasGradient;
  5820. }
  5821. function createRadialGradient(ctx, obj, rect) {
  5822. var width = rect.width;
  5823. var height = rect.height;
  5824. var min = Math.min(width, height);
  5825. var x = obj.x == null ? 0.5 : obj.x;
  5826. var y = obj.y == null ? 0.5 : obj.y;
  5827. var r = obj.r == null ? 0.5 : obj.r;
  5828. if (!obj.global) {
  5829. x = x * width + rect.x;
  5830. y = y * height + rect.y;
  5831. r = r * min;
  5832. }
  5833. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  5834. return canvasGradient;
  5835. }
  5836. Style.prototype = {
  5837. constructor: Style,
  5838. /**
  5839. * @type {string}
  5840. */
  5841. fill: '#000',
  5842. /**
  5843. * @type {string}
  5844. */
  5845. stroke: null,
  5846. /**
  5847. * @type {number}
  5848. */
  5849. opacity: 1,
  5850. /**
  5851. * @type {number}
  5852. */
  5853. fillOpacity: null,
  5854. /**
  5855. * @type {number}
  5856. */
  5857. strokeOpacity: null,
  5858. /**
  5859. * @type {Array.<number>}
  5860. */
  5861. lineDash: null,
  5862. /**
  5863. * @type {number}
  5864. */
  5865. lineDashOffset: 0,
  5866. /**
  5867. * @type {number}
  5868. */
  5869. shadowBlur: 0,
  5870. /**
  5871. * @type {number}
  5872. */
  5873. shadowOffsetX: 0,
  5874. /**
  5875. * @type {number}
  5876. */
  5877. shadowOffsetY: 0,
  5878. /**
  5879. * @type {number}
  5880. */
  5881. lineWidth: 1,
  5882. /**
  5883. * If stroke ignore scale
  5884. * @type {Boolean}
  5885. */
  5886. strokeNoScale: false,
  5887. // Bounding rect text configuration
  5888. // Not affected by element transform
  5889. /**
  5890. * @type {string}
  5891. */
  5892. text: null,
  5893. /**
  5894. * If `fontSize` or `fontFamily` exists, `font` will be reset by
  5895. * `fontSize`, `fontStyle`, `fontWeight`, `fontFamily`.
  5896. * So do not visit it directly in upper application (like echarts),
  5897. * but use `contain/text#makeFont` instead.
  5898. * @type {string}
  5899. */
  5900. font: null,
  5901. /**
  5902. * The same as font. Use font please.
  5903. * @deprecated
  5904. * @type {string}
  5905. */
  5906. textFont: null,
  5907. /**
  5908. * It helps merging respectively, rather than parsing an entire font string.
  5909. * @type {string}
  5910. */
  5911. fontStyle: null,
  5912. /**
  5913. * It helps merging respectively, rather than parsing an entire font string.
  5914. * @type {string}
  5915. */
  5916. fontWeight: null,
  5917. /**
  5918. * It helps merging respectively, rather than parsing an entire font string.
  5919. * Should be 12 but not '12px'.
  5920. * @type {number}
  5921. */
  5922. fontSize: null,
  5923. /**
  5924. * It helps merging respectively, rather than parsing an entire font string.
  5925. * @type {string}
  5926. */
  5927. fontFamily: null,
  5928. /**
  5929. * Reserved for special functinality, like 'hr'.
  5930. * @type {string}
  5931. */
  5932. textTag: null,
  5933. /**
  5934. * @type {string}
  5935. */
  5936. textFill: '#000',
  5937. /**
  5938. * @type {string}
  5939. */
  5940. textStroke: null,
  5941. /**
  5942. * @type {number}
  5943. */
  5944. textWidth: null,
  5945. /**
  5946. * Only for textBackground.
  5947. * @type {number}
  5948. */
  5949. textHeight: null,
  5950. /**
  5951. * textStroke may be set as some color as a default
  5952. * value in upper applicaion, where the default value
  5953. * of textStrokeWidth should be 0 to make sure that
  5954. * user can choose to do not use text stroke.
  5955. * @type {number}
  5956. */
  5957. textStrokeWidth: 0,
  5958. /**
  5959. * @type {number}
  5960. */
  5961. textLineHeight: null,
  5962. /**
  5963. * 'inside', 'left', 'right', 'top', 'bottom'
  5964. * [x, y]
  5965. * Based on x, y of rect.
  5966. * @type {string|Array.<number>}
  5967. * @default 'inside'
  5968. */
  5969. textPosition: 'inside',
  5970. /**
  5971. * If not specified, use the boundingRect of a `displayable`.
  5972. * @type {Object}
  5973. */
  5974. textRect: null,
  5975. /**
  5976. * [x, y]
  5977. * @type {Array.<number>}
  5978. */
  5979. textOffset: null,
  5980. /**
  5981. * @type {string}
  5982. */
  5983. textAlign: null,
  5984. /**
  5985. * @type {string}
  5986. */
  5987. textVerticalAlign: null,
  5988. /**
  5989. * @type {number}
  5990. */
  5991. textDistance: 5,
  5992. /**
  5993. * @type {string}
  5994. */
  5995. textShadowColor: 'transparent',
  5996. /**
  5997. * @type {number}
  5998. */
  5999. textShadowBlur: 0,
  6000. /**
  6001. * @type {number}
  6002. */
  6003. textShadowOffsetX: 0,
  6004. /**
  6005. * @type {number}
  6006. */
  6007. textShadowOffsetY: 0,
  6008. /**
  6009. * @type {string}
  6010. */
  6011. textBoxShadowColor: 'transparent',
  6012. /**
  6013. * @type {number}
  6014. */
  6015. textBoxShadowBlur: 0,
  6016. /**
  6017. * @type {number}
  6018. */
  6019. textBoxShadowOffsetX: 0,
  6020. /**
  6021. * @type {number}
  6022. */
  6023. textBoxShadowOffsetY: 0,
  6024. /**
  6025. * Whether transform text.
  6026. * Only useful in Path and Image element
  6027. * @type {boolean}
  6028. */
  6029. transformText: false,
  6030. /**
  6031. * Text rotate around position of Path or Image
  6032. * Only useful in Path and Image element and transformText is false.
  6033. */
  6034. textRotation: 0,
  6035. /**
  6036. * Text origin of text rotation, like [10, 40].
  6037. * Based on x, y of rect.
  6038. * Useful in label rotation of circular symbol.
  6039. * By default, this origin is textPosition.
  6040. * Can be 'center'.
  6041. * @type {string|Array.<number>}
  6042. */
  6043. textOrigin: null,
  6044. /**
  6045. * @type {string}
  6046. */
  6047. textBackgroundColor: null,
  6048. /**
  6049. * @type {string}
  6050. */
  6051. textBorderColor: null,
  6052. /**
  6053. * @type {number}
  6054. */
  6055. textBorderWidth: 0,
  6056. /**
  6057. * @type {number}
  6058. */
  6059. textBorderRadius: 0,
  6060. /**
  6061. * Can be `2` or `[2, 4]` or `[2, 3, 4, 5]`
  6062. * @type {number|Array.<number>}
  6063. */
  6064. textPadding: null,
  6065. /**
  6066. * Text styles for rich text.
  6067. * @type {Object}
  6068. */
  6069. rich: null,
  6070. /**
  6071. * {outerWidth, outerHeight, ellipsis, placeholder}
  6072. * @type {Object}
  6073. */
  6074. truncate: null,
  6075. /**
  6076. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  6077. * @type {string}
  6078. */
  6079. blend: null,
  6080. /**
  6081. * @param {CanvasRenderingContext2D} ctx
  6082. */
  6083. bind: function (ctx, el, prevEl) {
  6084. var style = this;
  6085. var prevStyle = prevEl && prevEl.style;
  6086. // If no prevStyle, it means first draw.
  6087. // Only apply cache if the last time cachced by this function.
  6088. var notCheckCache = !prevStyle || ctx.__attrCachedBy !== ContextCachedBy.STYLE_BIND;
  6089. ctx.__attrCachedBy = ContextCachedBy.STYLE_BIND;
  6090. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6091. var prop = STYLE_COMMON_PROPS[i];
  6092. var styleName = prop[0];
  6093. if (notCheckCache || style[styleName] !== prevStyle[styleName]) {
  6094. // FIXME Invalid property value will cause style leak from previous element.
  6095. ctx[styleName] =
  6096. fixShadow(ctx, styleName, style[styleName] || prop[1]);
  6097. }
  6098. }
  6099. if ((notCheckCache || style.fill !== prevStyle.fill)) {
  6100. ctx.fillStyle = style.fill;
  6101. }
  6102. if ((notCheckCache || style.stroke !== prevStyle.stroke)) {
  6103. ctx.strokeStyle = style.stroke;
  6104. }
  6105. if ((notCheckCache || style.opacity !== prevStyle.opacity)) {
  6106. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  6107. }
  6108. if ((notCheckCache || style.blend !== prevStyle.blend)) {
  6109. ctx.globalCompositeOperation = style.blend || 'source-over';
  6110. }
  6111. if (this.hasStroke()) {
  6112. var lineWidth = style.lineWidth;
  6113. ctx.lineWidth = lineWidth / (
  6114. (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1
  6115. );
  6116. }
  6117. },
  6118. hasFill: function () {
  6119. var fill = this.fill;
  6120. return fill != null && fill !== 'none';
  6121. },
  6122. hasStroke: function () {
  6123. var stroke = this.stroke;
  6124. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  6125. },
  6126. /**
  6127. * Extend from other style
  6128. * @param {zrender/graphic/Style} otherStyle
  6129. * @param {boolean} overwrite true: overwrirte any way.
  6130. * false: overwrite only when !target.hasOwnProperty
  6131. * others: overwrite when property is not null/undefined.
  6132. */
  6133. extendFrom: function (otherStyle, overwrite) {
  6134. if (otherStyle) {
  6135. for (var name in otherStyle) {
  6136. if (otherStyle.hasOwnProperty(name)
  6137. && (overwrite === true
  6138. || (
  6139. overwrite === false
  6140. ? !this.hasOwnProperty(name)
  6141. : otherStyle[name] != null
  6142. )
  6143. )
  6144. ) {
  6145. this[name] = otherStyle[name];
  6146. }
  6147. }
  6148. }
  6149. },
  6150. /**
  6151. * Batch setting style with a given object
  6152. * @param {Object|string} obj
  6153. * @param {*} [obj]
  6154. */
  6155. set: function (obj, value) {
  6156. if (typeof obj === 'string') {
  6157. this[obj] = value;
  6158. }
  6159. else {
  6160. this.extendFrom(obj, true);
  6161. }
  6162. },
  6163. /**
  6164. * Clone
  6165. * @return {zrender/graphic/Style} [description]
  6166. */
  6167. clone: function () {
  6168. var newStyle = new this.constructor();
  6169. newStyle.extendFrom(this, true);
  6170. return newStyle;
  6171. },
  6172. getGradient: function (ctx, obj, rect) {
  6173. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  6174. var canvasGradient = method(ctx, obj, rect);
  6175. var colorStops = obj.colorStops;
  6176. for (var i = 0; i < colorStops.length; i++) {
  6177. canvasGradient.addColorStop(
  6178. colorStops[i].offset, colorStops[i].color
  6179. );
  6180. }
  6181. return canvasGradient;
  6182. }
  6183. };
  6184. var styleProto = Style.prototype;
  6185. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6186. var prop = STYLE_COMMON_PROPS[i];
  6187. if (!(prop[0] in styleProto)) {
  6188. styleProto[prop[0]] = prop[1];
  6189. }
  6190. }
  6191. // Provide for others
  6192. Style.getGradient = styleProto.getGradient;
  6193. var Pattern = function (image, repeat) {
  6194. // Should do nothing more in this constructor. Because gradient can be
  6195. // declard by `color: {image: ...}`, where this constructor will not be called.
  6196. this.image = image;
  6197. this.repeat = repeat;
  6198. // Can be cloned
  6199. this.type = 'pattern';
  6200. };
  6201. Pattern.prototype.getCanvasPattern = function (ctx) {
  6202. return ctx.createPattern(this.image, this.repeat || 'repeat');
  6203. };
  6204. /**
  6205. * @module zrender/Layer
  6206. * @author pissang(https://www.github.com/pissang)
  6207. */
  6208. function returnFalse() {
  6209. return false;
  6210. }
  6211. /**
  6212. * 创建dom
  6213. *
  6214. * @inner
  6215. * @param {string} id dom id 待用
  6216. * @param {Painter} painter painter instance
  6217. * @param {number} number
  6218. */
  6219. function createDom(id, painter, dpr) {
  6220. var newDom = createCanvas();
  6221. var width = painter.getWidth();
  6222. var height = painter.getHeight();
  6223. var newDomStyle = newDom.style;
  6224. if (newDomStyle) { // In node or some other non-browser environment
  6225. newDomStyle.position = 'absolute';
  6226. newDomStyle.left = 0;
  6227. newDomStyle.top = 0;
  6228. newDomStyle.width = width + 'px';
  6229. newDomStyle.height = height + 'px';
  6230. newDom.setAttribute('data-zr-dom-id', id);
  6231. }
  6232. newDom.width = width * dpr;
  6233. newDom.height = height * dpr;
  6234. return newDom;
  6235. }
  6236. /**
  6237. * @alias module:zrender/Layer
  6238. * @constructor
  6239. * @extends module:zrender/mixin/Transformable
  6240. * @param {string} id
  6241. * @param {module:zrender/Painter} painter
  6242. * @param {number} [dpr]
  6243. */
  6244. var Layer = function (id, painter, dpr) {
  6245. var dom;
  6246. dpr = dpr || devicePixelRatio;
  6247. if (typeof id === 'string') {
  6248. dom = createDom(id, painter, dpr);
  6249. }
  6250. // Not using isDom because in node it will return false
  6251. else if (isObject$1(id)) {
  6252. dom = id;
  6253. id = dom.id;
  6254. }
  6255. this.id = id;
  6256. this.dom = dom;
  6257. var domStyle = dom.style;
  6258. if (domStyle) { // Not in node
  6259. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  6260. domStyle['-webkit-user-select'] = 'none';
  6261. domStyle['user-select'] = 'none';
  6262. domStyle['-webkit-touch-callout'] = 'none';
  6263. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  6264. domStyle['padding'] = 0;
  6265. domStyle['margin'] = 0;
  6266. domStyle['border-width'] = 0;
  6267. }
  6268. this.domBack = null;
  6269. this.ctxBack = null;
  6270. this.painter = painter;
  6271. this.config = null;
  6272. // Configs
  6273. /**
  6274. * 每次清空画布的颜色
  6275. * @type {string}
  6276. * @default 0
  6277. */
  6278. this.clearColor = 0;
  6279. /**
  6280. * 是否开启动态模糊
  6281. * @type {boolean}
  6282. * @default false
  6283. */
  6284. this.motionBlur = false;
  6285. /**
  6286. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  6287. * @type {number}
  6288. * @default 0.7
  6289. */
  6290. this.lastFrameAlpha = 0.7;
  6291. /**
  6292. * Layer dpr
  6293. * @type {number}
  6294. */
  6295. this.dpr = dpr;
  6296. };
  6297. Layer.prototype = {
  6298. constructor: Layer,
  6299. __dirty: true,
  6300. __used: false,
  6301. __drawIndex: 0,
  6302. __startIndex: 0,
  6303. __endIndex: 0,
  6304. incremental: false,
  6305. getElementCount: function () {
  6306. return this.__endIndex - this.__startIndex;
  6307. },
  6308. initContext: function () {
  6309. this.ctx = this.dom.getContext('2d');
  6310. this.ctx.dpr = this.dpr;
  6311. },
  6312. createBackBuffer: function () {
  6313. var dpr = this.dpr;
  6314. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  6315. this.ctxBack = this.domBack.getContext('2d');
  6316. if (dpr !== 1) {
  6317. this.ctxBack.scale(dpr, dpr);
  6318. }
  6319. },
  6320. /**
  6321. * @param {number} width
  6322. * @param {number} height
  6323. */
  6324. resize: function (width, height) {
  6325. var dpr = this.dpr;
  6326. var dom = this.dom;
  6327. var domStyle = dom.style;
  6328. var domBack = this.domBack;
  6329. if (domStyle) {
  6330. domStyle.width = width + 'px';
  6331. domStyle.height = height + 'px';
  6332. }
  6333. dom.width = width * dpr;
  6334. dom.height = height * dpr;
  6335. if (domBack) {
  6336. domBack.width = width * dpr;
  6337. domBack.height = height * dpr;
  6338. if (dpr !== 1) {
  6339. this.ctxBack.scale(dpr, dpr);
  6340. }
  6341. }
  6342. },
  6343. /**
  6344. * 清空该层画布
  6345. * @param {boolean} [clearAll]=false Clear all with out motion blur
  6346. * @param {Color} [clearColor]
  6347. */
  6348. clear: function (clearAll, clearColor) {
  6349. var dom = this.dom;
  6350. var ctx = this.ctx;
  6351. var width = dom.width;
  6352. var height = dom.height;
  6353. var clearColor = clearColor || this.clearColor;
  6354. var haveMotionBLur = this.motionBlur && !clearAll;
  6355. var lastFrameAlpha = this.lastFrameAlpha;
  6356. var dpr = this.dpr;
  6357. if (haveMotionBLur) {
  6358. if (!this.domBack) {
  6359. this.createBackBuffer();
  6360. }
  6361. this.ctxBack.globalCompositeOperation = 'copy';
  6362. this.ctxBack.drawImage(
  6363. dom, 0, 0,
  6364. width / dpr,
  6365. height / dpr
  6366. );
  6367. }
  6368. ctx.clearRect(0, 0, width, height);
  6369. if (clearColor && clearColor !== 'transparent') {
  6370. var clearColorGradientOrPattern;
  6371. // Gradient
  6372. if (clearColor.colorStops) {
  6373. // Cache canvas gradient
  6374. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  6375. x: 0,
  6376. y: 0,
  6377. width: width,
  6378. height: height
  6379. });
  6380. clearColor.__canvasGradient = clearColorGradientOrPattern;
  6381. }
  6382. // Pattern
  6383. else if (clearColor.image) {
  6384. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  6385. }
  6386. ctx.save();
  6387. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  6388. ctx.fillRect(0, 0, width, height);
  6389. ctx.restore();
  6390. }
  6391. if (haveMotionBLur) {
  6392. var domBack = this.domBack;
  6393. ctx.save();
  6394. ctx.globalAlpha = lastFrameAlpha;
  6395. ctx.drawImage(domBack, 0, 0, width, height);
  6396. ctx.restore();
  6397. }
  6398. }
  6399. };
  6400. var requestAnimationFrame = (
  6401. typeof window !== 'undefined'
  6402. && (
  6403. (window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  6404. // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809
  6405. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  6406. || window.mozRequestAnimationFrame
  6407. || window.webkitRequestAnimationFrame
  6408. )
  6409. ) || function (func) {
  6410. setTimeout(func, 16);
  6411. };
  6412. var globalImageCache = new LRU(50);
  6413. /**
  6414. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6415. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6416. */
  6417. function findExistImage(newImageOrSrc) {
  6418. if (typeof newImageOrSrc === 'string') {
  6419. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6420. return cachedImgObj && cachedImgObj.image;
  6421. }
  6422. else {
  6423. return newImageOrSrc;
  6424. }
  6425. }
  6426. /**
  6427. * Caution: User should cache loaded images, but not just count on LRU.
  6428. * Consider if required images more than LRU size, will dead loop occur?
  6429. *
  6430. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6431. * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.
  6432. * @param {module:zrender/Element} [hostEl] For calling `dirty`.
  6433. * @param {Function} [cb] params: (image, cbPayload)
  6434. * @param {Object} [cbPayload] Payload on cb calling.
  6435. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6436. */
  6437. function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {
  6438. if (!newImageOrSrc) {
  6439. return image;
  6440. }
  6441. else if (typeof newImageOrSrc === 'string') {
  6442. // Image should not be loaded repeatly.
  6443. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  6444. return image;
  6445. }
  6446. // Only when there is no existent image or existent image src
  6447. // is different, this method is responsible for load.
  6448. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6449. var pendingWrap = {hostEl: hostEl, cb: cb, cbPayload: cbPayload};
  6450. if (cachedImgObj) {
  6451. image = cachedImgObj.image;
  6452. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  6453. }
  6454. else {
  6455. image = new Image();
  6456. image.onload = image.onerror = imageOnLoad;
  6457. globalImageCache.put(
  6458. newImageOrSrc,
  6459. image.__cachedImgObj = {
  6460. image: image,
  6461. pending: [pendingWrap]
  6462. }
  6463. );
  6464. image.src = image.__zrImageSrc = newImageOrSrc;
  6465. }
  6466. return image;
  6467. }
  6468. // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas
  6469. else {
  6470. return newImageOrSrc;
  6471. }
  6472. }
  6473. function imageOnLoad() {
  6474. var cachedImgObj = this.__cachedImgObj;
  6475. this.onload = this.onerror = this.__cachedImgObj = null;
  6476. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  6477. var pendingWrap = cachedImgObj.pending[i];
  6478. var cb = pendingWrap.cb;
  6479. cb && cb(this, pendingWrap.cbPayload);
  6480. pendingWrap.hostEl.dirty();
  6481. }
  6482. cachedImgObj.pending.length = 0;
  6483. }
  6484. function isImageReady(image) {
  6485. return image && image.width && image.height;
  6486. }
  6487. var textWidthCache = {};
  6488. var textWidthCacheCounter = 0;
  6489. var TEXT_CACHE_MAX = 5000;
  6490. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  6491. var DEFAULT_FONT$1 = '12px sans-serif';
  6492. // Avoid assign to an exported variable, for transforming to cjs.
  6493. var methods$1 = {};
  6494. function $override$1(name, fn) {
  6495. methods$1[name] = fn;
  6496. }
  6497. /**
  6498. * @public
  6499. * @param {string} text
  6500. * @param {string} font
  6501. * @return {number} width
  6502. */
  6503. function getWidth(text, font) {
  6504. font = font || DEFAULT_FONT$1;
  6505. var key = text + ':' + font;
  6506. if (textWidthCache[key]) {
  6507. return textWidthCache[key];
  6508. }
  6509. var textLines = (text + '').split('\n');
  6510. var width = 0;
  6511. for (var i = 0, l = textLines.length; i < l; i++) {
  6512. // textContain.measureText may be overrided in SVG or VML
  6513. width = Math.max(measureText(textLines[i], font).width, width);
  6514. }
  6515. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  6516. textWidthCacheCounter = 0;
  6517. textWidthCache = {};
  6518. }
  6519. textWidthCacheCounter++;
  6520. textWidthCache[key] = width;
  6521. return width;
  6522. }
  6523. /**
  6524. * @public
  6525. * @param {string} text
  6526. * @param {string} font
  6527. * @param {string} [textAlign='left']
  6528. * @param {string} [textVerticalAlign='top']
  6529. * @param {Array.<number>} [textPadding]
  6530. * @param {Object} [rich]
  6531. * @param {Object} [truncate]
  6532. * @return {Object} {x, y, width, height, lineHeight}
  6533. */
  6534. function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6535. return rich
  6536. ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate)
  6537. : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate);
  6538. }
  6539. function getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate) {
  6540. var contentBlock = parsePlainText(text, font, textPadding, textLineHeight, truncate);
  6541. var outerWidth = getWidth(text, font);
  6542. if (textPadding) {
  6543. outerWidth += textPadding[1] + textPadding[3];
  6544. }
  6545. var outerHeight = contentBlock.outerHeight;
  6546. var x = adjustTextX(0, outerWidth, textAlign);
  6547. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6548. var rect = new BoundingRect(x, y, outerWidth, outerHeight);
  6549. rect.lineHeight = contentBlock.lineHeight;
  6550. return rect;
  6551. }
  6552. function getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6553. var contentBlock = parseRichText(text, {
  6554. rich: rich,
  6555. truncate: truncate,
  6556. font: font,
  6557. textAlign: textAlign,
  6558. textPadding: textPadding,
  6559. textLineHeight: textLineHeight
  6560. });
  6561. var outerWidth = contentBlock.outerWidth;
  6562. var outerHeight = contentBlock.outerHeight;
  6563. var x = adjustTextX(0, outerWidth, textAlign);
  6564. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6565. return new BoundingRect(x, y, outerWidth, outerHeight);
  6566. }
  6567. /**
  6568. * @public
  6569. * @param {number} x
  6570. * @param {number} width
  6571. * @param {string} [textAlign='left']
  6572. * @return {number} Adjusted x.
  6573. */
  6574. function adjustTextX(x, width, textAlign) {
  6575. // FIXME Right to left language
  6576. if (textAlign === 'right') {
  6577. x -= width;
  6578. }
  6579. else if (textAlign === 'center') {
  6580. x -= width / 2;
  6581. }
  6582. return x;
  6583. }
  6584. /**
  6585. * @public
  6586. * @param {number} y
  6587. * @param {number} height
  6588. * @param {string} [textVerticalAlign='top']
  6589. * @return {number} Adjusted y.
  6590. */
  6591. function adjustTextY(y, height, textVerticalAlign) {
  6592. if (textVerticalAlign === 'middle') {
  6593. y -= height / 2;
  6594. }
  6595. else if (textVerticalAlign === 'bottom') {
  6596. y -= height;
  6597. }
  6598. return y;
  6599. }
  6600. /**
  6601. * @public
  6602. * @param {stirng} textPosition
  6603. * @param {Object} rect {x, y, width, height}
  6604. * @param {number} distance
  6605. * @return {Object} {x, y, textAlign, textVerticalAlign}
  6606. */
  6607. function adjustTextPositionOnRect(textPosition, rect, distance) {
  6608. var x = rect.x;
  6609. var y = rect.y;
  6610. var height = rect.height;
  6611. var width = rect.width;
  6612. var halfHeight = height / 2;
  6613. var textAlign = 'left';
  6614. var textVerticalAlign = 'top';
  6615. switch (textPosition) {
  6616. case 'left':
  6617. x -= distance;
  6618. y += halfHeight;
  6619. textAlign = 'right';
  6620. textVerticalAlign = 'middle';
  6621. break;
  6622. case 'right':
  6623. x += distance + width;
  6624. y += halfHeight;
  6625. textVerticalAlign = 'middle';
  6626. break;
  6627. case 'top':
  6628. x += width / 2;
  6629. y -= distance;
  6630. textAlign = 'center';
  6631. textVerticalAlign = 'bottom';
  6632. break;
  6633. case 'bottom':
  6634. x += width / 2;
  6635. y += height + distance;
  6636. textAlign = 'center';
  6637. break;
  6638. case 'inside':
  6639. x += width / 2;
  6640. y += halfHeight;
  6641. textAlign = 'center';
  6642. textVerticalAlign = 'middle';
  6643. break;
  6644. case 'insideLeft':
  6645. x += distance;
  6646. y += halfHeight;
  6647. textVerticalAlign = 'middle';
  6648. break;
  6649. case 'insideRight':
  6650. x += width - distance;
  6651. y += halfHeight;
  6652. textAlign = 'right';
  6653. textVerticalAlign = 'middle';
  6654. break;
  6655. case 'insideTop':
  6656. x += width / 2;
  6657. y += distance;
  6658. textAlign = 'center';
  6659. break;
  6660. case 'insideBottom':
  6661. x += width / 2;
  6662. y += height - distance;
  6663. textAlign = 'center';
  6664. textVerticalAlign = 'bottom';
  6665. break;
  6666. case 'insideTopLeft':
  6667. x += distance;
  6668. y += distance;
  6669. break;
  6670. case 'insideTopRight':
  6671. x += width - distance;
  6672. y += distance;
  6673. textAlign = 'right';
  6674. break;
  6675. case 'insideBottomLeft':
  6676. x += distance;
  6677. y += height - distance;
  6678. textVerticalAlign = 'bottom';
  6679. break;
  6680. case 'insideBottomRight':
  6681. x += width - distance;
  6682. y += height - distance;
  6683. textAlign = 'right';
  6684. textVerticalAlign = 'bottom';
  6685. break;
  6686. }
  6687. return {
  6688. x: x,
  6689. y: y,
  6690. textAlign: textAlign,
  6691. textVerticalAlign: textVerticalAlign
  6692. };
  6693. }
  6694. /**
  6695. * Show ellipsis if overflow.
  6696. *
  6697. * @public
  6698. * @param {string} text
  6699. * @param {string} containerWidth
  6700. * @param {string} font
  6701. * @param {number} [ellipsis='...']
  6702. * @param {Object} [options]
  6703. * @param {number} [options.maxIterations=3]
  6704. * @param {number} [options.minChar=0] If truncate result are less
  6705. * then minChar, ellipsis will not show, which is
  6706. * better for user hint in some cases.
  6707. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  6708. * @return {string}
  6709. */
  6710. function truncateText(text, containerWidth, font, ellipsis, options) {
  6711. if (!containerWidth) {
  6712. return '';
  6713. }
  6714. var textLines = (text + '').split('\n');
  6715. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  6716. // FIXME
  6717. // It is not appropriate that every line has '...' when truncate multiple lines.
  6718. for (var i = 0, len = textLines.length; i < len; i++) {
  6719. textLines[i] = truncateSingleLine(textLines[i], options);
  6720. }
  6721. return textLines.join('\n');
  6722. }
  6723. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  6724. options = extend({}, options);
  6725. options.font = font;
  6726. var ellipsis = retrieve2(ellipsis, '...');
  6727. options.maxIterations = retrieve2(options.maxIterations, 2);
  6728. var minChar = options.minChar = retrieve2(options.minChar, 0);
  6729. // FIXME
  6730. // Other languages?
  6731. options.cnCharWidth = getWidth('国', font);
  6732. // FIXME
  6733. // Consider proportional font?
  6734. var ascCharWidth = options.ascCharWidth = getWidth('a', font);
  6735. options.placeholder = retrieve2(options.placeholder, '');
  6736. // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  6737. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  6738. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  6739. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  6740. contentWidth -= ascCharWidth;
  6741. }
  6742. var ellipsisWidth = getWidth(ellipsis, font);
  6743. if (ellipsisWidth > contentWidth) {
  6744. ellipsis = '';
  6745. ellipsisWidth = 0;
  6746. }
  6747. contentWidth = containerWidth - ellipsisWidth;
  6748. options.ellipsis = ellipsis;
  6749. options.ellipsisWidth = ellipsisWidth;
  6750. options.contentWidth = contentWidth;
  6751. options.containerWidth = containerWidth;
  6752. return options;
  6753. }
  6754. function truncateSingleLine(textLine, options) {
  6755. var containerWidth = options.containerWidth;
  6756. var font = options.font;
  6757. var contentWidth = options.contentWidth;
  6758. if (!containerWidth) {
  6759. return '';
  6760. }
  6761. var lineWidth = getWidth(textLine, font);
  6762. if (lineWidth <= containerWidth) {
  6763. return textLine;
  6764. }
  6765. for (var j = 0; ; j++) {
  6766. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  6767. textLine += options.ellipsis;
  6768. break;
  6769. }
  6770. var subLength = j === 0
  6771. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  6772. : lineWidth > 0
  6773. ? Math.floor(textLine.length * contentWidth / lineWidth)
  6774. : 0;
  6775. textLine = textLine.substr(0, subLength);
  6776. lineWidth = getWidth(textLine, font);
  6777. }
  6778. if (textLine === '') {
  6779. textLine = options.placeholder;
  6780. }
  6781. return textLine;
  6782. }
  6783. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  6784. var width = 0;
  6785. var i = 0;
  6786. for (var len = text.length; i < len && width < contentWidth; i++) {
  6787. var charCode = text.charCodeAt(i);
  6788. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  6789. }
  6790. return i;
  6791. }
  6792. /**
  6793. * @public
  6794. * @param {string} font
  6795. * @return {number} line height
  6796. */
  6797. function getLineHeight(font) {
  6798. // FIXME A rough approach.
  6799. return getWidth('国', font);
  6800. }
  6801. /**
  6802. * @public
  6803. * @param {string} text
  6804. * @param {string} font
  6805. * @return {Object} width
  6806. */
  6807. function measureText(text, font) {
  6808. return methods$1.measureText(text, font);
  6809. }
  6810. // Avoid assign to an exported variable, for transforming to cjs.
  6811. methods$1.measureText = function (text, font) {
  6812. var ctx = getContext();
  6813. ctx.font = font || DEFAULT_FONT$1;
  6814. return ctx.measureText(text);
  6815. };
  6816. /**
  6817. * @public
  6818. * @param {string} text
  6819. * @param {string} font
  6820. * @param {Object} [truncate]
  6821. * @return {Object} block: {lineHeight, lines, height, outerHeight}
  6822. * Notice: for performance, do not calculate outerWidth util needed.
  6823. */
  6824. function parsePlainText(text, font, padding, textLineHeight, truncate) {
  6825. text != null && (text += '');
  6826. var lineHeight = retrieve2(textLineHeight, getLineHeight(font));
  6827. var lines = text ? text.split('\n') : [];
  6828. var height = lines.length * lineHeight;
  6829. var outerHeight = height;
  6830. if (padding) {
  6831. outerHeight += padding[0] + padding[2];
  6832. }
  6833. if (text && truncate) {
  6834. var truncOuterHeight = truncate.outerHeight;
  6835. var truncOuterWidth = truncate.outerWidth;
  6836. if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
  6837. text = '';
  6838. lines = [];
  6839. }
  6840. else if (truncOuterWidth != null) {
  6841. var options = prepareTruncateOptions(
  6842. truncOuterWidth - (padding ? padding[1] + padding[3] : 0),
  6843. font,
  6844. truncate.ellipsis,
  6845. {minChar: truncate.minChar, placeholder: truncate.placeholder}
  6846. );
  6847. // FIXME
  6848. // It is not appropriate that every line has '...' when truncate multiple lines.
  6849. for (var i = 0, len = lines.length; i < len; i++) {
  6850. lines[i] = truncateSingleLine(lines[i], options);
  6851. }
  6852. }
  6853. }
  6854. return {
  6855. lines: lines,
  6856. height: height,
  6857. outerHeight: outerHeight,
  6858. lineHeight: lineHeight
  6859. };
  6860. }
  6861. /**
  6862. * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'
  6863. * Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
  6864. *
  6865. * @public
  6866. * @param {string} text
  6867. * @param {Object} style
  6868. * @return {Object} block
  6869. * {
  6870. * width,
  6871. * height,
  6872. * lines: [{
  6873. * lineHeight,
  6874. * width,
  6875. * tokens: [[{
  6876. * styleName,
  6877. * text,
  6878. * width, // include textPadding
  6879. * height, // include textPadding
  6880. * textWidth, // pure text width
  6881. * textHeight, // pure text height
  6882. * lineHeihgt,
  6883. * font,
  6884. * textAlign,
  6885. * textVerticalAlign
  6886. * }], [...], ...]
  6887. * }, ...]
  6888. * }
  6889. * If styleName is undefined, it is plain text.
  6890. */
  6891. function parseRichText(text, style) {
  6892. var contentBlock = {lines: [], width: 0, height: 0};
  6893. text != null && (text += '');
  6894. if (!text) {
  6895. return contentBlock;
  6896. }
  6897. var lastIndex = STYLE_REG.lastIndex = 0;
  6898. var result;
  6899. while ((result = STYLE_REG.exec(text)) != null) {
  6900. var matchedIndex = result.index;
  6901. if (matchedIndex > lastIndex) {
  6902. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));
  6903. }
  6904. pushTokens(contentBlock, result[2], result[1]);
  6905. lastIndex = STYLE_REG.lastIndex;
  6906. }
  6907. if (lastIndex < text.length) {
  6908. pushTokens(contentBlock, text.substring(lastIndex, text.length));
  6909. }
  6910. var lines = contentBlock.lines;
  6911. var contentHeight = 0;
  6912. var contentWidth = 0;
  6913. // For `textWidth: 100%`
  6914. var pendingList = [];
  6915. var stlPadding = style.textPadding;
  6916. var truncate = style.truncate;
  6917. var truncateWidth = truncate && truncate.outerWidth;
  6918. var truncateHeight = truncate && truncate.outerHeight;
  6919. if (stlPadding) {
  6920. truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);
  6921. truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);
  6922. }
  6923. // Calculate layout info of tokens.
  6924. for (var i = 0; i < lines.length; i++) {
  6925. var line = lines[i];
  6926. var lineHeight = 0;
  6927. var lineWidth = 0;
  6928. for (var j = 0; j < line.tokens.length; j++) {
  6929. var token = line.tokens[j];
  6930. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  6931. // textPadding should not inherit from style.
  6932. var textPadding = token.textPadding = tokenStyle.textPadding;
  6933. // textFont has been asigned to font by `normalizeStyle`.
  6934. var font = token.font = tokenStyle.font || style.font;
  6935. // textHeight can be used when textVerticalAlign is specified in token.
  6936. var tokenHeight = token.textHeight = retrieve2(
  6937. // textHeight should not be inherited, consider it can be specified
  6938. // as box height of the block.
  6939. tokenStyle.textHeight, getLineHeight(font)
  6940. );
  6941. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  6942. token.height = tokenHeight;
  6943. token.lineHeight = retrieve3(
  6944. tokenStyle.textLineHeight, style.textLineHeight, tokenHeight
  6945. );
  6946. token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;
  6947. token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';
  6948. if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {
  6949. return {lines: [], width: 0, height: 0};
  6950. }
  6951. token.textWidth = getWidth(token.text, font);
  6952. var tokenWidth = tokenStyle.textWidth;
  6953. var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto';
  6954. // Percent width, can be `100%`, can be used in drawing separate
  6955. // line when box width is needed to be auto.
  6956. if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {
  6957. token.percentWidth = tokenWidth;
  6958. pendingList.push(token);
  6959. tokenWidth = 0;
  6960. // Do not truncate in this case, because there is no user case
  6961. // and it is too complicated.
  6962. }
  6963. else {
  6964. if (tokenWidthNotSpecified) {
  6965. tokenWidth = token.textWidth;
  6966. // FIXME: If image is not loaded and textWidth is not specified, calling
  6967. // `getBoundingRect()` will not get correct result.
  6968. var textBackgroundColor = tokenStyle.textBackgroundColor;
  6969. var bgImg = textBackgroundColor && textBackgroundColor.image;
  6970. // Use cases:
  6971. // (1) If image is not loaded, it will be loaded at render phase and call
  6972. // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded
  6973. // image, and then the right size will be calculated here at the next tick.
  6974. // See `graphic/helper/text.js`.
  6975. // (2) If image loaded, and `textBackgroundColor.image` is image src string,
  6976. // use `imageHelper.findExistImage` to find cached image.
  6977. // `imageHelper.findExistImage` will always be called here before
  6978. // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`
  6979. // which ensures that image will not be rendered before correct size calcualted.
  6980. if (bgImg) {
  6981. bgImg = findExistImage(bgImg);
  6982. if (isImageReady(bgImg)) {
  6983. tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);
  6984. }
  6985. }
  6986. }
  6987. var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;
  6988. tokenWidth += paddingW;
  6989. var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;
  6990. if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {
  6991. if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {
  6992. token.text = '';
  6993. token.textWidth = tokenWidth = 0;
  6994. }
  6995. else {
  6996. token.text = truncateText(
  6997. token.text, remianTruncWidth - paddingW, font, truncate.ellipsis,
  6998. {minChar: truncate.minChar}
  6999. );
  7000. token.textWidth = getWidth(token.text, font);
  7001. tokenWidth = token.textWidth + paddingW;
  7002. }
  7003. }
  7004. }
  7005. lineWidth += (token.width = tokenWidth);
  7006. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  7007. }
  7008. line.width = lineWidth;
  7009. line.lineHeight = lineHeight;
  7010. contentHeight += lineHeight;
  7011. contentWidth = Math.max(contentWidth, lineWidth);
  7012. }
  7013. contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);
  7014. contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);
  7015. if (stlPadding) {
  7016. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  7017. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  7018. }
  7019. for (var i = 0; i < pendingList.length; i++) {
  7020. var token = pendingList[i];
  7021. var percentWidth = token.percentWidth;
  7022. // Should not base on outerWidth, because token can not be placed out of padding.
  7023. token.width = parseInt(percentWidth, 10) / 100 * contentWidth;
  7024. }
  7025. return contentBlock;
  7026. }
  7027. function pushTokens(block, str, styleName) {
  7028. var isEmptyStr = str === '';
  7029. var strs = str.split('\n');
  7030. var lines = block.lines;
  7031. for (var i = 0; i < strs.length; i++) {
  7032. var text = strs[i];
  7033. var token = {
  7034. styleName: styleName,
  7035. text: text,
  7036. isLineHolder: !text && !isEmptyStr
  7037. };
  7038. // The first token should be appended to the last line.
  7039. if (!i) {
  7040. var tokens = (lines[lines.length - 1] || (lines[0] = {tokens: []})).tokens;
  7041. // Consider cases:
  7042. // (1) ''.split('\n') => ['', '\n', ''], the '' at the first item
  7043. // (which is a placeholder) should be replaced by new token.
  7044. // (2) A image backage, where token likes {a|}.
  7045. // (3) A redundant '' will affect textAlign in line.
  7046. // (4) tokens with the same tplName should not be merged, because
  7047. // they should be displayed in different box (with border and padding).
  7048. var tokensLen = tokens.length;
  7049. (tokensLen === 1 && tokens[0].isLineHolder)
  7050. ? (tokens[0] = token)
  7051. // Consider text is '', only insert when it is the "lineHolder" or
  7052. // "emptyStr". Otherwise a redundant '' will affect textAlign in line.
  7053. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  7054. }
  7055. // Other tokens always start a new line.
  7056. else {
  7057. // If there is '', insert it as a placeholder.
  7058. lines.push({tokens: [token]});
  7059. }
  7060. }
  7061. }
  7062. function makeFont(style) {
  7063. // FIXME in node-canvas fontWeight is before fontStyle
  7064. // Use `fontSize` `fontFamily` to check whether font properties are defined.
  7065. var font = (style.fontSize || style.fontFamily) && [
  7066. style.fontStyle,
  7067. style.fontWeight,
  7068. (style.fontSize || 12) + 'px',
  7069. // If font properties are defined, `fontFamily` should not be ignored.
  7070. style.fontFamily || 'sans-serif'
  7071. ].join(' ');
  7072. return font && trim(font) || style.textFont || style.font;
  7073. }
  7074. /**
  7075. * @param {Object} ctx
  7076. * @param {Object} shape
  7077. * @param {number} shape.x
  7078. * @param {number} shape.y
  7079. * @param {number} shape.width
  7080. * @param {number} shape.height
  7081. * @param {number} shape.r
  7082. */
  7083. function buildPath(ctx, shape) {
  7084. var x = shape.x;
  7085. var y = shape.y;
  7086. var width = shape.width;
  7087. var height = shape.height;
  7088. var r = shape.r;
  7089. var r1;
  7090. var r2;
  7091. var r3;
  7092. var r4;
  7093. // Convert width and height to positive for better borderRadius
  7094. if (width < 0) {
  7095. x = x + width;
  7096. width = -width;
  7097. }
  7098. if (height < 0) {
  7099. y = y + height;
  7100. height = -height;
  7101. }
  7102. if (typeof r === 'number') {
  7103. r1 = r2 = r3 = r4 = r;
  7104. }
  7105. else if (r instanceof Array) {
  7106. if (r.length === 1) {
  7107. r1 = r2 = r3 = r4 = r[0];
  7108. }
  7109. else if (r.length === 2) {
  7110. r1 = r3 = r[0];
  7111. r2 = r4 = r[1];
  7112. }
  7113. else if (r.length === 3) {
  7114. r1 = r[0];
  7115. r2 = r4 = r[1];
  7116. r3 = r[2];
  7117. }
  7118. else {
  7119. r1 = r[0];
  7120. r2 = r[1];
  7121. r3 = r[2];
  7122. r4 = r[3];
  7123. }
  7124. }
  7125. else {
  7126. r1 = r2 = r3 = r4 = 0;
  7127. }
  7128. var total;
  7129. if (r1 + r2 > width) {
  7130. total = r1 + r2;
  7131. r1 *= width / total;
  7132. r2 *= width / total;
  7133. }
  7134. if (r3 + r4 > width) {
  7135. total = r3 + r4;
  7136. r3 *= width / total;
  7137. r4 *= width / total;
  7138. }
  7139. if (r2 + r3 > height) {
  7140. total = r2 + r3;
  7141. r2 *= height / total;
  7142. r3 *= height / total;
  7143. }
  7144. if (r1 + r4 > height) {
  7145. total = r1 + r4;
  7146. r1 *= height / total;
  7147. r4 *= height / total;
  7148. }
  7149. ctx.moveTo(x + r1, y);
  7150. ctx.lineTo(x + width - r2, y);
  7151. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  7152. ctx.lineTo(x + width, y + height - r3);
  7153. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  7154. ctx.lineTo(x + r4, y + height);
  7155. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  7156. ctx.lineTo(x, y + r1);
  7157. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  7158. }
  7159. var DEFAULT_FONT = DEFAULT_FONT$1;
  7160. // TODO: Have not support 'start', 'end' yet.
  7161. var VALID_TEXT_ALIGN = {left: 1, right: 1, center: 1};
  7162. var VALID_TEXT_VERTICAL_ALIGN = {top: 1, bottom: 1, middle: 1};
  7163. // Different from `STYLE_COMMON_PROPS` of `graphic/Style`,
  7164. // the default value of shadowColor is `'transparent'`.
  7165. var SHADOW_STYLE_COMMON_PROPS = [
  7166. ['textShadowBlur', 'shadowBlur', 0],
  7167. ['textShadowOffsetX', 'shadowOffsetX', 0],
  7168. ['textShadowOffsetY', 'shadowOffsetY', 0],
  7169. ['textShadowColor', 'shadowColor', 'transparent']
  7170. ];
  7171. /**
  7172. * @param {module:zrender/graphic/Style} style
  7173. * @return {module:zrender/graphic/Style} The input style.
  7174. */
  7175. function normalizeTextStyle(style) {
  7176. normalizeStyle(style);
  7177. each$1(style.rich, normalizeStyle);
  7178. return style;
  7179. }
  7180. function normalizeStyle(style) {
  7181. if (style) {
  7182. style.font = makeFont(style);
  7183. var textAlign = style.textAlign;
  7184. textAlign === 'middle' && (textAlign = 'center');
  7185. style.textAlign = (
  7186. textAlign == null || VALID_TEXT_ALIGN[textAlign]
  7187. ) ? textAlign : 'left';
  7188. // Compatible with textBaseline.
  7189. var textVerticalAlign = style.textVerticalAlign || style.textBaseline;
  7190. textVerticalAlign === 'center' && (textVerticalAlign = 'middle');
  7191. style.textVerticalAlign = (
  7192. textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign]
  7193. ) ? textVerticalAlign : 'top';
  7194. var textPadding = style.textPadding;
  7195. if (textPadding) {
  7196. style.textPadding = normalizeCssArray(style.textPadding);
  7197. }
  7198. }
  7199. }
  7200. /**
  7201. * @param {CanvasRenderingContext2D} ctx
  7202. * @param {string} text
  7203. * @param {module:zrender/graphic/Style} style
  7204. * @param {Object|boolean} [rect] {x, y, width, height}
  7205. * If set false, rect text is not used.
  7206. * @param {Element|module:zrender/graphic/helper/constant.WILL_BE_RESTORED} [prevEl] For ctx prop cache.
  7207. */
  7208. function renderText(hostEl, ctx, text, style, rect, prevEl) {
  7209. style.rich
  7210. ? renderRichText(hostEl, ctx, text, style, rect, prevEl)
  7211. : renderPlainText(hostEl, ctx, text, style, rect, prevEl);
  7212. }
  7213. // Avoid setting to ctx according to prevEl if possible for
  7214. // performance in scenarios of large amount text.
  7215. function renderPlainText(hostEl, ctx, text, style, rect, prevEl) {
  7216. 'use strict';
  7217. var needDrawBg = needDrawBackground(style);
  7218. var prevStyle;
  7219. var checkCache = false;
  7220. var cachedByMe = ctx.__attrCachedBy === ContextCachedBy.PLAIN_TEXT;
  7221. // Only take and check cache for `Text` el, but not RectText.
  7222. if (prevEl !== WILL_BE_RESTORED) {
  7223. if (prevEl) {
  7224. prevStyle = prevEl.style;
  7225. checkCache = !needDrawBg && cachedByMe && prevStyle;
  7226. }
  7227. // Prevent from using cache in `Style::bind`, because of the case:
  7228. // ctx property is modified by other properties than `Style::bind`
  7229. // used, and Style::bind is called next.
  7230. ctx.__attrCachedBy = needDrawBg ? ContextCachedBy.NONE : ContextCachedBy.PLAIN_TEXT;
  7231. }
  7232. // Since this will be restored, prevent from using these props to check cache in the next
  7233. // entering of this method. But do not need to clear other cache like `Style::bind`.
  7234. else if (cachedByMe) {
  7235. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7236. }
  7237. var styleFont = style.font || DEFAULT_FONT;
  7238. // PENDING
  7239. // Only `Text` el set `font` and keep it (`RectText` will restore). So theoretically
  7240. // we can make font cache on ctx, which can cache for text el that are discontinuous.
  7241. // But layer save/restore needed to be considered.
  7242. // if (styleFont !== ctx.__fontCache) {
  7243. // ctx.font = styleFont;
  7244. // if (prevEl !== WILL_BE_RESTORED) {
  7245. // ctx.__fontCache = styleFont;
  7246. // }
  7247. // }
  7248. if (!checkCache || styleFont !== (prevStyle.font || DEFAULT_FONT)) {
  7249. ctx.font = styleFont;
  7250. }
  7251. // Use the final font from context-2d, because the final
  7252. // font might not be the style.font when it is illegal.
  7253. // But get `ctx.font` might be time consuming.
  7254. var computedFont = hostEl.__computedFont;
  7255. if (hostEl.__styleFont !== styleFont) {
  7256. hostEl.__styleFont = styleFont;
  7257. computedFont = hostEl.__computedFont = ctx.font;
  7258. }
  7259. var textPadding = style.textPadding;
  7260. var textLineHeight = style.textLineHeight;
  7261. var contentBlock = hostEl.__textCotentBlock;
  7262. if (!contentBlock || hostEl.__dirtyText) {
  7263. contentBlock = hostEl.__textCotentBlock = parsePlainText(
  7264. text, computedFont, textPadding, textLineHeight, style.truncate
  7265. );
  7266. }
  7267. var outerHeight = contentBlock.outerHeight;
  7268. var textLines = contentBlock.lines;
  7269. var lineHeight = contentBlock.lineHeight;
  7270. var boxPos = getBoxPosition(outerHeight, style, rect);
  7271. var baseX = boxPos.baseX;
  7272. var baseY = boxPos.baseY;
  7273. var textAlign = boxPos.textAlign || 'left';
  7274. var textVerticalAlign = boxPos.textVerticalAlign;
  7275. // Origin of textRotation should be the base point of text drawing.
  7276. applyTextRotation(ctx, style, rect, baseX, baseY);
  7277. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7278. var textX = baseX;
  7279. var textY = boxY;
  7280. if (needDrawBg || textPadding) {
  7281. // Consider performance, do not call getTextWidth util necessary.
  7282. var textWidth = getWidth(text, computedFont);
  7283. var outerWidth = textWidth;
  7284. textPadding && (outerWidth += textPadding[1] + textPadding[3]);
  7285. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7286. needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  7287. if (textPadding) {
  7288. textX = getTextXForPadding(baseX, textAlign, textPadding);
  7289. textY += textPadding[0];
  7290. }
  7291. }
  7292. // Always set textAlign and textBase line, because it is difficute to calculate
  7293. // textAlign from prevEl, and we dont sure whether textAlign will be reset if
  7294. // font set happened.
  7295. ctx.textAlign = textAlign;
  7296. // Force baseline to be "middle". Otherwise, if using "top", the
  7297. // text will offset downward a little bit in font "Microsoft YaHei".
  7298. ctx.textBaseline = 'middle';
  7299. // Set text opacity
  7300. ctx.globalAlpha = style.opacity || 1;
  7301. // Always set shadowBlur and shadowOffset to avoid leak from displayable.
  7302. for (var i = 0; i < SHADOW_STYLE_COMMON_PROPS.length; i++) {
  7303. var propItem = SHADOW_STYLE_COMMON_PROPS[i];
  7304. var styleProp = propItem[0];
  7305. var ctxProp = propItem[1];
  7306. var val = style[styleProp];
  7307. if (!checkCache || val !== prevStyle[styleProp]) {
  7308. ctx[ctxProp] = fixShadow(ctx, ctxProp, val || propItem[2]);
  7309. }
  7310. }
  7311. // `textBaseline` is set as 'middle'.
  7312. textY += lineHeight / 2;
  7313. var textStrokeWidth = style.textStrokeWidth;
  7314. var textStrokeWidthPrev = checkCache ? prevStyle.textStrokeWidth : null;
  7315. var strokeWidthChanged = !checkCache || textStrokeWidth !== textStrokeWidthPrev;
  7316. var strokeChanged = !checkCache || strokeWidthChanged || style.textStroke !== prevStyle.textStroke;
  7317. var textStroke = getStroke(style.textStroke, textStrokeWidth);
  7318. var textFill = getFill(style.textFill);
  7319. if (textStroke) {
  7320. if (strokeWidthChanged) {
  7321. ctx.lineWidth = textStrokeWidth;
  7322. }
  7323. if (strokeChanged) {
  7324. ctx.strokeStyle = textStroke;
  7325. }
  7326. }
  7327. if (textFill) {
  7328. if (!checkCache || style.textFill !== prevStyle.textFill) {
  7329. ctx.fillStyle = textFill;
  7330. }
  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. }
  7338. else {
  7339. for (var i = 0; i < textLines.length; i++) {
  7340. // Fill after stroke so the outline will not cover the main part.
  7341. textStroke && ctx.strokeText(textLines[i], textX, textY);
  7342. textFill && ctx.fillText(textLines[i], textX, textY);
  7343. textY += lineHeight;
  7344. }
  7345. }
  7346. }
  7347. function renderRichText(hostEl, ctx, text, style, rect, prevEl) {
  7348. // Do not do cache for rich text because of the complexity.
  7349. // But `RectText` this will be restored, do not need to clear other cache like `Style::bind`.
  7350. if (prevEl !== WILL_BE_RESTORED) {
  7351. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7352. }
  7353. var contentBlock = hostEl.__textCotentBlock;
  7354. if (!contentBlock || hostEl.__dirtyText) {
  7355. contentBlock = hostEl.__textCotentBlock = parseRichText(text, style);
  7356. }
  7357. drawRichText(hostEl, ctx, contentBlock, style, rect);
  7358. }
  7359. function drawRichText(hostEl, ctx, contentBlock, style, rect) {
  7360. var contentWidth = contentBlock.width;
  7361. var outerWidth = contentBlock.outerWidth;
  7362. var outerHeight = contentBlock.outerHeight;
  7363. var textPadding = style.textPadding;
  7364. var boxPos = getBoxPosition(outerHeight, style, rect);
  7365. var baseX = boxPos.baseX;
  7366. var baseY = boxPos.baseY;
  7367. var textAlign = boxPos.textAlign;
  7368. var textVerticalAlign = boxPos.textVerticalAlign;
  7369. // Origin of textRotation should be the base point of text drawing.
  7370. applyTextRotation(ctx, style, rect, baseX, baseY);
  7371. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7372. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7373. var xLeft = boxX;
  7374. var lineTop = boxY;
  7375. if (textPadding) {
  7376. xLeft += textPadding[3];
  7377. lineTop += textPadding[0];
  7378. }
  7379. var xRight = xLeft + contentWidth;
  7380. needDrawBackground(style) && drawBackground(
  7381. hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight
  7382. );
  7383. for (var i = 0; i < contentBlock.lines.length; i++) {
  7384. var line = contentBlock.lines[i];
  7385. var tokens = line.tokens;
  7386. var tokenCount = tokens.length;
  7387. var lineHeight = line.lineHeight;
  7388. var usedWidth = line.width;
  7389. var leftIndex = 0;
  7390. var lineXLeft = xLeft;
  7391. var lineXRight = xRight;
  7392. var rightIndex = tokenCount - 1;
  7393. var token;
  7394. while (
  7395. leftIndex < tokenCount
  7396. && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')
  7397. ) {
  7398. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
  7399. usedWidth -= token.width;
  7400. lineXLeft += token.width;
  7401. leftIndex++;
  7402. }
  7403. while (
  7404. rightIndex >= 0
  7405. && (token = tokens[rightIndex], token.textAlign === 'right')
  7406. ) {
  7407. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
  7408. usedWidth -= token.width;
  7409. lineXRight -= token.width;
  7410. rightIndex--;
  7411. }
  7412. // The other tokens are placed as textAlign 'center' if there is enough space.
  7413. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;
  7414. while (leftIndex <= rightIndex) {
  7415. token = tokens[leftIndex];
  7416. // Consider width specified by user, use 'center' rather than 'left'.
  7417. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');
  7418. lineXLeft += token.width;
  7419. leftIndex++;
  7420. }
  7421. lineTop += lineHeight;
  7422. }
  7423. }
  7424. function applyTextRotation(ctx, style, rect, x, y) {
  7425. // textRotation only apply in RectText.
  7426. if (rect && style.textRotation) {
  7427. var origin = style.textOrigin;
  7428. if (origin === 'center') {
  7429. x = rect.width / 2 + rect.x;
  7430. y = rect.height / 2 + rect.y;
  7431. }
  7432. else if (origin) {
  7433. x = origin[0] + rect.x;
  7434. y = origin[1] + rect.y;
  7435. }
  7436. ctx.translate(x, y);
  7437. // Positive: anticlockwise
  7438. ctx.rotate(-style.textRotation);
  7439. ctx.translate(-x, -y);
  7440. }
  7441. }
  7442. function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
  7443. var tokenStyle = style.rich[token.styleName] || {};
  7444. tokenStyle.text = token.text;
  7445. // 'ctx.textBaseline' is always set as 'middle', for sake of
  7446. // the bias of "Microsoft YaHei".
  7447. var textVerticalAlign = token.textVerticalAlign;
  7448. var y = lineTop + lineHeight / 2;
  7449. if (textVerticalAlign === 'top') {
  7450. y = lineTop + token.height / 2;
  7451. }
  7452. else if (textVerticalAlign === 'bottom') {
  7453. y = lineTop + lineHeight - token.height / 2;
  7454. }
  7455. !token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(
  7456. hostEl,
  7457. ctx,
  7458. tokenStyle,
  7459. textAlign === 'right'
  7460. ? x - token.width
  7461. : textAlign === 'center'
  7462. ? x - token.width / 2
  7463. : x,
  7464. y - token.height / 2,
  7465. token.width,
  7466. token.height
  7467. );
  7468. var textPadding = token.textPadding;
  7469. if (textPadding) {
  7470. x = getTextXForPadding(x, textAlign, textPadding);
  7471. y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
  7472. }
  7473. setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
  7474. setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
  7475. setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
  7476. setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
  7477. setCtx(ctx, 'textAlign', textAlign);
  7478. // Force baseline to be "middle". Otherwise, if using "top", the
  7479. // text will offset downward a little bit in font "Microsoft YaHei".
  7480. setCtx(ctx, 'textBaseline', 'middle');
  7481. setCtx(ctx, 'font', token.font || DEFAULT_FONT);
  7482. var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
  7483. var textFill = getFill(tokenStyle.textFill || style.textFill);
  7484. var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth);
  7485. // Fill after stroke so the outline will not cover the main part.
  7486. if (textStroke) {
  7487. setCtx(ctx, 'lineWidth', textStrokeWidth);
  7488. setCtx(ctx, 'strokeStyle', textStroke);
  7489. ctx.strokeText(token.text, x, y);
  7490. }
  7491. if (textFill) {
  7492. setCtx(ctx, 'fillStyle', textFill);
  7493. ctx.fillText(token.text, x, y);
  7494. }
  7495. }
  7496. function needDrawBackground(style) {
  7497. return !!(
  7498. style.textBackgroundColor
  7499. || (style.textBorderWidth && style.textBorderColor)
  7500. );
  7501. }
  7502. // style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius, text}
  7503. // shape: {x, y, width, height}
  7504. function drawBackground(hostEl, ctx, style, x, y, width, height) {
  7505. var textBackgroundColor = style.textBackgroundColor;
  7506. var textBorderWidth = style.textBorderWidth;
  7507. var textBorderColor = style.textBorderColor;
  7508. var isPlainBg = isString(textBackgroundColor);
  7509. setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);
  7510. setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');
  7511. setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);
  7512. setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);
  7513. if (isPlainBg || (textBorderWidth && textBorderColor)) {
  7514. ctx.beginPath();
  7515. var textBorderRadius = style.textBorderRadius;
  7516. if (!textBorderRadius) {
  7517. ctx.rect(x, y, width, height);
  7518. }
  7519. else {
  7520. buildPath(ctx, {
  7521. x: x, y: y, width: width, height: height, r: textBorderRadius
  7522. });
  7523. }
  7524. ctx.closePath();
  7525. }
  7526. if (isPlainBg) {
  7527. setCtx(ctx, 'fillStyle', textBackgroundColor);
  7528. if (style.fillOpacity != null) {
  7529. var originalGlobalAlpha = ctx.globalAlpha;
  7530. ctx.globalAlpha = style.fillOpacity * style.opacity;
  7531. ctx.fill();
  7532. ctx.globalAlpha = originalGlobalAlpha;
  7533. }
  7534. else {
  7535. ctx.fill();
  7536. }
  7537. }
  7538. else if (isObject$1(textBackgroundColor)) {
  7539. var image = textBackgroundColor.image;
  7540. image = createOrUpdateImage(
  7541. image, null, hostEl, onBgImageLoaded, textBackgroundColor
  7542. );
  7543. if (image && isImageReady(image)) {
  7544. ctx.drawImage(image, x, y, width, height);
  7545. }
  7546. }
  7547. if (textBorderWidth && textBorderColor) {
  7548. setCtx(ctx, 'lineWidth', textBorderWidth);
  7549. setCtx(ctx, 'strokeStyle', textBorderColor);
  7550. if (style.strokeOpacity != null) {
  7551. var originalGlobalAlpha = ctx.globalAlpha;
  7552. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  7553. ctx.stroke();
  7554. ctx.globalAlpha = originalGlobalAlpha;
  7555. }
  7556. else {
  7557. ctx.stroke();
  7558. }
  7559. }
  7560. }
  7561. function onBgImageLoaded(image, textBackgroundColor) {
  7562. // Replace image, so that `contain/text.js#parseRichText`
  7563. // will get correct result in next tick.
  7564. textBackgroundColor.image = image;
  7565. }
  7566. function getBoxPosition(blockHeiht, style, rect) {
  7567. var baseX = style.x || 0;
  7568. var baseY = style.y || 0;
  7569. var textAlign = style.textAlign;
  7570. var textVerticalAlign = style.textVerticalAlign;
  7571. // Text position represented by coord
  7572. if (rect) {
  7573. var textPosition = style.textPosition;
  7574. if (textPosition instanceof Array) {
  7575. // Percent
  7576. baseX = rect.x + parsePercent(textPosition[0], rect.width);
  7577. baseY = rect.y + parsePercent(textPosition[1], rect.height);
  7578. }
  7579. else {
  7580. var res = adjustTextPositionOnRect(
  7581. textPosition, rect, style.textDistance
  7582. );
  7583. baseX = res.x;
  7584. baseY = res.y;
  7585. // Default align and baseline when has textPosition
  7586. textAlign = textAlign || res.textAlign;
  7587. textVerticalAlign = textVerticalAlign || res.textVerticalAlign;
  7588. }
  7589. // textOffset is only support in RectText, otherwise
  7590. // we have to adjust boundingRect for textOffset.
  7591. var textOffset = style.textOffset;
  7592. if (textOffset) {
  7593. baseX += textOffset[0];
  7594. baseY += textOffset[1];
  7595. }
  7596. }
  7597. return {
  7598. baseX: baseX,
  7599. baseY: baseY,
  7600. textAlign: textAlign,
  7601. textVerticalAlign: textVerticalAlign
  7602. };
  7603. }
  7604. function setCtx(ctx, prop, value) {
  7605. ctx[prop] = fixShadow(ctx, prop, value);
  7606. return ctx[prop];
  7607. }
  7608. /**
  7609. * @param {string} [stroke] If specified, do not check style.textStroke.
  7610. * @param {string} [lineWidth] If specified, do not check style.textStroke.
  7611. * @param {number} style
  7612. */
  7613. function getStroke(stroke, lineWidth) {
  7614. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  7615. ? null
  7616. // TODO pattern and gradient?
  7617. : (stroke.image || stroke.colorStops)
  7618. ? '#000'
  7619. : stroke;
  7620. }
  7621. function getFill(fill) {
  7622. return (fill == null || fill === 'none')
  7623. ? null
  7624. // TODO pattern and gradient?
  7625. : (fill.image || fill.colorStops)
  7626. ? '#000'
  7627. : fill;
  7628. }
  7629. function parsePercent(value, maxValue) {
  7630. if (typeof value === 'string') {
  7631. if (value.lastIndexOf('%') >= 0) {
  7632. return parseFloat(value) / 100 * maxValue;
  7633. }
  7634. return parseFloat(value);
  7635. }
  7636. return value;
  7637. }
  7638. function getTextXForPadding(x, textAlign, textPadding) {
  7639. return textAlign === 'right'
  7640. ? (x - textPadding[1])
  7641. : textAlign === 'center'
  7642. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  7643. : (x + textPadding[3]);
  7644. }
  7645. /**
  7646. * @param {string} text
  7647. * @param {module:zrender/Style} style
  7648. * @return {boolean}
  7649. */
  7650. function needDrawText(text, style) {
  7651. return text != null
  7652. && (text
  7653. || style.textBackgroundColor
  7654. || (style.textBorderWidth && style.textBorderColor)
  7655. || style.textPadding
  7656. );
  7657. }
  7658. /**
  7659. * Mixin for drawing text in a element bounding rect
  7660. * @module zrender/mixin/RectText
  7661. */
  7662. var tmpRect$1 = new BoundingRect();
  7663. var RectText = function () {};
  7664. RectText.prototype = {
  7665. constructor: RectText,
  7666. /**
  7667. * Draw text in a rect with specified position.
  7668. * @param {CanvasRenderingContext2D} ctx
  7669. * @param {Object} rect Displayable rect
  7670. */
  7671. drawRectText: function (ctx, rect) {
  7672. var style = this.style;
  7673. rect = style.textRect || rect;
  7674. // Optimize, avoid normalize every time.
  7675. this.__dirty && normalizeTextStyle(style, true);
  7676. var text = style.text;
  7677. // Convert to string
  7678. text != null && (text += '');
  7679. if (!needDrawText(text, style)) {
  7680. return;
  7681. }
  7682. // FIXME
  7683. // Do not provide prevEl to `textHelper.renderText` for ctx prop cache,
  7684. // but use `ctx.save()` and `ctx.restore()`. Because the cache for rect
  7685. // text propably break the cache for its host elements.
  7686. ctx.save();
  7687. // Transform rect to view space
  7688. var transform = this.transform;
  7689. if (!style.transformText) {
  7690. if (transform) {
  7691. tmpRect$1.copy(rect);
  7692. tmpRect$1.applyTransform(transform);
  7693. rect = tmpRect$1;
  7694. }
  7695. }
  7696. else {
  7697. this.setTransform(ctx);
  7698. }
  7699. // transformText and textRotation can not be used at the same time.
  7700. renderText(this, ctx, text, style, rect, WILL_BE_RESTORED);
  7701. ctx.restore();
  7702. }
  7703. };
  7704. /**
  7705. * 可绘制的图形基类
  7706. * Base class of all displayable graphic objects
  7707. * @module zrender/graphic/Displayable
  7708. */
  7709. /**
  7710. * @alias module:zrender/graphic/Displayable
  7711. * @extends module:zrender/Element
  7712. * @extends module:zrender/graphic/mixin/RectText
  7713. */
  7714. function Displayable(opts) {
  7715. opts = opts || {};
  7716. Element.call(this, opts);
  7717. // Extend properties
  7718. for (var name in opts) {
  7719. if (
  7720. opts.hasOwnProperty(name)
  7721. && name !== 'style'
  7722. ) {
  7723. this[name] = opts[name];
  7724. }
  7725. }
  7726. /**
  7727. * @type {module:zrender/graphic/Style}
  7728. */
  7729. this.style = new Style(opts.style, this);
  7730. this._rect = null;
  7731. // Shapes for cascade clipping.
  7732. this.__clipPaths = [];
  7733. // FIXME Stateful must be mixined after style is setted
  7734. // Stateful.call(this, opts);
  7735. }
  7736. Displayable.prototype = {
  7737. constructor: Displayable,
  7738. type: 'displayable',
  7739. /**
  7740. * Displayable 是否为脏,Painter 中会根据该标记判断是否需要是否需要重新绘制
  7741. * Dirty flag. From which painter will determine if this displayable object needs brush
  7742. * @name module:zrender/graphic/Displayable#__dirty
  7743. * @type {boolean}
  7744. */
  7745. __dirty: true,
  7746. /**
  7747. * 图形是否可见,为true时不绘制图形,但是仍能触发鼠标事件
  7748. * If ignore drawing of the displayable object. Mouse event will still be triggered
  7749. * @name module:/zrender/graphic/Displayable#invisible
  7750. * @type {boolean}
  7751. * @default false
  7752. */
  7753. invisible: false,
  7754. /**
  7755. * @name module:/zrender/graphic/Displayable#z
  7756. * @type {number}
  7757. * @default 0
  7758. */
  7759. z: 0,
  7760. /**
  7761. * @name module:/zrender/graphic/Displayable#z
  7762. * @type {number}
  7763. * @default 0
  7764. */
  7765. z2: 0,
  7766. /**
  7767. * z层level,决定绘画在哪层canvas中
  7768. * @name module:/zrender/graphic/Displayable#zlevel
  7769. * @type {number}
  7770. * @default 0
  7771. */
  7772. zlevel: 0,
  7773. /**
  7774. * 是否可拖拽
  7775. * @name module:/zrender/graphic/Displayable#draggable
  7776. * @type {boolean}
  7777. * @default false
  7778. */
  7779. draggable: false,
  7780. /**
  7781. * 是否正在拖拽
  7782. * @name module:/zrender/graphic/Displayable#draggable
  7783. * @type {boolean}
  7784. * @default false
  7785. */
  7786. dragging: false,
  7787. /**
  7788. * 是否相应鼠标事件
  7789. * @name module:/zrender/graphic/Displayable#silent
  7790. * @type {boolean}
  7791. * @default false
  7792. */
  7793. silent: false,
  7794. /**
  7795. * If enable culling
  7796. * @type {boolean}
  7797. * @default false
  7798. */
  7799. culling: false,
  7800. /**
  7801. * Mouse cursor when hovered
  7802. * @name module:/zrender/graphic/Displayable#cursor
  7803. * @type {string}
  7804. */
  7805. cursor: 'pointer',
  7806. /**
  7807. * If hover area is bounding rect
  7808. * @name module:/zrender/graphic/Displayable#rectHover
  7809. * @type {string}
  7810. */
  7811. rectHover: false,
  7812. /**
  7813. * Render the element progressively when the value >= 0,
  7814. * usefull for large data.
  7815. * @type {boolean}
  7816. */
  7817. progressive: false,
  7818. /**
  7819. * @type {boolean}
  7820. */
  7821. incremental: false,
  7822. /**
  7823. * Scale ratio for global scale.
  7824. * @type {boolean}
  7825. */
  7826. globalScaleRatio: 1,
  7827. beforeBrush: function (ctx) {},
  7828. afterBrush: function (ctx) {},
  7829. /**
  7830. * 图形绘制方法
  7831. * @param {CanvasRenderingContext2D} ctx
  7832. */
  7833. // Interface
  7834. brush: function (ctx, prevEl) {},
  7835. /**
  7836. * 获取最小包围盒
  7837. * @return {module:zrender/core/BoundingRect}
  7838. */
  7839. // Interface
  7840. getBoundingRect: function () {},
  7841. /**
  7842. * 判断坐标 x, y 是否在图形上
  7843. * If displayable element contain coord x, y
  7844. * @param {number} x
  7845. * @param {number} y
  7846. * @return {boolean}
  7847. */
  7848. contain: function (x, y) {
  7849. return this.rectContain(x, y);
  7850. },
  7851. /**
  7852. * @param {Function} cb
  7853. * @param {} context
  7854. */
  7855. traverse: function (cb, context) {
  7856. cb.call(context, this);
  7857. },
  7858. /**
  7859. * 判断坐标 x, y 是否在图形的包围盒上
  7860. * If bounding rect of element contain coord x, y
  7861. * @param {number} x
  7862. * @param {number} y
  7863. * @return {boolean}
  7864. */
  7865. rectContain: function (x, y) {
  7866. var coord = this.transformCoordToLocal(x, y);
  7867. var rect = this.getBoundingRect();
  7868. return rect.contain(coord[0], coord[1]);
  7869. },
  7870. /**
  7871. * 标记图形元素为脏,并且在下一帧重绘
  7872. * Mark displayable element dirty and refresh next frame
  7873. */
  7874. dirty: function () {
  7875. this.__dirty = this.__dirtyText = true;
  7876. this._rect = null;
  7877. this.__zr && this.__zr.refresh();
  7878. },
  7879. /**
  7880. * 图形是否会触发事件
  7881. * If displayable object binded any event
  7882. * @return {boolean}
  7883. */
  7884. // TODO, 通过 bind 绑定的事件
  7885. // isSilent: function () {
  7886. // return !(
  7887. // this.hoverable || this.draggable
  7888. // || this.onmousemove || this.onmouseover || this.onmouseout
  7889. // || this.onmousedown || this.onmouseup || this.onclick
  7890. // || this.ondragenter || this.ondragover || this.ondragleave
  7891. // || this.ondrop
  7892. // );
  7893. // },
  7894. /**
  7895. * Alias for animate('style')
  7896. * @param {boolean} loop
  7897. */
  7898. animateStyle: function (loop) {
  7899. return this.animate('style', loop);
  7900. },
  7901. attrKV: function (key, value) {
  7902. if (key !== 'style') {
  7903. Element.prototype.attrKV.call(this, key, value);
  7904. }
  7905. else {
  7906. this.style.set(value);
  7907. }
  7908. },
  7909. /**
  7910. * @param {Object|string} key
  7911. * @param {*} value
  7912. */
  7913. setStyle: function (key, value) {
  7914. this.style.set(key, value);
  7915. this.dirty(false);
  7916. return this;
  7917. },
  7918. /**
  7919. * Use given style object
  7920. * @param {Object} obj
  7921. */
  7922. useStyle: function (obj) {
  7923. this.style = new Style(obj, this);
  7924. this.dirty(false);
  7925. return this;
  7926. }
  7927. };
  7928. inherits(Displayable, Element);
  7929. mixin(Displayable, RectText);
  7930. /**
  7931. * @alias zrender/graphic/Image
  7932. * @extends module:zrender/graphic/Displayable
  7933. * @constructor
  7934. * @param {Object} opts
  7935. */
  7936. function ZImage(opts) {
  7937. Displayable.call(this, opts);
  7938. }
  7939. ZImage.prototype = {
  7940. constructor: ZImage,
  7941. type: 'image',
  7942. brush: function (ctx, prevEl) {
  7943. var style = this.style;
  7944. var src = style.image;
  7945. // Must bind each time
  7946. style.bind(ctx, this, prevEl);
  7947. var image = this._image = createOrUpdateImage(
  7948. src,
  7949. this._image,
  7950. this,
  7951. this.onload
  7952. );
  7953. if (!image || !isImageReady(image)) {
  7954. return;
  7955. }
  7956. // 图片已经加载完成
  7957. // if (image.nodeName.toUpperCase() == 'IMG') {
  7958. // if (!image.complete) {
  7959. // return;
  7960. // }
  7961. // }
  7962. // Else is canvas
  7963. var x = style.x || 0;
  7964. var y = style.y || 0;
  7965. var width = style.width;
  7966. var height = style.height;
  7967. var aspect = image.width / image.height;
  7968. if (width == null && height != null) {
  7969. // Keep image/height ratio
  7970. width = height * aspect;
  7971. }
  7972. else if (height == null && width != null) {
  7973. height = width / aspect;
  7974. }
  7975. else if (width == null && height == null) {
  7976. width = image.width;
  7977. height = image.height;
  7978. }
  7979. // 设置transform
  7980. this.setTransform(ctx);
  7981. if (style.sWidth && style.sHeight) {
  7982. var sx = style.sx || 0;
  7983. var sy = style.sy || 0;
  7984. ctx.drawImage(
  7985. image,
  7986. sx, sy, style.sWidth, style.sHeight,
  7987. x, y, width, height
  7988. );
  7989. }
  7990. else if (style.sx && style.sy) {
  7991. var sx = style.sx;
  7992. var sy = style.sy;
  7993. var sWidth = width - sx;
  7994. var sHeight = height - sy;
  7995. ctx.drawImage(
  7996. image,
  7997. sx, sy, sWidth, sHeight,
  7998. x, y, width, height
  7999. );
  8000. }
  8001. else {
  8002. ctx.drawImage(image, x, y, width, height);
  8003. }
  8004. // Draw rect text
  8005. if (style.text != null) {
  8006. // Only restore transform when needs draw text.
  8007. this.restoreTransform(ctx);
  8008. this.drawRectText(ctx, this.getBoundingRect());
  8009. }
  8010. },
  8011. getBoundingRect: function () {
  8012. var style = this.style;
  8013. if (!this._rect) {
  8014. this._rect = new BoundingRect(
  8015. style.x || 0, style.y || 0, style.width || 0, style.height || 0
  8016. );
  8017. }
  8018. return this._rect;
  8019. }
  8020. };
  8021. inherits(ZImage, Displayable);
  8022. var HOVER_LAYER_ZLEVEL = 1e5;
  8023. var CANVAS_ZLEVEL = 314159;
  8024. var EL_AFTER_INCREMENTAL_INC = 0.01;
  8025. var INCREMENTAL_INC = 0.001;
  8026. function parseInt10(val) {
  8027. return parseInt(val, 10);
  8028. }
  8029. function isLayerValid(layer) {
  8030. if (!layer) {
  8031. return false;
  8032. }
  8033. if (layer.__builtin__) {
  8034. return true;
  8035. }
  8036. if (typeof (layer.resize) !== 'function'
  8037. || typeof (layer.refresh) !== 'function'
  8038. ) {
  8039. return false;
  8040. }
  8041. return true;
  8042. }
  8043. var tmpRect = new BoundingRect(0, 0, 0, 0);
  8044. var viewRect = new BoundingRect(0, 0, 0, 0);
  8045. function isDisplayableCulled(el, width, height) {
  8046. tmpRect.copy(el.getBoundingRect());
  8047. if (el.transform) {
  8048. tmpRect.applyTransform(el.transform);
  8049. }
  8050. viewRect.width = width;
  8051. viewRect.height = height;
  8052. return !tmpRect.intersect(viewRect);
  8053. }
  8054. function isClipPathChanged(clipPaths, prevClipPaths) {
  8055. if (clipPaths === prevClipPaths) { // Can both be null or undefined
  8056. return false;
  8057. }
  8058. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  8059. return true;
  8060. }
  8061. for (var i = 0; i < clipPaths.length; i++) {
  8062. if (clipPaths[i] !== prevClipPaths[i]) {
  8063. return true;
  8064. }
  8065. }
  8066. }
  8067. function doClip(clipPaths, ctx) {
  8068. for (var i = 0; i < clipPaths.length; i++) {
  8069. var clipPath = clipPaths[i];
  8070. clipPath.setTransform(ctx);
  8071. ctx.beginPath();
  8072. clipPath.buildPath(ctx, clipPath.shape);
  8073. ctx.clip();
  8074. // Transform back
  8075. clipPath.restoreTransform(ctx);
  8076. }
  8077. }
  8078. function createRoot(width, height) {
  8079. var domRoot = document.createElement('div');
  8080. // domRoot.onselectstart = returnFalse; // 避免页面选中的尴尬
  8081. domRoot.style.cssText = [
  8082. 'position:relative',
  8083. 'overflow:hidden',
  8084. 'width:' + width + 'px',
  8085. 'height:' + height + 'px',
  8086. 'padding:0',
  8087. 'margin:0',
  8088. 'border-width:0'
  8089. ].join(';') + ';';
  8090. return domRoot;
  8091. }
  8092. /**
  8093. * @alias module:zrender/Painter
  8094. * @constructor
  8095. * @param {HTMLElement} root 绘图容器
  8096. * @param {module:zrender/Storage} storage
  8097. * @param {Object} opts
  8098. */
  8099. var Painter = function (root, storage, opts) {
  8100. this.type = 'canvas';
  8101. // In node environment using node-canvas
  8102. var singleCanvas = !root.nodeName // In node ?
  8103. || root.nodeName.toUpperCase() === 'CANVAS';
  8104. this._opts = opts = extend({}, opts || {});
  8105. /**
  8106. * @type {number}
  8107. */
  8108. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  8109. /**
  8110. * @type {boolean}
  8111. * @private
  8112. */
  8113. this._singleCanvas = singleCanvas;
  8114. /**
  8115. * 绘图容器
  8116. * @type {HTMLElement}
  8117. */
  8118. this.root = root;
  8119. var rootStyle = root.style;
  8120. if (rootStyle) {
  8121. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  8122. rootStyle['-webkit-user-select'] =
  8123. rootStyle['user-select'] =
  8124. rootStyle['-webkit-touch-callout'] = 'none';
  8125. root.innerHTML = '';
  8126. }
  8127. /**
  8128. * @type {module:zrender/Storage}
  8129. */
  8130. this.storage = storage;
  8131. /**
  8132. * @type {Array.<number>}
  8133. * @private
  8134. */
  8135. var zlevelList = this._zlevelList = [];
  8136. /**
  8137. * @type {Object.<string, module:zrender/Layer>}
  8138. * @private
  8139. */
  8140. var layers = this._layers = {};
  8141. /**
  8142. * @type {Object.<string, Object>}
  8143. * @private
  8144. */
  8145. this._layerConfig = {};
  8146. /**
  8147. * zrender will do compositing when root is a canvas and have multiple zlevels.
  8148. */
  8149. this._needsManuallyCompositing = false;
  8150. if (!singleCanvas) {
  8151. this._width = this._getSize(0);
  8152. this._height = this._getSize(1);
  8153. var domRoot = this._domRoot = createRoot(
  8154. this._width, this._height
  8155. );
  8156. root.appendChild(domRoot);
  8157. }
  8158. else {
  8159. var width = root.width;
  8160. var height = root.height;
  8161. if (opts.width != null) {
  8162. width = opts.width;
  8163. }
  8164. if (opts.height != null) {
  8165. height = opts.height;
  8166. }
  8167. this.dpr = opts.devicePixelRatio || 1;
  8168. // Use canvas width and height directly
  8169. root.width = width * this.dpr;
  8170. root.height = height * this.dpr;
  8171. this._width = width;
  8172. this._height = height;
  8173. // Create layer if only one given canvas
  8174. // Device can be specified to create a high dpi image.
  8175. var mainLayer = new Layer(root, this, this.dpr);
  8176. mainLayer.__builtin__ = true;
  8177. mainLayer.initContext();
  8178. // FIXME Use canvas width and height
  8179. // mainLayer.resize(width, height);
  8180. layers[CANVAS_ZLEVEL] = mainLayer;
  8181. mainLayer.zlevel = CANVAS_ZLEVEL;
  8182. // Not use common zlevel.
  8183. zlevelList.push(CANVAS_ZLEVEL);
  8184. this._domRoot = root;
  8185. }
  8186. /**
  8187. * @type {module:zrender/Layer}
  8188. * @private
  8189. */
  8190. this._hoverlayer = null;
  8191. this._hoverElements = [];
  8192. };
  8193. Painter.prototype = {
  8194. constructor: Painter,
  8195. getType: function () {
  8196. return 'canvas';
  8197. },
  8198. /**
  8199. * If painter use a single canvas
  8200. * @return {boolean}
  8201. */
  8202. isSingleCanvas: function () {
  8203. return this._singleCanvas;
  8204. },
  8205. /**
  8206. * @return {HTMLDivElement}
  8207. */
  8208. getViewportRoot: function () {
  8209. return this._domRoot;
  8210. },
  8211. getViewportRootOffset: function () {
  8212. var viewportRoot = this.getViewportRoot();
  8213. if (viewportRoot) {
  8214. return {
  8215. offsetLeft: viewportRoot.offsetLeft || 0,
  8216. offsetTop: viewportRoot.offsetTop || 0
  8217. };
  8218. }
  8219. },
  8220. /**
  8221. * 刷新
  8222. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  8223. */
  8224. refresh: function (paintAll) {
  8225. var list = this.storage.getDisplayList(true);
  8226. var zlevelList = this._zlevelList;
  8227. this._redrawId = Math.random();
  8228. this._paintList(list, paintAll, this._redrawId);
  8229. // Paint custum layers
  8230. for (var i = 0; i < zlevelList.length; i++) {
  8231. var z = zlevelList[i];
  8232. var layer = this._layers[z];
  8233. if (!layer.__builtin__ && layer.refresh) {
  8234. var clearColor = i === 0 ? this._backgroundColor : null;
  8235. layer.refresh(clearColor);
  8236. }
  8237. }
  8238. this.refreshHover();
  8239. return this;
  8240. },
  8241. addHover: function (el, hoverStyle) {
  8242. if (el.__hoverMir) {
  8243. return;
  8244. }
  8245. var elMirror = new el.constructor({
  8246. style: el.style,
  8247. shape: el.shape,
  8248. z: el.z,
  8249. z2: el.z2,
  8250. silent: el.silent
  8251. });
  8252. elMirror.__from = el;
  8253. el.__hoverMir = elMirror;
  8254. hoverStyle && elMirror.setStyle(hoverStyle);
  8255. this._hoverElements.push(elMirror);
  8256. return elMirror;
  8257. },
  8258. removeHover: function (el) {
  8259. var elMirror = el.__hoverMir;
  8260. var hoverElements = this._hoverElements;
  8261. var idx = indexOf(hoverElements, elMirror);
  8262. if (idx >= 0) {
  8263. hoverElements.splice(idx, 1);
  8264. }
  8265. el.__hoverMir = null;
  8266. },
  8267. clearHover: function (el) {
  8268. var hoverElements = this._hoverElements;
  8269. for (var i = 0; i < hoverElements.length; i++) {
  8270. var from = hoverElements[i].__from;
  8271. if (from) {
  8272. from.__hoverMir = null;
  8273. }
  8274. }
  8275. hoverElements.length = 0;
  8276. },
  8277. refreshHover: function () {
  8278. var hoverElements = this._hoverElements;
  8279. var len = hoverElements.length;
  8280. var hoverLayer = this._hoverlayer;
  8281. hoverLayer && hoverLayer.clear();
  8282. if (!len) {
  8283. return;
  8284. }
  8285. sort(hoverElements, this.storage.displayableSortFunc);
  8286. // Use a extream large zlevel
  8287. // FIXME?
  8288. if (!hoverLayer) {
  8289. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  8290. }
  8291. var scope = {};
  8292. hoverLayer.ctx.save();
  8293. for (var i = 0; i < len;) {
  8294. var el = hoverElements[i];
  8295. var originalEl = el.__from;
  8296. // Original el is removed
  8297. // PENDING
  8298. if (!(originalEl && originalEl.__zr)) {
  8299. hoverElements.splice(i, 1);
  8300. originalEl.__hoverMir = null;
  8301. len--;
  8302. continue;
  8303. }
  8304. i++;
  8305. // Use transform
  8306. // FIXME style and shape ?
  8307. if (!originalEl.invisible) {
  8308. el.transform = originalEl.transform;
  8309. el.invTransform = originalEl.invTransform;
  8310. el.__clipPaths = originalEl.__clipPaths;
  8311. // el.
  8312. this._doPaintEl(el, hoverLayer, true, scope);
  8313. }
  8314. }
  8315. hoverLayer.ctx.restore();
  8316. },
  8317. getHoverLayer: function () {
  8318. return this.getLayer(HOVER_LAYER_ZLEVEL);
  8319. },
  8320. _paintList: function (list, paintAll, redrawId) {
  8321. if (this._redrawId !== redrawId) {
  8322. return;
  8323. }
  8324. paintAll = paintAll || false;
  8325. this._updateLayerStatus(list);
  8326. var finished = this._doPaintList(list, paintAll);
  8327. if (this._needsManuallyCompositing) {
  8328. this._compositeManually();
  8329. }
  8330. if (!finished) {
  8331. var self = this;
  8332. requestAnimationFrame(function () {
  8333. self._paintList(list, paintAll, redrawId);
  8334. });
  8335. }
  8336. },
  8337. _compositeManually: function () {
  8338. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  8339. var width = this._domRoot.width;
  8340. var height = this._domRoot.height;
  8341. ctx.clearRect(0, 0, width, height);
  8342. // PENDING, If only builtin layer?
  8343. this.eachBuiltinLayer(function (layer) {
  8344. if (layer.virtual) {
  8345. ctx.drawImage(layer.dom, 0, 0, width, height);
  8346. }
  8347. });
  8348. },
  8349. _doPaintList: function (list, paintAll) {
  8350. var layerList = [];
  8351. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  8352. var zlevel = this._zlevelList[zi];
  8353. var layer = this._layers[zlevel];
  8354. if (layer.__builtin__
  8355. && layer !== this._hoverlayer
  8356. && (layer.__dirty || paintAll)
  8357. ) {
  8358. layerList.push(layer);
  8359. }
  8360. }
  8361. var finished = true;
  8362. for (var k = 0; k < layerList.length; k++) {
  8363. var layer = layerList[k];
  8364. var ctx = layer.ctx;
  8365. var scope = {};
  8366. ctx.save();
  8367. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  8368. var useTimer = !paintAll && layer.incremental && Date.now;
  8369. var startTime = useTimer && Date.now();
  8370. var clearColor = layer.zlevel === this._zlevelList[0]
  8371. ? this._backgroundColor : null;
  8372. // All elements in this layer are cleared.
  8373. if (layer.__startIndex === layer.__endIndex) {
  8374. layer.clear(false, clearColor);
  8375. }
  8376. else if (start === layer.__startIndex) {
  8377. var firstEl = list[start];
  8378. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  8379. layer.clear(false, clearColor);
  8380. }
  8381. }
  8382. if (start === -1) {
  8383. console.error('For some unknown reason. drawIndex is -1');
  8384. start = layer.__startIndex;
  8385. }
  8386. for (var i = start; i < layer.__endIndex; i++) {
  8387. var el = list[i];
  8388. this._doPaintEl(el, layer, paintAll, scope);
  8389. el.__dirty = el.__dirtyText = false;
  8390. if (useTimer) {
  8391. // Date.now can be executed in 13,025,305 ops/second.
  8392. var dTime = Date.now() - startTime;
  8393. // Give 15 millisecond to draw.
  8394. // The rest elements will be drawn in the next frame.
  8395. if (dTime > 15) {
  8396. break;
  8397. }
  8398. }
  8399. }
  8400. layer.__drawIndex = i;
  8401. if (layer.__drawIndex < layer.__endIndex) {
  8402. finished = false;
  8403. }
  8404. if (scope.prevElClipPaths) {
  8405. // Needs restore the state. If last drawn element is in the clipping area.
  8406. ctx.restore();
  8407. }
  8408. ctx.restore();
  8409. }
  8410. if (env$1.wxa) {
  8411. // Flush for weixin application
  8412. each$1(this._layers, function (layer) {
  8413. if (layer && layer.ctx && layer.ctx.draw) {
  8414. layer.ctx.draw();
  8415. }
  8416. });
  8417. }
  8418. return finished;
  8419. },
  8420. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  8421. var ctx = currentLayer.ctx;
  8422. var m = el.transform;
  8423. if (
  8424. (currentLayer.__dirty || forcePaint)
  8425. // Ignore invisible element
  8426. && !el.invisible
  8427. // Ignore transparent element
  8428. && el.style.opacity !== 0
  8429. // Ignore scale 0 element, in some environment like node-canvas
  8430. // Draw a scale 0 element can cause all following draw wrong
  8431. // And setTransform with scale 0 will cause set back transform failed.
  8432. && !(m && !m[0] && !m[3])
  8433. // Ignore culled element
  8434. && !(el.culling && isDisplayableCulled(el, this._width, this._height))
  8435. ) {
  8436. var clipPaths = el.__clipPaths;
  8437. // Optimize when clipping on group with several elements
  8438. if (!scope.prevElClipPaths
  8439. || isClipPathChanged(clipPaths, scope.prevElClipPaths)
  8440. ) {
  8441. // If has previous clipping state, restore from it
  8442. if (scope.prevElClipPaths) {
  8443. currentLayer.ctx.restore();
  8444. scope.prevElClipPaths = null;
  8445. // Reset prevEl since context has been restored
  8446. scope.prevEl = null;
  8447. }
  8448. // New clipping state
  8449. if (clipPaths) {
  8450. ctx.save();
  8451. doClip(clipPaths, ctx);
  8452. scope.prevElClipPaths = clipPaths;
  8453. }
  8454. }
  8455. el.beforeBrush && el.beforeBrush(ctx);
  8456. el.brush(ctx, scope.prevEl || null);
  8457. scope.prevEl = el;
  8458. el.afterBrush && el.afterBrush(ctx);
  8459. }
  8460. },
  8461. /**
  8462. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  8463. * @param {number} zlevel
  8464. * @param {boolean} virtual Virtual layer will not be inserted into dom.
  8465. * @return {module:zrender/Layer}
  8466. */
  8467. getLayer: function (zlevel, virtual) {
  8468. if (this._singleCanvas && !this._needsManuallyCompositing) {
  8469. zlevel = CANVAS_ZLEVEL;
  8470. }
  8471. var layer = this._layers[zlevel];
  8472. if (!layer) {
  8473. // Create a new layer
  8474. layer = new Layer('zr_' + zlevel, this, this.dpr);
  8475. layer.zlevel = zlevel;
  8476. layer.__builtin__ = true;
  8477. if (this._layerConfig[zlevel]) {
  8478. merge(layer, this._layerConfig[zlevel], true);
  8479. }
  8480. if (virtual) {
  8481. layer.virtual = virtual;
  8482. }
  8483. this.insertLayer(zlevel, layer);
  8484. // Context is created after dom inserted to document
  8485. // Or excanvas will get 0px clientWidth and clientHeight
  8486. layer.initContext();
  8487. }
  8488. return layer;
  8489. },
  8490. insertLayer: function (zlevel, layer) {
  8491. var layersMap = this._layers;
  8492. var zlevelList = this._zlevelList;
  8493. var len = zlevelList.length;
  8494. var prevLayer = null;
  8495. var i = -1;
  8496. var domRoot = this._domRoot;
  8497. if (layersMap[zlevel]) {
  8498. zrLog('ZLevel ' + zlevel + ' has been used already');
  8499. return;
  8500. }
  8501. // Check if is a valid layer
  8502. if (!isLayerValid(layer)) {
  8503. zrLog('Layer of zlevel ' + zlevel + ' is not valid');
  8504. return;
  8505. }
  8506. if (len > 0 && zlevel > zlevelList[0]) {
  8507. for (i = 0; i < len - 1; i++) {
  8508. if (
  8509. zlevelList[i] < zlevel
  8510. && zlevelList[i + 1] > zlevel
  8511. ) {
  8512. break;
  8513. }
  8514. }
  8515. prevLayer = layersMap[zlevelList[i]];
  8516. }
  8517. zlevelList.splice(i + 1, 0, zlevel);
  8518. layersMap[zlevel] = layer;
  8519. // Vitual layer will not directly show on the screen.
  8520. // (It can be a WebGL layer and assigned to a ZImage element)
  8521. // But it still under management of zrender.
  8522. if (!layer.virtual) {
  8523. if (prevLayer) {
  8524. var prevDom = prevLayer.dom;
  8525. if (prevDom.nextSibling) {
  8526. domRoot.insertBefore(
  8527. layer.dom,
  8528. prevDom.nextSibling
  8529. );
  8530. }
  8531. else {
  8532. domRoot.appendChild(layer.dom);
  8533. }
  8534. }
  8535. else {
  8536. if (domRoot.firstChild) {
  8537. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  8538. }
  8539. else {
  8540. domRoot.appendChild(layer.dom);
  8541. }
  8542. }
  8543. }
  8544. },
  8545. // Iterate each layer
  8546. eachLayer: function (cb, context) {
  8547. var zlevelList = this._zlevelList;
  8548. var z;
  8549. var i;
  8550. for (i = 0; i < zlevelList.length; i++) {
  8551. z = zlevelList[i];
  8552. cb.call(context, this._layers[z], z);
  8553. }
  8554. },
  8555. // Iterate each buildin layer
  8556. eachBuiltinLayer: function (cb, context) {
  8557. var zlevelList = this._zlevelList;
  8558. var layer;
  8559. var z;
  8560. var i;
  8561. for (i = 0; i < zlevelList.length; i++) {
  8562. z = zlevelList[i];
  8563. layer = this._layers[z];
  8564. if (layer.__builtin__) {
  8565. cb.call(context, layer, z);
  8566. }
  8567. }
  8568. },
  8569. // Iterate each other layer except buildin layer
  8570. eachOtherLayer: function (cb, context) {
  8571. var zlevelList = this._zlevelList;
  8572. var layer;
  8573. var z;
  8574. var i;
  8575. for (i = 0; i < zlevelList.length; i++) {
  8576. z = zlevelList[i];
  8577. layer = this._layers[z];
  8578. if (!layer.__builtin__) {
  8579. cb.call(context, layer, z);
  8580. }
  8581. }
  8582. },
  8583. /**
  8584. * 获取所有已创建的层
  8585. * @param {Array.<module:zrender/Layer>} [prevLayer]
  8586. */
  8587. getLayers: function () {
  8588. return this._layers;
  8589. },
  8590. _updateLayerStatus: function (list) {
  8591. this.eachBuiltinLayer(function (layer, z) {
  8592. layer.__dirty = layer.__used = false;
  8593. });
  8594. function updatePrevLayer(idx) {
  8595. if (prevLayer) {
  8596. if (prevLayer.__endIndex !== idx) {
  8597. prevLayer.__dirty = true;
  8598. }
  8599. prevLayer.__endIndex = idx;
  8600. }
  8601. }
  8602. if (this._singleCanvas) {
  8603. for (var i = 1; i < list.length; i++) {
  8604. var el = list[i];
  8605. if (el.zlevel !== list[i - 1].zlevel || el.incremental) {
  8606. this._needsManuallyCompositing = true;
  8607. break;
  8608. }
  8609. }
  8610. }
  8611. var prevLayer = null;
  8612. var incrementalLayerCount = 0;
  8613. for (var i = 0; i < list.length; i++) {
  8614. var el = list[i];
  8615. var zlevel = el.zlevel;
  8616. var layer;
  8617. // PENDING If change one incremental element style ?
  8618. // TODO Where there are non-incremental elements between incremental elements.
  8619. if (el.incremental) {
  8620. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  8621. layer.incremental = true;
  8622. incrementalLayerCount = 1;
  8623. }
  8624. else {
  8625. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  8626. }
  8627. if (!layer.__builtin__) {
  8628. zrLog('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  8629. }
  8630. if (layer !== prevLayer) {
  8631. layer.__used = true;
  8632. if (layer.__startIndex !== i) {
  8633. layer.__dirty = true;
  8634. }
  8635. layer.__startIndex = i;
  8636. if (!layer.incremental) {
  8637. layer.__drawIndex = i;
  8638. }
  8639. else {
  8640. // Mark layer draw index needs to update.
  8641. layer.__drawIndex = -1;
  8642. }
  8643. updatePrevLayer(i);
  8644. prevLayer = layer;
  8645. }
  8646. if (el.__dirty) {
  8647. layer.__dirty = true;
  8648. if (layer.incremental && layer.__drawIndex < 0) {
  8649. // Start draw from the first dirty element.
  8650. layer.__drawIndex = i;
  8651. }
  8652. }
  8653. }
  8654. updatePrevLayer(i);
  8655. this.eachBuiltinLayer(function (layer, z) {
  8656. // Used in last frame but not in this frame. Needs clear
  8657. if (!layer.__used && layer.getElementCount() > 0) {
  8658. layer.__dirty = true;
  8659. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  8660. }
  8661. // For incremental layer. In case start index changed and no elements are dirty.
  8662. if (layer.__dirty && layer.__drawIndex < 0) {
  8663. layer.__drawIndex = layer.__startIndex;
  8664. }
  8665. });
  8666. },
  8667. /**
  8668. * 清除hover层外所有内容
  8669. */
  8670. clear: function () {
  8671. this.eachBuiltinLayer(this._clearLayer);
  8672. return this;
  8673. },
  8674. _clearLayer: function (layer) {
  8675. layer.clear();
  8676. },
  8677. setBackgroundColor: function (backgroundColor) {
  8678. this._backgroundColor = backgroundColor;
  8679. },
  8680. /**
  8681. * 修改指定zlevel的绘制参数
  8682. *
  8683. * @param {string} zlevel
  8684. * @param {Object} config 配置对象
  8685. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  8686. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  8687. * @param {number} [config.lastFrameAlpha=0.7]
  8688. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  8689. */
  8690. configLayer: function (zlevel, config) {
  8691. if (config) {
  8692. var layerConfig = this._layerConfig;
  8693. if (!layerConfig[zlevel]) {
  8694. layerConfig[zlevel] = config;
  8695. }
  8696. else {
  8697. merge(layerConfig[zlevel], config, true);
  8698. }
  8699. for (var i = 0; i < this._zlevelList.length; i++) {
  8700. var _zlevel = this._zlevelList[i];
  8701. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  8702. var layer = this._layers[_zlevel];
  8703. merge(layer, layerConfig[zlevel], true);
  8704. }
  8705. }
  8706. }
  8707. },
  8708. /**
  8709. * 删除指定层
  8710. * @param {number} zlevel 层所在的zlevel
  8711. */
  8712. delLayer: function (zlevel) {
  8713. var layers = this._layers;
  8714. var zlevelList = this._zlevelList;
  8715. var layer = layers[zlevel];
  8716. if (!layer) {
  8717. return;
  8718. }
  8719. layer.dom.parentNode.removeChild(layer.dom);
  8720. delete layers[zlevel];
  8721. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  8722. },
  8723. /**
  8724. * 区域大小变化后重绘
  8725. */
  8726. resize: function (width, height) {
  8727. if (!this._domRoot.style) { // Maybe in node or worker
  8728. if (width == null || height == null) {
  8729. return;
  8730. }
  8731. this._width = width;
  8732. this._height = height;
  8733. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  8734. }
  8735. else {
  8736. var domRoot = this._domRoot;
  8737. // FIXME Why ?
  8738. domRoot.style.display = 'none';
  8739. // Save input w/h
  8740. var opts = this._opts;
  8741. width != null && (opts.width = width);
  8742. height != null && (opts.height = height);
  8743. width = this._getSize(0);
  8744. height = this._getSize(1);
  8745. domRoot.style.display = '';
  8746. // 优化没有实际改变的resize
  8747. if (this._width !== width || height !== this._height) {
  8748. domRoot.style.width = width + 'px';
  8749. domRoot.style.height = height + 'px';
  8750. for (var id in this._layers) {
  8751. if (this._layers.hasOwnProperty(id)) {
  8752. this._layers[id].resize(width, height);
  8753. }
  8754. }
  8755. each$1(this._progressiveLayers, function (layer) {
  8756. layer.resize(width, height);
  8757. });
  8758. this.refresh(true);
  8759. }
  8760. this._width = width;
  8761. this._height = height;
  8762. }
  8763. return this;
  8764. },
  8765. /**
  8766. * 清除单独的一个层
  8767. * @param {number} zlevel
  8768. */
  8769. clearLayer: function (zlevel) {
  8770. var layer = this._layers[zlevel];
  8771. if (layer) {
  8772. layer.clear();
  8773. }
  8774. },
  8775. /**
  8776. * 释放
  8777. */
  8778. dispose: function () {
  8779. this.root.innerHTML = '';
  8780. this.root =
  8781. this.storage =
  8782. this._domRoot =
  8783. this._layers = null;
  8784. },
  8785. /**
  8786. * Get canvas which has all thing rendered
  8787. * @param {Object} opts
  8788. * @param {string} [opts.backgroundColor]
  8789. * @param {number} [opts.pixelRatio]
  8790. */
  8791. getRenderedCanvas: function (opts) {
  8792. opts = opts || {};
  8793. if (this._singleCanvas && !this._compositeManually) {
  8794. return this._layers[CANVAS_ZLEVEL].dom;
  8795. }
  8796. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  8797. imageLayer.initContext();
  8798. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  8799. if (opts.pixelRatio <= this.dpr) {
  8800. this.refresh();
  8801. var width = imageLayer.dom.width;
  8802. var height = imageLayer.dom.height;
  8803. var ctx = imageLayer.ctx;
  8804. this.eachLayer(function (layer) {
  8805. if (layer.__builtin__) {
  8806. ctx.drawImage(layer.dom, 0, 0, width, height);
  8807. }
  8808. else if (layer.renderToCanvas) {
  8809. imageLayer.ctx.save();
  8810. layer.renderToCanvas(imageLayer.ctx);
  8811. imageLayer.ctx.restore();
  8812. }
  8813. });
  8814. }
  8815. else {
  8816. // PENDING, echarts-gl and incremental rendering.
  8817. var scope = {};
  8818. var displayList = this.storage.getDisplayList(true);
  8819. for (var i = 0; i < displayList.length; i++) {
  8820. var el = displayList[i];
  8821. this._doPaintEl(el, imageLayer, true, scope);
  8822. }
  8823. }
  8824. return imageLayer.dom;
  8825. },
  8826. /**
  8827. * 获取绘图区域宽度
  8828. */
  8829. getWidth: function () {
  8830. return this._width;
  8831. },
  8832. /**
  8833. * 获取绘图区域高度
  8834. */
  8835. getHeight: function () {
  8836. return this._height;
  8837. },
  8838. _getSize: function (whIdx) {
  8839. var opts = this._opts;
  8840. var wh = ['width', 'height'][whIdx];
  8841. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  8842. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  8843. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  8844. if (opts[wh] != null && opts[wh] !== 'auto') {
  8845. return parseFloat(opts[wh]);
  8846. }
  8847. var root = this.root;
  8848. // IE8 does not support getComputedStyle, but it use VML.
  8849. var stl = document.defaultView.getComputedStyle(root);
  8850. return (
  8851. (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  8852. - (parseInt10(stl[plt]) || 0)
  8853. - (parseInt10(stl[prb]) || 0)
  8854. ) | 0;
  8855. },
  8856. pathToImage: function (path, dpr) {
  8857. dpr = dpr || this.dpr;
  8858. var canvas = document.createElement('canvas');
  8859. var ctx = canvas.getContext('2d');
  8860. var rect = path.getBoundingRect();
  8861. var style = path.style;
  8862. var shadowBlurSize = style.shadowBlur * dpr;
  8863. var shadowOffsetX = style.shadowOffsetX * dpr;
  8864. var shadowOffsetY = style.shadowOffsetY * dpr;
  8865. var lineWidth = style.hasStroke() ? style.lineWidth : 0;
  8866. var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);
  8867. var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);
  8868. var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);
  8869. var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);
  8870. var width = rect.width + leftMargin + rightMargin;
  8871. var height = rect.height + topMargin + bottomMargin;
  8872. canvas.width = width * dpr;
  8873. canvas.height = height * dpr;
  8874. ctx.scale(dpr, dpr);
  8875. ctx.clearRect(0, 0, width, height);
  8876. ctx.dpr = dpr;
  8877. var pathTransform = {
  8878. position: path.position,
  8879. rotation: path.rotation,
  8880. scale: path.scale
  8881. };
  8882. path.position = [leftMargin - rect.x, topMargin - rect.y];
  8883. path.rotation = 0;
  8884. path.scale = [1, 1];
  8885. path.updateTransform();
  8886. if (path) {
  8887. path.brush(ctx);
  8888. }
  8889. var ImageShape = ZImage;
  8890. var imgShape = new ImageShape({
  8891. style: {
  8892. x: 0,
  8893. y: 0,
  8894. image: canvas
  8895. }
  8896. });
  8897. if (pathTransform.position != null) {
  8898. imgShape.position = path.position = pathTransform.position;
  8899. }
  8900. if (pathTransform.rotation != null) {
  8901. imgShape.rotation = path.rotation = pathTransform.rotation;
  8902. }
  8903. if (pathTransform.scale != null) {
  8904. imgShape.scale = path.scale = pathTransform.scale;
  8905. }
  8906. return imgShape;
  8907. }
  8908. };
  8909. /**
  8910. * 动画主类, 调度和管理所有动画控制器
  8911. *
  8912. * @module zrender/animation/Animation
  8913. * @author pissang(https://github.com/pissang)
  8914. */
  8915. // TODO Additive animation
  8916. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  8917. // https://developer.apple.com/videos/wwdc2014/#236
  8918. /**
  8919. * @typedef {Object} IZRenderStage
  8920. * @property {Function} update
  8921. */
  8922. /**
  8923. * @alias module:zrender/animation/Animation
  8924. * @constructor
  8925. * @param {Object} [options]
  8926. * @param {Function} [options.onframe]
  8927. * @param {IZRenderStage} [options.stage]
  8928. * @example
  8929. * var animation = new Animation();
  8930. * var obj = {
  8931. * x: 100,
  8932. * y: 100
  8933. * };
  8934. * animation.animate(node.position)
  8935. * .when(1000, {
  8936. * x: 500,
  8937. * y: 500
  8938. * })
  8939. * .when(2000, {
  8940. * x: 100,
  8941. * y: 100
  8942. * })
  8943. * .start('spline');
  8944. */
  8945. var Animation = function (options) {
  8946. options = options || {};
  8947. this.stage = options.stage || {};
  8948. this.onframe = options.onframe || function () {};
  8949. // private properties
  8950. this._clips = [];
  8951. this._running = false;
  8952. this._time;
  8953. this._pausedTime;
  8954. this._pauseStart;
  8955. this._paused = false;
  8956. Eventful.call(this);
  8957. };
  8958. Animation.prototype = {
  8959. constructor: Animation,
  8960. /**
  8961. * 添加 clip
  8962. * @param {module:zrender/animation/Clip} clip
  8963. */
  8964. addClip: function (clip) {
  8965. this._clips.push(clip);
  8966. },
  8967. /**
  8968. * 添加 animator
  8969. * @param {module:zrender/animation/Animator} animator
  8970. */
  8971. addAnimator: function (animator) {
  8972. animator.animation = this;
  8973. var clips = animator.getClips();
  8974. for (var i = 0; i < clips.length; i++) {
  8975. this.addClip(clips[i]);
  8976. }
  8977. },
  8978. /**
  8979. * 删除动画片段
  8980. * @param {module:zrender/animation/Clip} clip
  8981. */
  8982. removeClip: function (clip) {
  8983. var idx = indexOf(this._clips, clip);
  8984. if (idx >= 0) {
  8985. this._clips.splice(idx, 1);
  8986. }
  8987. },
  8988. /**
  8989. * 删除动画片段
  8990. * @param {module:zrender/animation/Animator} animator
  8991. */
  8992. removeAnimator: function (animator) {
  8993. var clips = animator.getClips();
  8994. for (var i = 0; i < clips.length; i++) {
  8995. this.removeClip(clips[i]);
  8996. }
  8997. animator.animation = null;
  8998. },
  8999. _update: function () {
  9000. var time = new Date().getTime() - this._pausedTime;
  9001. var delta = time - this._time;
  9002. var clips = this._clips;
  9003. var len = clips.length;
  9004. var deferredEvents = [];
  9005. var deferredClips = [];
  9006. for (var i = 0; i < len; i++) {
  9007. var clip = clips[i];
  9008. var e = clip.step(time, delta);
  9009. // Throw out the events need to be called after
  9010. // stage.update, like destroy
  9011. if (e) {
  9012. deferredEvents.push(e);
  9013. deferredClips.push(clip);
  9014. }
  9015. }
  9016. // Remove the finished clip
  9017. for (var i = 0; i < len;) {
  9018. if (clips[i]._needsRemove) {
  9019. clips[i] = clips[len - 1];
  9020. clips.pop();
  9021. len--;
  9022. }
  9023. else {
  9024. i++;
  9025. }
  9026. }
  9027. len = deferredEvents.length;
  9028. for (var i = 0; i < len; i++) {
  9029. deferredClips[i].fire(deferredEvents[i]);
  9030. }
  9031. this._time = time;
  9032. this.onframe(delta);
  9033. // 'frame' should be triggered before stage, because upper application
  9034. // depends on the sequence (e.g., echarts-stream and finish
  9035. // event judge)
  9036. this.trigger('frame', delta);
  9037. if (this.stage.update) {
  9038. this.stage.update();
  9039. }
  9040. },
  9041. _startLoop: function () {
  9042. var self = this;
  9043. this._running = true;
  9044. function step() {
  9045. if (self._running) {
  9046. requestAnimationFrame(step);
  9047. !self._paused && self._update();
  9048. }
  9049. }
  9050. requestAnimationFrame(step);
  9051. },
  9052. /**
  9053. * Start animation.
  9054. */
  9055. start: function () {
  9056. this._time = new Date().getTime();
  9057. this._pausedTime = 0;
  9058. this._startLoop();
  9059. },
  9060. /**
  9061. * Stop animation.
  9062. */
  9063. stop: function () {
  9064. this._running = false;
  9065. },
  9066. /**
  9067. * Pause animation.
  9068. */
  9069. pause: function () {
  9070. if (!this._paused) {
  9071. this._pauseStart = new Date().getTime();
  9072. this._paused = true;
  9073. }
  9074. },
  9075. /**
  9076. * Resume animation.
  9077. */
  9078. resume: function () {
  9079. if (this._paused) {
  9080. this._pausedTime += (new Date().getTime()) - this._pauseStart;
  9081. this._paused = false;
  9082. }
  9083. },
  9084. /**
  9085. * Clear animation.
  9086. */
  9087. clear: function () {
  9088. this._clips = [];
  9089. },
  9090. /**
  9091. * Whether animation finished.
  9092. */
  9093. isFinished: function () {
  9094. return !this._clips.length;
  9095. },
  9096. /**
  9097. * Creat animator for a target, whose props can be animated.
  9098. *
  9099. * @param {Object} target
  9100. * @param {Object} options
  9101. * @param {boolean} [options.loop=false] Whether loop animation.
  9102. * @param {Function} [options.getter=null] Get value from target.
  9103. * @param {Function} [options.setter=null] Set value to target.
  9104. * @return {module:zrender/animation/Animation~Animator}
  9105. */
  9106. // TODO Gap
  9107. animate: function (target, options) {
  9108. options = options || {};
  9109. var animator = new Animator(
  9110. target,
  9111. options.loop,
  9112. options.getter,
  9113. options.setter
  9114. );
  9115. this.addAnimator(animator);
  9116. return animator;
  9117. }
  9118. };
  9119. mixin(Animation, Eventful);
  9120. var TOUCH_CLICK_DELAY = 300;
  9121. var mouseHandlerNames = [
  9122. 'click', 'dblclick', 'mousewheel', 'mouseout',
  9123. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  9124. ];
  9125. var touchHandlerNames = [
  9126. 'touchstart', 'touchend', 'touchmove'
  9127. ];
  9128. var pointerEventNames = {
  9129. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  9130. };
  9131. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  9132. var nm = name.replace('mouse', 'pointer');
  9133. return pointerEventNames[nm] ? nm : name;
  9134. });
  9135. function eventNameFix(name) {
  9136. return (name === 'mousewheel' && env$1.browser.firefox) ? 'DOMMouseScroll' : name;
  9137. }
  9138. // function onMSGestureChange(proxy, event) {
  9139. // if (event.translationX || event.translationY) {
  9140. // // mousemove is carried by MSGesture to reduce the sensitivity.
  9141. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  9142. // }
  9143. // if (event.scale !== 1) {
  9144. // event.pinchX = event.offsetX;
  9145. // event.pinchY = event.offsetY;
  9146. // event.pinchScale = event.scale;
  9147. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  9148. // }
  9149. // }
  9150. /**
  9151. * Prevent mouse event from being dispatched after Touch Events action
  9152. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  9153. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  9154. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  9155. * Result: Blocking Mouse Events for 700ms.
  9156. */
  9157. function setTouchTimer(instance) {
  9158. instance._touching = true;
  9159. clearTimeout(instance._touchTimer);
  9160. instance._touchTimer = setTimeout(function () {
  9161. instance._touching = false;
  9162. }, 700);
  9163. }
  9164. var domHandlers = {
  9165. /**
  9166. * Mouse move handler
  9167. * @inner
  9168. * @param {Event} event
  9169. */
  9170. mousemove: function (event) {
  9171. event = normalizeEvent(this.dom, event);
  9172. this.trigger('mousemove', event);
  9173. },
  9174. /**
  9175. * Mouse out handler
  9176. * @inner
  9177. * @param {Event} event
  9178. */
  9179. mouseout: function (event) {
  9180. event = normalizeEvent(this.dom, event);
  9181. var element = event.toElement || event.relatedTarget;
  9182. if (element !== this.dom) {
  9183. while (element && element.nodeType !== 9) {
  9184. // 忽略包含在root中的dom引起的mouseOut
  9185. if (element === this.dom) {
  9186. return;
  9187. }
  9188. element = element.parentNode;
  9189. }
  9190. }
  9191. this.trigger('mouseout', event);
  9192. },
  9193. /**
  9194. * Touch开始响应函数
  9195. * @inner
  9196. * @param {Event} event
  9197. */
  9198. touchstart: function (event) {
  9199. // Default mouse behaviour should not be disabled here.
  9200. // For example, page may needs to be slided.
  9201. event = normalizeEvent(this.dom, event);
  9202. // Mark touch, which is useful in distinguish touch and
  9203. // mouse event in upper applicatoin.
  9204. event.zrByTouch = true;
  9205. this._lastTouchMoment = new Date();
  9206. this.handler.processGesture(this, event, 'start');
  9207. // In touch device, trigger `mousemove`(`mouseover`) should
  9208. // be triggered, and must before `mousedown` triggered.
  9209. domHandlers.mousemove.call(this, event);
  9210. domHandlers.mousedown.call(this, event);
  9211. setTouchTimer(this);
  9212. },
  9213. /**
  9214. * Touch移动响应函数
  9215. * @inner
  9216. * @param {Event} event
  9217. */
  9218. touchmove: function (event) {
  9219. event = normalizeEvent(this.dom, event);
  9220. // Mark touch, which is useful in distinguish touch and
  9221. // mouse event in upper applicatoin.
  9222. event.zrByTouch = true;
  9223. this.handler.processGesture(this, event, 'change');
  9224. // Mouse move should always be triggered no matter whether
  9225. // there is gestrue event, because mouse move and pinch may
  9226. // be used at the same time.
  9227. domHandlers.mousemove.call(this, event);
  9228. setTouchTimer(this);
  9229. },
  9230. /**
  9231. * Touch结束响应函数
  9232. * @inner
  9233. * @param {Event} event
  9234. */
  9235. touchend: function (event) {
  9236. event = normalizeEvent(this.dom, event);
  9237. // Mark touch, which is useful in distinguish touch and
  9238. // mouse event in upper applicatoin.
  9239. event.zrByTouch = true;
  9240. this.handler.processGesture(this, event, 'end');
  9241. domHandlers.mouseup.call(this, event);
  9242. // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  9243. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  9244. // we can conveniently implement "hover style" in both PC and touch device just
  9245. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  9246. // to remove "hover style" on an element, without any additional code for
  9247. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  9248. // style" will remain for user view)
  9249. // click event should always be triggered no matter whether
  9250. // there is gestrue event. System click can not be prevented.
  9251. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  9252. domHandlers.click.call(this, event);
  9253. }
  9254. setTouchTimer(this);
  9255. },
  9256. pointerdown: function (event) {
  9257. domHandlers.mousedown.call(this, event);
  9258. // if (useMSGuesture(this, event)) {
  9259. // this._msGesture.addPointer(event.pointerId);
  9260. // }
  9261. },
  9262. pointermove: function (event) {
  9263. // FIXME
  9264. // pointermove is so sensitive that it always triggered when
  9265. // tap(click) on touch screen, which affect some judgement in
  9266. // upper application. So, we dont support mousemove on MS touch
  9267. // device yet.
  9268. if (!isPointerFromTouch(event)) {
  9269. domHandlers.mousemove.call(this, event);
  9270. }
  9271. },
  9272. pointerup: function (event) {
  9273. domHandlers.mouseup.call(this, event);
  9274. },
  9275. pointerout: function (event) {
  9276. // pointerout will be triggered when tap on touch screen
  9277. // (IE11+/Edge on MS Surface) after click event triggered,
  9278. // which is inconsistent with the mousout behavior we defined
  9279. // in touchend. So we unify them.
  9280. // (check domHandlers.touchend for detailed explanation)
  9281. if (!isPointerFromTouch(event)) {
  9282. domHandlers.mouseout.call(this, event);
  9283. }
  9284. }
  9285. };
  9286. function isPointerFromTouch(event) {
  9287. var pointerType = event.pointerType;
  9288. return pointerType === 'pen' || pointerType === 'touch';
  9289. }
  9290. // function useMSGuesture(handlerProxy, event) {
  9291. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  9292. // }
  9293. // Common handlers
  9294. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  9295. domHandlers[name] = function (event) {
  9296. event = normalizeEvent(this.dom, event);
  9297. this.trigger(name, event);
  9298. };
  9299. });
  9300. /**
  9301. * 为控制类实例初始化dom 事件处理函数
  9302. *
  9303. * @inner
  9304. * @param {module:zrender/Handler} instance 控制类实例
  9305. */
  9306. function initDomHandler(instance) {
  9307. each$1(touchHandlerNames, function (name) {
  9308. instance._handlers[name] = bind(domHandlers[name], instance);
  9309. });
  9310. each$1(pointerHandlerNames, function (name) {
  9311. instance._handlers[name] = bind(domHandlers[name], instance);
  9312. });
  9313. each$1(mouseHandlerNames, function (name) {
  9314. instance._handlers[name] = makeMouseHandler(domHandlers[name], instance);
  9315. });
  9316. function makeMouseHandler(fn, instance) {
  9317. return function () {
  9318. if (instance._touching) {
  9319. return;
  9320. }
  9321. return fn.apply(instance, arguments);
  9322. };
  9323. }
  9324. }
  9325. function HandlerDomProxy(dom) {
  9326. Eventful.call(this);
  9327. this.dom = dom;
  9328. /**
  9329. * @private
  9330. * @type {boolean}
  9331. */
  9332. this._touching = false;
  9333. /**
  9334. * @private
  9335. * @type {number}
  9336. */
  9337. this._touchTimer;
  9338. this._handlers = {};
  9339. initDomHandler(this);
  9340. if (env$1.pointerEventsSupported) { // Only IE11+/Edge
  9341. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  9342. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  9343. // at the same time.
  9344. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  9345. // screen, which do not occurs in pointer event.
  9346. // So we use pointer event to both detect touch gesture and mouse behavior.
  9347. mountHandlers(pointerHandlerNames, this);
  9348. // FIXME
  9349. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  9350. // which does not prevent defuault behavior occasionally (which may cause view port
  9351. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  9352. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  9353. // touch screen. And we only support click behavior on MS touch screen now.
  9354. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  9355. // We dont support touch on IE on win7.
  9356. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  9357. // if (typeof MSGesture === 'function') {
  9358. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  9359. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  9360. // }
  9361. }
  9362. else {
  9363. if (env$1.touchEventsSupported) {
  9364. mountHandlers(touchHandlerNames, this);
  9365. // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  9366. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  9367. }
  9368. // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  9369. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  9370. // mouse event can not be handle in those devices.
  9371. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  9372. // mouseevent after touch event triggered, see `setTouchTimer`.
  9373. mountHandlers(mouseHandlerNames, this);
  9374. }
  9375. function mountHandlers(handlerNames, instance) {
  9376. each$1(handlerNames, function (name) {
  9377. addEventListener(dom, eventNameFix(name), instance._handlers[name]);
  9378. }, instance);
  9379. }
  9380. }
  9381. var handlerDomProxyProto = HandlerDomProxy.prototype;
  9382. handlerDomProxyProto.dispose = function () {
  9383. var handlerNames = mouseHandlerNames.concat(touchHandlerNames);
  9384. for (var i = 0; i < handlerNames.length; i++) {
  9385. var name = handlerNames[i];
  9386. removeEventListener(this.dom, eventNameFix(name), this._handlers[name]);
  9387. }
  9388. };
  9389. handlerDomProxyProto.setCursor = function (cursorStyle) {
  9390. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  9391. };
  9392. mixin(HandlerDomProxy, Eventful);
  9393. /*!
  9394. * ZRender, a high performance 2d drawing library.
  9395. *
  9396. * Copyright (c) 2013, Baidu Inc.
  9397. * All rights reserved.
  9398. *
  9399. * LICENSE
  9400. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  9401. */
  9402. var useVML = !env$1.canvasSupported;
  9403. var painterCtors = {
  9404. canvas: Painter
  9405. };
  9406. var instances$1 = {}; // ZRender实例map索引
  9407. /**
  9408. * @type {string}
  9409. */
  9410. var version$1 = '4.0.7';
  9411. /**
  9412. * Initializing a zrender instance
  9413. * @param {HTMLElement} dom
  9414. * @param {Object} [opts]
  9415. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9416. * @param {number} [opts.devicePixelRatio]
  9417. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9418. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9419. * @return {module:zrender/ZRender}
  9420. */
  9421. function init$1(dom, opts) {
  9422. var zr = new ZRender(guid(), dom, opts);
  9423. instances$1[zr.id] = zr;
  9424. return zr;
  9425. }
  9426. /**
  9427. * Dispose zrender instance
  9428. * @param {module:zrender/ZRender} zr
  9429. */
  9430. function dispose$1(zr) {
  9431. if (zr) {
  9432. zr.dispose();
  9433. }
  9434. else {
  9435. for (var key in instances$1) {
  9436. if (instances$1.hasOwnProperty(key)) {
  9437. instances$1[key].dispose();
  9438. }
  9439. }
  9440. instances$1 = {};
  9441. }
  9442. return this;
  9443. }
  9444. /**
  9445. * Get zrender instance by id
  9446. * @param {string} id zrender instance id
  9447. * @return {module:zrender/ZRender}
  9448. */
  9449. function getInstance(id) {
  9450. return instances$1[id];
  9451. }
  9452. function registerPainter(name, Ctor) {
  9453. painterCtors[name] = Ctor;
  9454. }
  9455. function delInstance(id) {
  9456. delete instances$1[id];
  9457. }
  9458. /**
  9459. * @module zrender/ZRender
  9460. */
  9461. /**
  9462. * @constructor
  9463. * @alias module:zrender/ZRender
  9464. * @param {string} id
  9465. * @param {HTMLElement} dom
  9466. * @param {Object} opts
  9467. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9468. * @param {number} [opts.devicePixelRatio]
  9469. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  9470. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  9471. */
  9472. var ZRender = function (id, dom, opts) {
  9473. opts = opts || {};
  9474. /**
  9475. * @type {HTMLDomElement}
  9476. */
  9477. this.dom = dom;
  9478. /**
  9479. * @type {string}
  9480. */
  9481. this.id = id;
  9482. var self = this;
  9483. var storage = new Storage();
  9484. var rendererType = opts.renderer;
  9485. // TODO WebGL
  9486. if (useVML) {
  9487. if (!painterCtors.vml) {
  9488. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  9489. }
  9490. rendererType = 'vml';
  9491. }
  9492. else if (!rendererType || !painterCtors[rendererType]) {
  9493. rendererType = 'canvas';
  9494. }
  9495. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  9496. this.storage = storage;
  9497. this.painter = painter;
  9498. var handerProxy = (!env$1.node && !env$1.worker) ? new HandlerDomProxy(painter.getViewportRoot()) : null;
  9499. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  9500. /**
  9501. * @type {module:zrender/animation/Animation}
  9502. */
  9503. this.animation = new Animation({
  9504. stage: {
  9505. update: bind(this.flush, this)
  9506. }
  9507. });
  9508. this.animation.start();
  9509. /**
  9510. * @type {boolean}
  9511. * @private
  9512. */
  9513. this._needsRefresh;
  9514. // 修改 storage.delFromStorage, 每次删除元素之前删除动画
  9515. // FIXME 有点ugly
  9516. var oldDelFromStorage = storage.delFromStorage;
  9517. var oldAddToStorage = storage.addToStorage;
  9518. storage.delFromStorage = function (el) {
  9519. oldDelFromStorage.call(storage, el);
  9520. el && el.removeSelfFromZr(self);
  9521. };
  9522. storage.addToStorage = function (el) {
  9523. oldAddToStorage.call(storage, el);
  9524. el.addSelfToZr(self);
  9525. };
  9526. };
  9527. ZRender.prototype = {
  9528. constructor: ZRender,
  9529. /**
  9530. * 获取实例唯一标识
  9531. * @return {string}
  9532. */
  9533. getId: function () {
  9534. return this.id;
  9535. },
  9536. /**
  9537. * 添加元素
  9538. * @param {module:zrender/Element} el
  9539. */
  9540. add: function (el) {
  9541. this.storage.addRoot(el);
  9542. this._needsRefresh = true;
  9543. },
  9544. /**
  9545. * 删除元素
  9546. * @param {module:zrender/Element} el
  9547. */
  9548. remove: function (el) {
  9549. this.storage.delRoot(el);
  9550. this._needsRefresh = true;
  9551. },
  9552. /**
  9553. * Change configuration of layer
  9554. * @param {string} zLevel
  9555. * @param {Object} config
  9556. * @param {string} [config.clearColor=0] Clear color
  9557. * @param {string} [config.motionBlur=false] If enable motion blur
  9558. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  9559. */
  9560. configLayer: function (zLevel, config) {
  9561. if (this.painter.configLayer) {
  9562. this.painter.configLayer(zLevel, config);
  9563. }
  9564. this._needsRefresh = true;
  9565. },
  9566. /**
  9567. * Set background color
  9568. * @param {string} backgroundColor
  9569. */
  9570. setBackgroundColor: function (backgroundColor) {
  9571. if (this.painter.setBackgroundColor) {
  9572. this.painter.setBackgroundColor(backgroundColor);
  9573. }
  9574. this._needsRefresh = true;
  9575. },
  9576. /**
  9577. * Repaint the canvas immediately
  9578. */
  9579. refreshImmediately: function () {
  9580. // var start = new Date();
  9581. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  9582. // Or it will cause zrender refreshes again and again.
  9583. this._needsRefresh = false;
  9584. this.painter.refresh();
  9585. /**
  9586. * Avoid trigger zr.refresh in Element#beforeUpdate hook
  9587. */
  9588. this._needsRefresh = false;
  9589. // var end = new Date();
  9590. // var log = document.getElementById('log');
  9591. // if (log) {
  9592. // log.innerHTML = log.innerHTML + '<br>' + (end - start);
  9593. // }
  9594. },
  9595. /**
  9596. * Mark and repaint the canvas in the next frame of browser
  9597. */
  9598. refresh: function () {
  9599. this._needsRefresh = true;
  9600. },
  9601. /**
  9602. * Perform all refresh
  9603. */
  9604. flush: function () {
  9605. var triggerRendered;
  9606. if (this._needsRefresh) {
  9607. triggerRendered = true;
  9608. this.refreshImmediately();
  9609. }
  9610. if (this._needsRefreshHover) {
  9611. triggerRendered = true;
  9612. this.refreshHoverImmediately();
  9613. }
  9614. triggerRendered && this.trigger('rendered');
  9615. },
  9616. /**
  9617. * Add element to hover layer
  9618. * @param {module:zrender/Element} el
  9619. * @param {Object} style
  9620. */
  9621. addHover: function (el, style) {
  9622. if (this.painter.addHover) {
  9623. var elMirror = this.painter.addHover(el, style);
  9624. this.refreshHover();
  9625. return elMirror;
  9626. }
  9627. },
  9628. /**
  9629. * Add element from hover layer
  9630. * @param {module:zrender/Element} el
  9631. */
  9632. removeHover: function (el) {
  9633. if (this.painter.removeHover) {
  9634. this.painter.removeHover(el);
  9635. this.refreshHover();
  9636. }
  9637. },
  9638. /**
  9639. * Clear all hover elements in hover layer
  9640. * @param {module:zrender/Element} el
  9641. */
  9642. clearHover: function () {
  9643. if (this.painter.clearHover) {
  9644. this.painter.clearHover();
  9645. this.refreshHover();
  9646. }
  9647. },
  9648. /**
  9649. * Refresh hover in next frame
  9650. */
  9651. refreshHover: function () {
  9652. this._needsRefreshHover = true;
  9653. },
  9654. /**
  9655. * Refresh hover immediately
  9656. */
  9657. refreshHoverImmediately: function () {
  9658. this._needsRefreshHover = false;
  9659. this.painter.refreshHover && this.painter.refreshHover();
  9660. },
  9661. /**
  9662. * Resize the canvas.
  9663. * Should be invoked when container size is changed
  9664. * @param {Object} [opts]
  9665. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9666. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9667. */
  9668. resize: function (opts) {
  9669. opts = opts || {};
  9670. this.painter.resize(opts.width, opts.height);
  9671. this.handler.resize();
  9672. },
  9673. /**
  9674. * Stop and clear all animation immediately
  9675. */
  9676. clearAnimation: function () {
  9677. this.animation.clear();
  9678. },
  9679. /**
  9680. * Get container width
  9681. */
  9682. getWidth: function () {
  9683. return this.painter.getWidth();
  9684. },
  9685. /**
  9686. * Get container height
  9687. */
  9688. getHeight: function () {
  9689. return this.painter.getHeight();
  9690. },
  9691. /**
  9692. * Export the canvas as Base64 URL
  9693. * @param {string} type
  9694. * @param {string} [backgroundColor='#fff']
  9695. * @return {string} Base64 URL
  9696. */
  9697. // toDataURL: function(type, backgroundColor) {
  9698. // return this.painter.getRenderedCanvas({
  9699. // backgroundColor: backgroundColor
  9700. // }).toDataURL(type);
  9701. // },
  9702. /**
  9703. * Converting a path to image.
  9704. * It has much better performance of drawing image rather than drawing a vector path.
  9705. * @param {module:zrender/graphic/Path} e
  9706. * @param {number} width
  9707. * @param {number} height
  9708. */
  9709. pathToImage: function (e, dpr) {
  9710. return this.painter.pathToImage(e, dpr);
  9711. },
  9712. /**
  9713. * Set default cursor
  9714. * @param {string} [cursorStyle='default'] 例如 crosshair
  9715. */
  9716. setCursorStyle: function (cursorStyle) {
  9717. this.handler.setCursorStyle(cursorStyle);
  9718. },
  9719. /**
  9720. * Find hovered element
  9721. * @param {number} x
  9722. * @param {number} y
  9723. * @return {Object} {target, topTarget}
  9724. */
  9725. findHover: function (x, y) {
  9726. return this.handler.findHover(x, y);
  9727. },
  9728. /**
  9729. * Bind event
  9730. *
  9731. * @param {string} eventName Event name
  9732. * @param {Function} eventHandler Handler function
  9733. * @param {Object} [context] Context object
  9734. */
  9735. on: function (eventName, eventHandler, context) {
  9736. this.handler.on(eventName, eventHandler, context);
  9737. },
  9738. /**
  9739. * Unbind event
  9740. * @param {string} eventName Event name
  9741. * @param {Function} [eventHandler] Handler function
  9742. */
  9743. off: function (eventName, eventHandler) {
  9744. this.handler.off(eventName, eventHandler);
  9745. },
  9746. /**
  9747. * Trigger event manually
  9748. *
  9749. * @param {string} eventName Event name
  9750. * @param {event=} event Event object
  9751. */
  9752. trigger: function (eventName, event) {
  9753. this.handler.trigger(eventName, event);
  9754. },
  9755. /**
  9756. * Clear all objects and the canvas.
  9757. */
  9758. clear: function () {
  9759. this.storage.delRoot();
  9760. this.painter.clear();
  9761. },
  9762. /**
  9763. * Dispose self.
  9764. */
  9765. dispose: function () {
  9766. this.animation.stop();
  9767. this.clear();
  9768. this.storage.dispose();
  9769. this.painter.dispose();
  9770. this.handler.dispose();
  9771. this.animation =
  9772. this.storage =
  9773. this.painter =
  9774. this.handler = null;
  9775. delInstance(this.id);
  9776. }
  9777. };
  9778. var zrender = (Object.freeze || Object)({
  9779. version: version$1,
  9780. init: init$1,
  9781. dispose: dispose$1,
  9782. getInstance: getInstance,
  9783. registerPainter: registerPainter
  9784. });
  9785. /*
  9786. * Licensed to the Apache Software Foundation (ASF) under one
  9787. * or more contributor license agreements. See the NOTICE file
  9788. * distributed with this work for additional information
  9789. * regarding copyright ownership. The ASF licenses this file
  9790. * to you under the Apache License, Version 2.0 (the
  9791. * "License"); you may not use this file except in compliance
  9792. * with the License. You may obtain a copy of the License at
  9793. *
  9794. * http://www.apache.org/licenses/LICENSE-2.0
  9795. *
  9796. * Unless required by applicable law or agreed to in writing,
  9797. * software distributed under the License is distributed on an
  9798. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  9799. * KIND, either express or implied. See the License for the
  9800. * specific language governing permissions and limitations
  9801. * under the License.
  9802. */
  9803. var each$2 = each$1;
  9804. var isObject$2 = isObject$1;
  9805. var isArray$1 = isArray;
  9806. /**
  9807. * Make the name displayable. But we should
  9808. * make sure it is not duplicated with user
  9809. * specified name, so use '\0';
  9810. */
  9811. var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
  9812. /**
  9813. * If value is not array, then translate it to array.
  9814. * @param {*} value
  9815. * @return {Array} [value] or value
  9816. */
  9817. function normalizeToArray(value) {
  9818. return value instanceof Array
  9819. ? value
  9820. : value == null
  9821. ? []
  9822. : [value];
  9823. }
  9824. /**
  9825. * Sync default option between normal and emphasis like `position` and `show`
  9826. * In case some one will write code like
  9827. * label: {
  9828. * show: false,
  9829. * position: 'outside',
  9830. * fontSize: 18
  9831. * },
  9832. * emphasis: {
  9833. * label: { show: true }
  9834. * }
  9835. * @param {Object} opt
  9836. * @param {string} key
  9837. * @param {Array.<string>} subOpts
  9838. */
  9839. function defaultEmphasis(opt, key, subOpts) {
  9840. // Caution: performance sensitive.
  9841. if (opt) {
  9842. opt[key] = opt[key] || {};
  9843. opt.emphasis = opt.emphasis || {};
  9844. opt.emphasis[key] = opt.emphasis[key] || {};
  9845. // Default emphasis option from normal
  9846. for (var i = 0, len = subOpts.length; i < len; i++) {
  9847. var subOptName = subOpts[i];
  9848. if (!opt.emphasis[key].hasOwnProperty(subOptName)
  9849. && opt[key].hasOwnProperty(subOptName)
  9850. ) {
  9851. opt.emphasis[key][subOptName] = opt[key][subOptName];
  9852. }
  9853. }
  9854. }
  9855. }
  9856. var TEXT_STYLE_OPTIONS = [
  9857. 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  9858. 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth',
  9859. 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline',
  9860. 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY',
  9861. 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY',
  9862. 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'
  9863. ];
  9864. // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  9865. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  9866. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  9867. // // FIXME: deprecated, check and remove it.
  9868. // 'textStyle'
  9869. // ]);
  9870. /**
  9871. * The method do not ensure performance.
  9872. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  9873. * This helper method retieves value from data.
  9874. * @param {string|number|Date|Array|Object} dataItem
  9875. * @return {number|string|Date|Array.<number|string|Date>}
  9876. */
  9877. function getDataItemValue(dataItem) {
  9878. return (isObject$2(dataItem) && !isArray$1(dataItem) && !(dataItem instanceof Date))
  9879. ? dataItem.value : dataItem;
  9880. }
  9881. /**
  9882. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  9883. * This helper method determine if dataItem has extra option besides value
  9884. * @param {string|number|Date|Array|Object} dataItem
  9885. */
  9886. function isDataItemOption(dataItem) {
  9887. return isObject$2(dataItem)
  9888. && !(dataItem instanceof Array);
  9889. // // markLine data can be array
  9890. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  9891. }
  9892. /**
  9893. * Mapping to exists for merge.
  9894. *
  9895. * @public
  9896. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  9897. * @param {Object|Array.<Object>} newCptOptions
  9898. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  9899. * index of which is the same as exists.
  9900. */
  9901. function mappingToExists(exists, newCptOptions) {
  9902. // Mapping by the order by original option (but not order of
  9903. // new option) in merge mode. Because we should ensure
  9904. // some specified index (like xAxisIndex) is consistent with
  9905. // original option, which is easy to understand, espatially in
  9906. // media query. And in most case, merge option is used to
  9907. // update partial option but not be expected to change order.
  9908. newCptOptions = (newCptOptions || []).slice();
  9909. var result = map(exists || [], function (obj, index) {
  9910. return {exist: obj};
  9911. });
  9912. // Mapping by id or name if specified.
  9913. each$2(newCptOptions, function (cptOption, index) {
  9914. if (!isObject$2(cptOption)) {
  9915. return;
  9916. }
  9917. // id has highest priority.
  9918. for (var i = 0; i < result.length; i++) {
  9919. if (!result[i].option // Consider name: two map to one.
  9920. && cptOption.id != null
  9921. && result[i].exist.id === cptOption.id + ''
  9922. ) {
  9923. result[i].option = cptOption;
  9924. newCptOptions[index] = null;
  9925. return;
  9926. }
  9927. }
  9928. for (var i = 0; i < result.length; i++) {
  9929. var exist = result[i].exist;
  9930. if (!result[i].option // Consider name: two map to one.
  9931. // Can not match when both ids exist but different.
  9932. && (exist.id == null || cptOption.id == null)
  9933. && cptOption.name != null
  9934. && !isIdInner(cptOption)
  9935. && !isIdInner(exist)
  9936. && exist.name === cptOption.name + ''
  9937. ) {
  9938. result[i].option = cptOption;
  9939. newCptOptions[index] = null;
  9940. return;
  9941. }
  9942. }
  9943. });
  9944. // Otherwise mapping by index.
  9945. each$2(newCptOptions, function (cptOption, index) {
  9946. if (!isObject$2(cptOption)) {
  9947. return;
  9948. }
  9949. var i = 0;
  9950. for (; i < result.length; i++) {
  9951. var exist = result[i].exist;
  9952. if (!result[i].option
  9953. // Existing model that already has id should be able to
  9954. // mapped to (because after mapping performed model may
  9955. // be assigned with a id, whish should not affect next
  9956. // mapping), except those has inner id.
  9957. && !isIdInner(exist)
  9958. // Caution:
  9959. // Do not overwrite id. But name can be overwritten,
  9960. // because axis use name as 'show label text'.
  9961. // 'exist' always has id and name and we dont
  9962. // need to check it.
  9963. && cptOption.id == null
  9964. ) {
  9965. result[i].option = cptOption;
  9966. break;
  9967. }
  9968. }
  9969. if (i >= result.length) {
  9970. result.push({option: cptOption});
  9971. }
  9972. });
  9973. return result;
  9974. }
  9975. /**
  9976. * Make id and name for mapping result (result of mappingToExists)
  9977. * into `keyInfo` field.
  9978. *
  9979. * @public
  9980. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  9981. * which order is the same as exists.
  9982. * @return {Array.<Object>} The input.
  9983. */
  9984. function makeIdAndName(mapResult) {
  9985. // We use this id to hash component models and view instances
  9986. // in echarts. id can be specified by user, or auto generated.
  9987. // The id generation rule ensures new view instance are able
  9988. // to mapped to old instance when setOption are called in
  9989. // no-merge mode. So we generate model id by name and plus
  9990. // type in view id.
  9991. // name can be duplicated among components, which is convenient
  9992. // to specify multi components (like series) by one name.
  9993. // Ensure that each id is distinct.
  9994. var idMap = createHashMap();
  9995. each$2(mapResult, function (item, index) {
  9996. var existCpt = item.exist;
  9997. existCpt && idMap.set(existCpt.id, item);
  9998. });
  9999. each$2(mapResult, function (item, index) {
  10000. var opt = item.option;
  10001. assert$1(
  10002. !opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item,
  10003. 'id duplicates: ' + (opt && opt.id)
  10004. );
  10005. opt && opt.id != null && idMap.set(opt.id, item);
  10006. !item.keyInfo && (item.keyInfo = {});
  10007. });
  10008. // Make name and id.
  10009. each$2(mapResult, function (item, index) {
  10010. var existCpt = item.exist;
  10011. var opt = item.option;
  10012. var keyInfo = item.keyInfo;
  10013. if (!isObject$2(opt)) {
  10014. return;
  10015. }
  10016. // name can be overwitten. Consider case: axis.name = '20km'.
  10017. // But id generated by name will not be changed, which affect
  10018. // only in that case: setOption with 'not merge mode' and view
  10019. // instance will be recreated, which can be accepted.
  10020. keyInfo.name = opt.name != null
  10021. ? opt.name + ''
  10022. : existCpt
  10023. ? existCpt.name
  10024. // Avoid diffferent series has the same name,
  10025. // because name may be used like in color pallet.
  10026. : DUMMY_COMPONENT_NAME_PREFIX + index;
  10027. if (existCpt) {
  10028. keyInfo.id = existCpt.id;
  10029. }
  10030. else if (opt.id != null) {
  10031. keyInfo.id = opt.id + '';
  10032. }
  10033. else {
  10034. // Consider this situatoin:
  10035. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  10036. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  10037. // Series with the same name between optionA and optionB
  10038. // should be mapped.
  10039. var idNum = 0;
  10040. do {
  10041. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  10042. }
  10043. while (idMap.get(keyInfo.id));
  10044. }
  10045. idMap.set(keyInfo.id, item);
  10046. });
  10047. }
  10048. function isNameSpecified(componentModel) {
  10049. var name = componentModel.name;
  10050. // Is specified when `indexOf` get -1 or > 0.
  10051. return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
  10052. }
  10053. /**
  10054. * @public
  10055. * @param {Object} cptOption
  10056. * @return {boolean}
  10057. */
  10058. function isIdInner(cptOption) {
  10059. return isObject$2(cptOption)
  10060. && cptOption.id
  10061. && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  10062. }
  10063. /**
  10064. * A helper for removing duplicate items between batchA and batchB,
  10065. * and in themselves, and categorize by series.
  10066. *
  10067. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10068. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10069. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  10070. */
  10071. function compressBatches(batchA, batchB) {
  10072. var mapA = {};
  10073. var mapB = {};
  10074. makeMap(batchA || [], mapA);
  10075. makeMap(batchB || [], mapB, mapA);
  10076. return [mapToArray(mapA), mapToArray(mapB)];
  10077. function makeMap(sourceBatch, map$$1, otherMap) {
  10078. for (var i = 0, len = sourceBatch.length; i < len; i++) {
  10079. var seriesId = sourceBatch[i].seriesId;
  10080. var dataIndices = normalizeToArray(sourceBatch[i].dataIndex);
  10081. var otherDataIndices = otherMap && otherMap[seriesId];
  10082. for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
  10083. var dataIndex = dataIndices[j];
  10084. if (otherDataIndices && otherDataIndices[dataIndex]) {
  10085. otherDataIndices[dataIndex] = null;
  10086. }
  10087. else {
  10088. (map$$1[seriesId] || (map$$1[seriesId] = {}))[dataIndex] = 1;
  10089. }
  10090. }
  10091. }
  10092. }
  10093. function mapToArray(map$$1, isData) {
  10094. var result = [];
  10095. for (var i in map$$1) {
  10096. if (map$$1.hasOwnProperty(i) && map$$1[i] != null) {
  10097. if (isData) {
  10098. result.push(+i);
  10099. }
  10100. else {
  10101. var dataIndices = mapToArray(map$$1[i], true);
  10102. dataIndices.length && result.push({seriesId: i, dataIndex: dataIndices});
  10103. }
  10104. }
  10105. }
  10106. return result;
  10107. }
  10108. }
  10109. /**
  10110. * @param {module:echarts/data/List} data
  10111. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  10112. * each of which can be Array or primary type.
  10113. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  10114. */
  10115. function queryDataIndex(data, payload) {
  10116. if (payload.dataIndexInside != null) {
  10117. return payload.dataIndexInside;
  10118. }
  10119. else if (payload.dataIndex != null) {
  10120. return isArray(payload.dataIndex)
  10121. ? map(payload.dataIndex, function (value) {
  10122. return data.indexOfRawIndex(value);
  10123. })
  10124. : data.indexOfRawIndex(payload.dataIndex);
  10125. }
  10126. else if (payload.name != null) {
  10127. return isArray(payload.name)
  10128. ? map(payload.name, function (value) {
  10129. return data.indexOfName(value);
  10130. })
  10131. : data.indexOfName(payload.name);
  10132. }
  10133. }
  10134. /**
  10135. * Enable property storage to any host object.
  10136. * Notice: Serialization is not supported.
  10137. *
  10138. * For example:
  10139. * var inner = zrUitl.makeInner();
  10140. *
  10141. * function some1(hostObj) {
  10142. * inner(hostObj).someProperty = 1212;
  10143. * ...
  10144. * }
  10145. * function some2() {
  10146. * var fields = inner(this);
  10147. * fields.someProperty1 = 1212;
  10148. * fields.someProperty2 = 'xx';
  10149. * ...
  10150. * }
  10151. *
  10152. * @return {Function}
  10153. */
  10154. function makeInner() {
  10155. // Consider different scope by es module import.
  10156. var key = '__\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);
  10157. return function (hostObj) {
  10158. return hostObj[key] || (hostObj[key] = {});
  10159. };
  10160. }
  10161. var innerUniqueIndex = 0;
  10162. /**
  10163. * @param {module:echarts/model/Global} ecModel
  10164. * @param {string|Object} finder
  10165. * If string, e.g., 'geo', means {geoIndex: 0}.
  10166. * If Object, could contain some of these properties below:
  10167. * {
  10168. * seriesIndex, seriesId, seriesName,
  10169. * geoIndex, geoId, geoName,
  10170. * bmapIndex, bmapId, bmapName,
  10171. * xAxisIndex, xAxisId, xAxisName,
  10172. * yAxisIndex, yAxisId, yAxisName,
  10173. * gridIndex, gridId, gridName,
  10174. * ... (can be extended)
  10175. * }
  10176. * Each properties can be number|string|Array.<number>|Array.<string>
  10177. * For example, a finder could be
  10178. * {
  10179. * seriesIndex: 3,
  10180. * geoId: ['aa', 'cc'],
  10181. * gridName: ['xx', 'rr']
  10182. * }
  10183. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  10184. * If nothing or null/undefined specified, return nothing.
  10185. * @param {Object} [opt]
  10186. * @param {string} [opt.defaultMainType]
  10187. * @param {Array.<string>} [opt.includeMainTypes]
  10188. * @return {Object} result like:
  10189. * {
  10190. * seriesModels: [seriesModel1, seriesModel2],
  10191. * seriesModel: seriesModel1, // The first model
  10192. * geoModels: [geoModel1, geoModel2],
  10193. * geoModel: geoModel1, // The first model
  10194. * ...
  10195. * }
  10196. */
  10197. function parseFinder(ecModel, finder, opt) {
  10198. if (isString(finder)) {
  10199. var obj = {};
  10200. obj[finder + 'Index'] = 0;
  10201. finder = obj;
  10202. }
  10203. var defaultMainType = opt && opt.defaultMainType;
  10204. if (defaultMainType
  10205. && !has(finder, defaultMainType + 'Index')
  10206. && !has(finder, defaultMainType + 'Id')
  10207. && !has(finder, defaultMainType + 'Name')
  10208. ) {
  10209. finder[defaultMainType + 'Index'] = 0;
  10210. }
  10211. var result = {};
  10212. each$2(finder, function (value, key) {
  10213. var value = finder[key];
  10214. // Exclude 'dataIndex' and other illgal keys.
  10215. if (key === 'dataIndex' || key === 'dataIndexInside') {
  10216. result[key] = value;
  10217. return;
  10218. }
  10219. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  10220. var mainType = parsedKey[1];
  10221. var queryType = (parsedKey[2] || '').toLowerCase();
  10222. if (!mainType
  10223. || !queryType
  10224. || value == null
  10225. || (queryType === 'index' && value === 'none')
  10226. || (opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0)
  10227. ) {
  10228. return;
  10229. }
  10230. var queryParam = {mainType: mainType};
  10231. if (queryType !== 'index' || value !== 'all') {
  10232. queryParam[queryType] = value;
  10233. }
  10234. var models = ecModel.queryComponents(queryParam);
  10235. result[mainType + 'Models'] = models;
  10236. result[mainType + 'Model'] = models[0];
  10237. });
  10238. return result;
  10239. }
  10240. function has(obj, prop) {
  10241. return obj && obj.hasOwnProperty(prop);
  10242. }
  10243. function setAttribute(dom, key, value) {
  10244. dom.setAttribute
  10245. ? dom.setAttribute(key, value)
  10246. : (dom[key] = value);
  10247. }
  10248. function getAttribute(dom, key) {
  10249. return dom.getAttribute
  10250. ? dom.getAttribute(key)
  10251. : dom[key];
  10252. }
  10253. function getTooltipRenderMode(renderModeOption) {
  10254. if (renderModeOption === 'auto') {
  10255. // Using html when `document` exists, use richText otherwise
  10256. return env$1.domSupported ? 'html' : 'richText';
  10257. }
  10258. else {
  10259. return renderModeOption || 'html';
  10260. }
  10261. }
  10262. /**
  10263. * Group a list by key.
  10264. *
  10265. * @param {Array} array
  10266. * @param {Function} getKey
  10267. * param {*} Array item
  10268. * return {string} key
  10269. * @return {Object} Result
  10270. * {Array}: keys,
  10271. * {module:zrender/core/util/HashMap} buckets: {key -> Array}
  10272. */
  10273. function groupData(array, getKey) {
  10274. var buckets = createHashMap();
  10275. var keys = [];
  10276. each$1(array, function (item) {
  10277. var key = getKey(item);
  10278. (buckets.get(key)
  10279. || (keys.push(key), buckets.set(key, []))
  10280. ).push(item);
  10281. });
  10282. return {keys: keys, buckets: buckets};
  10283. }
  10284. /*
  10285. * Licensed to the Apache Software Foundation (ASF) under one
  10286. * or more contributor license agreements. See the NOTICE file
  10287. * distributed with this work for additional information
  10288. * regarding copyright ownership. The ASF licenses this file
  10289. * to you under the Apache License, Version 2.0 (the
  10290. * "License"); you may not use this file except in compliance
  10291. * with the License. You may obtain a copy of the License at
  10292. *
  10293. * http://www.apache.org/licenses/LICENSE-2.0
  10294. *
  10295. * Unless required by applicable law or agreed to in writing,
  10296. * software distributed under the License is distributed on an
  10297. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10298. * KIND, either express or implied. See the License for the
  10299. * specific language governing permissions and limitations
  10300. * under the License.
  10301. */
  10302. var TYPE_DELIMITER = '.';
  10303. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  10304. /**
  10305. * Notice, parseClassType('') should returns {main: '', sub: ''}
  10306. * @public
  10307. */
  10308. function parseClassType$1(componentType) {
  10309. var ret = {main: '', sub: ''};
  10310. if (componentType) {
  10311. componentType = componentType.split(TYPE_DELIMITER);
  10312. ret.main = componentType[0] || '';
  10313. ret.sub = componentType[1] || '';
  10314. }
  10315. return ret;
  10316. }
  10317. /**
  10318. * @public
  10319. */
  10320. function checkClassType(componentType) {
  10321. assert$1(
  10322. /^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType),
  10323. 'componentType "' + componentType + '" illegal'
  10324. );
  10325. }
  10326. /**
  10327. * @public
  10328. */
  10329. function enableClassExtend(RootClass, mandatoryMethods) {
  10330. RootClass.$constructor = RootClass;
  10331. RootClass.extend = function (proto) {
  10332. if (__DEV__) {
  10333. each$1(mandatoryMethods, function (method) {
  10334. if (!proto[method]) {
  10335. console.warn(
  10336. 'Method `' + method + '` should be implemented'
  10337. + (proto.type ? ' in ' + proto.type : '') + '.'
  10338. );
  10339. }
  10340. });
  10341. }
  10342. var superClass = this;
  10343. var ExtendedClass = function () {
  10344. if (!proto.$constructor) {
  10345. superClass.apply(this, arguments);
  10346. }
  10347. else {
  10348. proto.$constructor.apply(this, arguments);
  10349. }
  10350. };
  10351. extend(ExtendedClass.prototype, proto);
  10352. ExtendedClass.extend = this.extend;
  10353. ExtendedClass.superCall = superCall;
  10354. ExtendedClass.superApply = superApply;
  10355. inherits(ExtendedClass, this);
  10356. ExtendedClass.superClass = superClass;
  10357. return ExtendedClass;
  10358. };
  10359. }
  10360. var classBase = 0;
  10361. /**
  10362. * Can not use instanceof, consider different scope by
  10363. * cross domain or es module import in ec extensions.
  10364. * Mount a method "isInstance()" to Clz.
  10365. */
  10366. function enableClassCheck(Clz) {
  10367. var classAttr = ['__\0is_clz', classBase++, Math.random().toFixed(3)].join('_');
  10368. Clz.prototype[classAttr] = true;
  10369. if (__DEV__) {
  10370. assert$1(!Clz.isInstance, 'The method "is" can not be defined.');
  10371. }
  10372. Clz.isInstance = function (obj) {
  10373. return !!(obj && obj[classAttr]);
  10374. };
  10375. }
  10376. // superCall should have class info, which can not be fetch from 'this'.
  10377. // Consider this case:
  10378. // class A has method f,
  10379. // class B inherits class A, overrides method f, f call superApply('f'),
  10380. // class C inherits class B, do not overrides method f,
  10381. // then when method of class C is called, dead loop occured.
  10382. function superCall(context, methodName) {
  10383. var args = slice(arguments, 2);
  10384. return this.superClass.prototype[methodName].apply(context, args);
  10385. }
  10386. function superApply(context, methodName, args) {
  10387. return this.superClass.prototype[methodName].apply(context, args);
  10388. }
  10389. /**
  10390. * @param {Object} entity
  10391. * @param {Object} options
  10392. * @param {boolean} [options.registerWhenExtend]
  10393. * @public
  10394. */
  10395. function enableClassManagement(entity, options) {
  10396. options = options || {};
  10397. /**
  10398. * Component model classes
  10399. * key: componentType,
  10400. * value:
  10401. * componentClass, when componentType is 'xxx'
  10402. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  10403. * @type {Object}
  10404. */
  10405. var storage = {};
  10406. entity.registerClass = function (Clazz, componentType) {
  10407. if (componentType) {
  10408. checkClassType(componentType);
  10409. componentType = parseClassType$1(componentType);
  10410. if (!componentType.sub) {
  10411. if (__DEV__) {
  10412. if (storage[componentType.main]) {
  10413. console.warn(componentType.main + ' exists.');
  10414. }
  10415. }
  10416. storage[componentType.main] = Clazz;
  10417. }
  10418. else if (componentType.sub !== IS_CONTAINER) {
  10419. var container = makeContainer(componentType);
  10420. container[componentType.sub] = Clazz;
  10421. }
  10422. }
  10423. return Clazz;
  10424. };
  10425. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  10426. var Clazz = storage[componentMainType];
  10427. if (Clazz && Clazz[IS_CONTAINER]) {
  10428. Clazz = subType ? Clazz[subType] : null;
  10429. }
  10430. if (throwWhenNotFound && !Clazz) {
  10431. throw new Error(
  10432. !subType
  10433. ? componentMainType + '.' + 'type should be specified.'
  10434. : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'
  10435. );
  10436. }
  10437. return Clazz;
  10438. };
  10439. entity.getClassesByMainType = function (componentType) {
  10440. componentType = parseClassType$1(componentType);
  10441. var result = [];
  10442. var obj = storage[componentType.main];
  10443. if (obj && obj[IS_CONTAINER]) {
  10444. each$1(obj, function (o, type) {
  10445. type !== IS_CONTAINER && result.push(o);
  10446. });
  10447. }
  10448. else {
  10449. result.push(obj);
  10450. }
  10451. return result;
  10452. };
  10453. entity.hasClass = function (componentType) {
  10454. // Just consider componentType.main.
  10455. componentType = parseClassType$1(componentType);
  10456. return !!storage[componentType.main];
  10457. };
  10458. /**
  10459. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  10460. */
  10461. entity.getAllClassMainTypes = function () {
  10462. var types = [];
  10463. each$1(storage, function (obj, type) {
  10464. types.push(type);
  10465. });
  10466. return types;
  10467. };
  10468. /**
  10469. * If a main type is container and has sub types
  10470. * @param {string} mainType
  10471. * @return {boolean}
  10472. */
  10473. entity.hasSubTypes = function (componentType) {
  10474. componentType = parseClassType$1(componentType);
  10475. var obj = storage[componentType.main];
  10476. return obj && obj[IS_CONTAINER];
  10477. };
  10478. entity.parseClassType = parseClassType$1;
  10479. function makeContainer(componentType) {
  10480. var container = storage[componentType.main];
  10481. if (!container || !container[IS_CONTAINER]) {
  10482. container = storage[componentType.main] = {};
  10483. container[IS_CONTAINER] = true;
  10484. }
  10485. return container;
  10486. }
  10487. if (options.registerWhenExtend) {
  10488. var originalExtend = entity.extend;
  10489. if (originalExtend) {
  10490. entity.extend = function (proto) {
  10491. var ExtendedClass = originalExtend.call(this, proto);
  10492. return entity.registerClass(ExtendedClass, proto.type);
  10493. };
  10494. }
  10495. }
  10496. return entity;
  10497. }
  10498. /**
  10499. * @param {string|Array.<string>} properties
  10500. */
  10501. /*
  10502. * Licensed to the Apache Software Foundation (ASF) under one
  10503. * or more contributor license agreements. See the NOTICE file
  10504. * distributed with this work for additional information
  10505. * regarding copyright ownership. The ASF licenses this file
  10506. * to you under the Apache License, Version 2.0 (the
  10507. * "License"); you may not use this file except in compliance
  10508. * with the License. You may obtain a copy of the License at
  10509. *
  10510. * http://www.apache.org/licenses/LICENSE-2.0
  10511. *
  10512. * Unless required by applicable law or agreed to in writing,
  10513. * software distributed under the License is distributed on an
  10514. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10515. * KIND, either express or implied. See the License for the
  10516. * specific language governing permissions and limitations
  10517. * under the License.
  10518. */
  10519. // TODO Parse shadow style
  10520. // TODO Only shallow path support
  10521. var makeStyleMapper = function (properties) {
  10522. // Normalize
  10523. for (var i = 0; i < properties.length; i++) {
  10524. if (!properties[i][1]) {
  10525. properties[i][1] = properties[i][0];
  10526. }
  10527. }
  10528. return function (model, excludes, includes) {
  10529. var style = {};
  10530. for (var i = 0; i < properties.length; i++) {
  10531. var propName = properties[i][1];
  10532. if ((excludes && indexOf(excludes, propName) >= 0)
  10533. || (includes && indexOf(includes, propName) < 0)
  10534. ) {
  10535. continue;
  10536. }
  10537. var val = model.getShallow(propName);
  10538. if (val != null) {
  10539. style[properties[i][0]] = val;
  10540. }
  10541. }
  10542. return style;
  10543. };
  10544. };
  10545. /*
  10546. * Licensed to the Apache Software Foundation (ASF) under one
  10547. * or more contributor license agreements. See the NOTICE file
  10548. * distributed with this work for additional information
  10549. * regarding copyright ownership. The ASF licenses this file
  10550. * to you under the Apache License, Version 2.0 (the
  10551. * "License"); you may not use this file except in compliance
  10552. * with the License. You may obtain a copy of the License at
  10553. *
  10554. * http://www.apache.org/licenses/LICENSE-2.0
  10555. *
  10556. * Unless required by applicable law or agreed to in writing,
  10557. * software distributed under the License is distributed on an
  10558. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10559. * KIND, either express or implied. See the License for the
  10560. * specific language governing permissions and limitations
  10561. * under the License.
  10562. */
  10563. var getLineStyle = makeStyleMapper(
  10564. [
  10565. ['lineWidth', 'width'],
  10566. ['stroke', 'color'],
  10567. ['opacity'],
  10568. ['shadowBlur'],
  10569. ['shadowOffsetX'],
  10570. ['shadowOffsetY'],
  10571. ['shadowColor']
  10572. ]
  10573. );
  10574. var lineStyleMixin = {
  10575. getLineStyle: function (excludes) {
  10576. var style = getLineStyle(this, excludes);
  10577. var lineDash = this.getLineDash(style.lineWidth);
  10578. lineDash && (style.lineDash = lineDash);
  10579. return style;
  10580. },
  10581. getLineDash: function (lineWidth) {
  10582. if (lineWidth == null) {
  10583. lineWidth = 1;
  10584. }
  10585. var lineType = this.get('type');
  10586. var dotSize = Math.max(lineWidth, 2);
  10587. var dashSize = lineWidth * 4;
  10588. return (lineType === 'solid' || lineType == null) ? null
  10589. : (lineType === 'dashed' ? [dashSize, dashSize] : [dotSize, dotSize]);
  10590. }
  10591. };
  10592. /*
  10593. * Licensed to the Apache Software Foundation (ASF) under one
  10594. * or more contributor license agreements. See the NOTICE file
  10595. * distributed with this work for additional information
  10596. * regarding copyright ownership. The ASF licenses this file
  10597. * to you under the Apache License, Version 2.0 (the
  10598. * "License"); you may not use this file except in compliance
  10599. * with the License. You may obtain a copy of the License at
  10600. *
  10601. * http://www.apache.org/licenses/LICENSE-2.0
  10602. *
  10603. * Unless required by applicable law or agreed to in writing,
  10604. * software distributed under the License is distributed on an
  10605. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10606. * KIND, either express or implied. See the License for the
  10607. * specific language governing permissions and limitations
  10608. * under the License.
  10609. */
  10610. var getAreaStyle = makeStyleMapper(
  10611. [
  10612. ['fill', 'color'],
  10613. ['shadowBlur'],
  10614. ['shadowOffsetX'],
  10615. ['shadowOffsetY'],
  10616. ['opacity'],
  10617. ['shadowColor']
  10618. ]
  10619. );
  10620. var areaStyleMixin = {
  10621. getAreaStyle: function (excludes, includes) {
  10622. return getAreaStyle(this, excludes, includes);
  10623. }
  10624. };
  10625. /**
  10626. * 曲线辅助模块
  10627. * @module zrender/core/curve
  10628. * @author pissang(https://www.github.com/pissang)
  10629. */
  10630. var mathPow = Math.pow;
  10631. var mathSqrt$2 = Math.sqrt;
  10632. var EPSILON$1 = 1e-8;
  10633. var EPSILON_NUMERIC = 1e-4;
  10634. var THREE_SQRT = mathSqrt$2(3);
  10635. var ONE_THIRD = 1 / 3;
  10636. // 临时变量
  10637. var _v0 = create();
  10638. var _v1 = create();
  10639. var _v2 = create();
  10640. function isAroundZero(val) {
  10641. return val > -EPSILON$1 && val < EPSILON$1;
  10642. }
  10643. function isNotAroundZero$1(val) {
  10644. return val > EPSILON$1 || val < -EPSILON$1;
  10645. }
  10646. /**
  10647. * 计算三次贝塞尔值
  10648. * @memberOf module:zrender/core/curve
  10649. * @param {number} p0
  10650. * @param {number} p1
  10651. * @param {number} p2
  10652. * @param {number} p3
  10653. * @param {number} t
  10654. * @return {number}
  10655. */
  10656. function cubicAt(p0, p1, p2, p3, t) {
  10657. var onet = 1 - t;
  10658. return onet * onet * (onet * p0 + 3 * t * p1)
  10659. + t * t * (t * p3 + 3 * onet * p2);
  10660. }
  10661. /**
  10662. * 计算三次贝塞尔导数值
  10663. * @memberOf module:zrender/core/curve
  10664. * @param {number} p0
  10665. * @param {number} p1
  10666. * @param {number} p2
  10667. * @param {number} p3
  10668. * @param {number} t
  10669. * @return {number}
  10670. */
  10671. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  10672. var onet = 1 - t;
  10673. return 3 * (
  10674. ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  10675. + (p3 - p2) * t * t
  10676. );
  10677. }
  10678. /**
  10679. * 计算三次贝塞尔方程根,使用盛金公式
  10680. * @memberOf module:zrender/core/curve
  10681. * @param {number} p0
  10682. * @param {number} p1
  10683. * @param {number} p2
  10684. * @param {number} p3
  10685. * @param {number} val
  10686. * @param {Array.<number>} roots
  10687. * @return {number} 有效根数目
  10688. */
  10689. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  10690. // Evaluate roots of cubic functions
  10691. var a = p3 + 3 * (p1 - p2) - p0;
  10692. var b = 3 * (p2 - p1 * 2 + p0);
  10693. var c = 3 * (p1 - p0);
  10694. var d = p0 - val;
  10695. var A = b * b - 3 * a * c;
  10696. var B = b * c - 9 * a * d;
  10697. var C = c * c - 3 * b * d;
  10698. var n = 0;
  10699. if (isAroundZero(A) && isAroundZero(B)) {
  10700. if (isAroundZero(b)) {
  10701. roots[0] = 0;
  10702. }
  10703. else {
  10704. var t1 = -c / b; //t1, t2, t3, b is not zero
  10705. if (t1 >= 0 && t1 <= 1) {
  10706. roots[n++] = t1;
  10707. }
  10708. }
  10709. }
  10710. else {
  10711. var disc = B * B - 4 * A * C;
  10712. if (isAroundZero(disc)) {
  10713. var K = B / A;
  10714. var t1 = -b / a + K; // t1, a is not zero
  10715. var t2 = -K / 2; // t2, t3
  10716. if (t1 >= 0 && t1 <= 1) {
  10717. roots[n++] = t1;
  10718. }
  10719. if (t2 >= 0 && t2 <= 1) {
  10720. roots[n++] = t2;
  10721. }
  10722. }
  10723. else if (disc > 0) {
  10724. var discSqrt = mathSqrt$2(disc);
  10725. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  10726. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  10727. if (Y1 < 0) {
  10728. Y1 = -mathPow(-Y1, ONE_THIRD);
  10729. }
  10730. else {
  10731. Y1 = mathPow(Y1, ONE_THIRD);
  10732. }
  10733. if (Y2 < 0) {
  10734. Y2 = -mathPow(-Y2, ONE_THIRD);
  10735. }
  10736. else {
  10737. Y2 = mathPow(Y2, ONE_THIRD);
  10738. }
  10739. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  10740. if (t1 >= 0 && t1 <= 1) {
  10741. roots[n++] = t1;
  10742. }
  10743. }
  10744. else {
  10745. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt$2(A * A * A));
  10746. var theta = Math.acos(T) / 3;
  10747. var ASqrt = mathSqrt$2(A);
  10748. var tmp = Math.cos(theta);
  10749. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  10750. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  10751. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  10752. if (t1 >= 0 && t1 <= 1) {
  10753. roots[n++] = t1;
  10754. }
  10755. if (t2 >= 0 && t2 <= 1) {
  10756. roots[n++] = t2;
  10757. }
  10758. if (t3 >= 0 && t3 <= 1) {
  10759. roots[n++] = t3;
  10760. }
  10761. }
  10762. }
  10763. return n;
  10764. }
  10765. /**
  10766. * 计算三次贝塞尔方程极限值的位置
  10767. * @memberOf module:zrender/core/curve
  10768. * @param {number} p0
  10769. * @param {number} p1
  10770. * @param {number} p2
  10771. * @param {number} p3
  10772. * @param {Array.<number>} extrema
  10773. * @return {number} 有效数目
  10774. */
  10775. function cubicExtrema(p0, p1, p2, p3, extrema) {
  10776. var b = 6 * p2 - 12 * p1 + 6 * p0;
  10777. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  10778. var c = 3 * p1 - 3 * p0;
  10779. var n = 0;
  10780. if (isAroundZero(a)) {
  10781. if (isNotAroundZero$1(b)) {
  10782. var t1 = -c / b;
  10783. if (t1 >= 0 && t1 <= 1) {
  10784. extrema[n++] = t1;
  10785. }
  10786. }
  10787. }
  10788. else {
  10789. var disc = b * b - 4 * a * c;
  10790. if (isAroundZero(disc)) {
  10791. extrema[0] = -b / (2 * a);
  10792. }
  10793. else if (disc > 0) {
  10794. var discSqrt = mathSqrt$2(disc);
  10795. var t1 = (-b + discSqrt) / (2 * a);
  10796. var t2 = (-b - discSqrt) / (2 * a);
  10797. if (t1 >= 0 && t1 <= 1) {
  10798. extrema[n++] = t1;
  10799. }
  10800. if (t2 >= 0 && t2 <= 1) {
  10801. extrema[n++] = t2;
  10802. }
  10803. }
  10804. }
  10805. return n;
  10806. }
  10807. /**
  10808. * 细分三次贝塞尔曲线
  10809. * @memberOf module:zrender/core/curve
  10810. * @param {number} p0
  10811. * @param {number} p1
  10812. * @param {number} p2
  10813. * @param {number} p3
  10814. * @param {number} t
  10815. * @param {Array.<number>} out
  10816. */
  10817. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  10818. var p01 = (p1 - p0) * t + p0;
  10819. var p12 = (p2 - p1) * t + p1;
  10820. var p23 = (p3 - p2) * t + p2;
  10821. var p012 = (p12 - p01) * t + p01;
  10822. var p123 = (p23 - p12) * t + p12;
  10823. var p0123 = (p123 - p012) * t + p012;
  10824. // Seg0
  10825. out[0] = p0;
  10826. out[1] = p01;
  10827. out[2] = p012;
  10828. out[3] = p0123;
  10829. // Seg1
  10830. out[4] = p0123;
  10831. out[5] = p123;
  10832. out[6] = p23;
  10833. out[7] = p3;
  10834. }
  10835. /**
  10836. * 投射点到三次贝塞尔曲线上,返回投射距离。
  10837. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  10838. * @param {number} x0
  10839. * @param {number} y0
  10840. * @param {number} x1
  10841. * @param {number} y1
  10842. * @param {number} x2
  10843. * @param {number} y2
  10844. * @param {number} x3
  10845. * @param {number} y3
  10846. * @param {number} x
  10847. * @param {number} y
  10848. * @param {Array.<number>} [out] 投射点
  10849. * @return {number}
  10850. */
  10851. function cubicProjectPoint(
  10852. x0, y0, x1, y1, x2, y2, x3, y3,
  10853. x, y, out
  10854. ) {
  10855. // http://pomax.github.io/bezierinfo/#projections
  10856. var t;
  10857. var interval = 0.005;
  10858. var d = Infinity;
  10859. var prev;
  10860. var next;
  10861. var d1;
  10862. var d2;
  10863. _v0[0] = x;
  10864. _v0[1] = y;
  10865. // 先粗略估计一下可能的最小距离的 t 值
  10866. // PENDING
  10867. for (var _t = 0; _t < 1; _t += 0.05) {
  10868. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  10869. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  10870. d1 = distSquare(_v0, _v1);
  10871. if (d1 < d) {
  10872. t = _t;
  10873. d = d1;
  10874. }
  10875. }
  10876. d = Infinity;
  10877. // At most 32 iteration
  10878. for (var i = 0; i < 32; i++) {
  10879. if (interval < EPSILON_NUMERIC) {
  10880. break;
  10881. }
  10882. prev = t - interval;
  10883. next = t + interval;
  10884. // t - interval
  10885. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  10886. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  10887. d1 = distSquare(_v1, _v0);
  10888. if (prev >= 0 && d1 < d) {
  10889. t = prev;
  10890. d = d1;
  10891. }
  10892. else {
  10893. // t + interval
  10894. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  10895. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  10896. d2 = distSquare(_v2, _v0);
  10897. if (next <= 1 && d2 < d) {
  10898. t = next;
  10899. d = d2;
  10900. }
  10901. else {
  10902. interval *= 0.5;
  10903. }
  10904. }
  10905. }
  10906. // t
  10907. if (out) {
  10908. out[0] = cubicAt(x0, x1, x2, x3, t);
  10909. out[1] = cubicAt(y0, y1, y2, y3, t);
  10910. }
  10911. // console.log(interval, i);
  10912. return mathSqrt$2(d);
  10913. }
  10914. /**
  10915. * 计算二次方贝塞尔值
  10916. * @param {number} p0
  10917. * @param {number} p1
  10918. * @param {number} p2
  10919. * @param {number} t
  10920. * @return {number}
  10921. */
  10922. function quadraticAt(p0, p1, p2, t) {
  10923. var onet = 1 - t;
  10924. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  10925. }
  10926. /**
  10927. * 计算二次方贝塞尔导数值
  10928. * @param {number} p0
  10929. * @param {number} p1
  10930. * @param {number} p2
  10931. * @param {number} t
  10932. * @return {number}
  10933. */
  10934. function quadraticDerivativeAt(p0, p1, p2, t) {
  10935. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  10936. }
  10937. /**
  10938. * 计算二次方贝塞尔方程根
  10939. * @param {number} p0
  10940. * @param {number} p1
  10941. * @param {number} p2
  10942. * @param {number} t
  10943. * @param {Array.<number>} roots
  10944. * @return {number} 有效根数目
  10945. */
  10946. function quadraticRootAt(p0, p1, p2, val, roots) {
  10947. var a = p0 - 2 * p1 + p2;
  10948. var b = 2 * (p1 - p0);
  10949. var c = p0 - val;
  10950. var n = 0;
  10951. if (isAroundZero(a)) {
  10952. if (isNotAroundZero$1(b)) {
  10953. var t1 = -c / b;
  10954. if (t1 >= 0 && t1 <= 1) {
  10955. roots[n++] = t1;
  10956. }
  10957. }
  10958. }
  10959. else {
  10960. var disc = b * b - 4 * a * c;
  10961. if (isAroundZero(disc)) {
  10962. var t1 = -b / (2 * a);
  10963. if (t1 >= 0 && t1 <= 1) {
  10964. roots[n++] = t1;
  10965. }
  10966. }
  10967. else if (disc > 0) {
  10968. var discSqrt = mathSqrt$2(disc);
  10969. var t1 = (-b + discSqrt) / (2 * a);
  10970. var t2 = (-b - discSqrt) / (2 * a);
  10971. if (t1 >= 0 && t1 <= 1) {
  10972. roots[n++] = t1;
  10973. }
  10974. if (t2 >= 0 && t2 <= 1) {
  10975. roots[n++] = t2;
  10976. }
  10977. }
  10978. }
  10979. return n;
  10980. }
  10981. /**
  10982. * 计算二次贝塞尔方程极限值
  10983. * @memberOf module:zrender/core/curve
  10984. * @param {number} p0
  10985. * @param {number} p1
  10986. * @param {number} p2
  10987. * @return {number}
  10988. */
  10989. function quadraticExtremum(p0, p1, p2) {
  10990. var divider = p0 + p2 - 2 * p1;
  10991. if (divider === 0) {
  10992. // p1 is center of p0 and p2
  10993. return 0.5;
  10994. }
  10995. else {
  10996. return (p0 - p1) / divider;
  10997. }
  10998. }
  10999. /**
  11000. * 细分二次贝塞尔曲线
  11001. * @memberOf module:zrender/core/curve
  11002. * @param {number} p0
  11003. * @param {number} p1
  11004. * @param {number} p2
  11005. * @param {number} t
  11006. * @param {Array.<number>} out
  11007. */
  11008. function quadraticSubdivide(p0, p1, p2, t, out) {
  11009. var p01 = (p1 - p0) * t + p0;
  11010. var p12 = (p2 - p1) * t + p1;
  11011. var p012 = (p12 - p01) * t + p01;
  11012. // Seg0
  11013. out[0] = p0;
  11014. out[1] = p01;
  11015. out[2] = p012;
  11016. // Seg1
  11017. out[3] = p012;
  11018. out[4] = p12;
  11019. out[5] = p2;
  11020. }
  11021. /**
  11022. * 投射点到二次贝塞尔曲线上,返回投射距离。
  11023. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  11024. * @param {number} x0
  11025. * @param {number} y0
  11026. * @param {number} x1
  11027. * @param {number} y1
  11028. * @param {number} x2
  11029. * @param {number} y2
  11030. * @param {number} x
  11031. * @param {number} y
  11032. * @param {Array.<number>} out 投射点
  11033. * @return {number}
  11034. */
  11035. function quadraticProjectPoint(
  11036. x0, y0, x1, y1, x2, y2,
  11037. x, y, out
  11038. ) {
  11039. // http://pomax.github.io/bezierinfo/#projections
  11040. var t;
  11041. var interval = 0.005;
  11042. var d = Infinity;
  11043. _v0[0] = x;
  11044. _v0[1] = y;
  11045. // 先粗略估计一下可能的最小距离的 t 值
  11046. // PENDING
  11047. for (var _t = 0; _t < 1; _t += 0.05) {
  11048. _v1[0] = quadraticAt(x0, x1, x2, _t);
  11049. _v1[1] = quadraticAt(y0, y1, y2, _t);
  11050. var d1 = distSquare(_v0, _v1);
  11051. if (d1 < d) {
  11052. t = _t;
  11053. d = d1;
  11054. }
  11055. }
  11056. d = Infinity;
  11057. // At most 32 iteration
  11058. for (var i = 0; i < 32; i++) {
  11059. if (interval < EPSILON_NUMERIC) {
  11060. break;
  11061. }
  11062. var prev = t - interval;
  11063. var next = t + interval;
  11064. // t - interval
  11065. _v1[0] = quadraticAt(x0, x1, x2, prev);
  11066. _v1[1] = quadraticAt(y0, y1, y2, prev);
  11067. var d1 = distSquare(_v1, _v0);
  11068. if (prev >= 0 && d1 < d) {
  11069. t = prev;
  11070. d = d1;
  11071. }
  11072. else {
  11073. // t + interval
  11074. _v2[0] = quadraticAt(x0, x1, x2, next);
  11075. _v2[1] = quadraticAt(y0, y1, y2, next);
  11076. var d2 = distSquare(_v2, _v0);
  11077. if (next <= 1 && d2 < d) {
  11078. t = next;
  11079. d = d2;
  11080. }
  11081. else {
  11082. interval *= 0.5;
  11083. }
  11084. }
  11085. }
  11086. // t
  11087. if (out) {
  11088. out[0] = quadraticAt(x0, x1, x2, t);
  11089. out[1] = quadraticAt(y0, y1, y2, t);
  11090. }
  11091. // console.log(interval, i);
  11092. return mathSqrt$2(d);
  11093. }
  11094. /**
  11095. * @author Yi Shen(https://github.com/pissang)
  11096. */
  11097. var mathMin$3 = Math.min;
  11098. var mathMax$3 = Math.max;
  11099. var mathSin$2 = Math.sin;
  11100. var mathCos$2 = Math.cos;
  11101. var PI2 = Math.PI * 2;
  11102. var start = create();
  11103. var end = create();
  11104. var extremity = create();
  11105. /**
  11106. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  11107. * @module zrender/core/bbox
  11108. * @param {Array<Object>} points 顶点数组
  11109. * @param {number} min
  11110. * @param {number} max
  11111. */
  11112. function fromPoints(points, min$$1, max$$1) {
  11113. if (points.length === 0) {
  11114. return;
  11115. }
  11116. var p = points[0];
  11117. var left = p[0];
  11118. var right = p[0];
  11119. var top = p[1];
  11120. var bottom = p[1];
  11121. var i;
  11122. for (i = 1; i < points.length; i++) {
  11123. p = points[i];
  11124. left = mathMin$3(left, p[0]);
  11125. right = mathMax$3(right, p[0]);
  11126. top = mathMin$3(top, p[1]);
  11127. bottom = mathMax$3(bottom, p[1]);
  11128. }
  11129. min$$1[0] = left;
  11130. min$$1[1] = top;
  11131. max$$1[0] = right;
  11132. max$$1[1] = bottom;
  11133. }
  11134. /**
  11135. * @memberOf module:zrender/core/bbox
  11136. * @param {number} x0
  11137. * @param {number} y0
  11138. * @param {number} x1
  11139. * @param {number} y1
  11140. * @param {Array.<number>} min
  11141. * @param {Array.<number>} max
  11142. */
  11143. function fromLine(x0, y0, x1, y1, min$$1, max$$1) {
  11144. min$$1[0] = mathMin$3(x0, x1);
  11145. min$$1[1] = mathMin$3(y0, y1);
  11146. max$$1[0] = mathMax$3(x0, x1);
  11147. max$$1[1] = mathMax$3(y0, y1);
  11148. }
  11149. var xDim = [];
  11150. var yDim = [];
  11151. /**
  11152. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  11153. * @memberOf module:zrender/core/bbox
  11154. * @param {number} x0
  11155. * @param {number} y0
  11156. * @param {number} x1
  11157. * @param {number} y1
  11158. * @param {number} x2
  11159. * @param {number} y2
  11160. * @param {number} x3
  11161. * @param {number} y3
  11162. * @param {Array.<number>} min
  11163. * @param {Array.<number>} max
  11164. */
  11165. function fromCubic(
  11166. x0, y0, x1, y1, x2, y2, x3, y3, min$$1, max$$1
  11167. ) {
  11168. var cubicExtrema$$1 = cubicExtrema;
  11169. var cubicAt$$1 = cubicAt;
  11170. var i;
  11171. var n = cubicExtrema$$1(x0, x1, x2, x3, xDim);
  11172. min$$1[0] = Infinity;
  11173. min$$1[1] = Infinity;
  11174. max$$1[0] = -Infinity;
  11175. max$$1[1] = -Infinity;
  11176. for (i = 0; i < n; i++) {
  11177. var x = cubicAt$$1(x0, x1, x2, x3, xDim[i]);
  11178. min$$1[0] = mathMin$3(x, min$$1[0]);
  11179. max$$1[0] = mathMax$3(x, max$$1[0]);
  11180. }
  11181. n = cubicExtrema$$1(y0, y1, y2, y3, yDim);
  11182. for (i = 0; i < n; i++) {
  11183. var y = cubicAt$$1(y0, y1, y2, y3, yDim[i]);
  11184. min$$1[1] = mathMin$3(y, min$$1[1]);
  11185. max$$1[1] = mathMax$3(y, max$$1[1]);
  11186. }
  11187. min$$1[0] = mathMin$3(x0, min$$1[0]);
  11188. max$$1[0] = mathMax$3(x0, max$$1[0]);
  11189. min$$1[0] = mathMin$3(x3, min$$1[0]);
  11190. max$$1[0] = mathMax$3(x3, max$$1[0]);
  11191. min$$1[1] = mathMin$3(y0, min$$1[1]);
  11192. max$$1[1] = mathMax$3(y0, max$$1[1]);
  11193. min$$1[1] = mathMin$3(y3, min$$1[1]);
  11194. max$$1[1] = mathMax$3(y3, max$$1[1]);
  11195. }
  11196. /**
  11197. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  11198. * @memberOf module:zrender/core/bbox
  11199. * @param {number} x0
  11200. * @param {number} y0
  11201. * @param {number} x1
  11202. * @param {number} y1
  11203. * @param {number} x2
  11204. * @param {number} y2
  11205. * @param {Array.<number>} min
  11206. * @param {Array.<number>} max
  11207. */
  11208. function fromQuadratic(x0, y0, x1, y1, x2, y2, min$$1, max$$1) {
  11209. var quadraticExtremum$$1 = quadraticExtremum;
  11210. var quadraticAt$$1 = quadraticAt;
  11211. // Find extremities, where derivative in x dim or y dim is zero
  11212. var tx =
  11213. mathMax$3(
  11214. mathMin$3(quadraticExtremum$$1(x0, x1, x2), 1), 0
  11215. );
  11216. var ty =
  11217. mathMax$3(
  11218. mathMin$3(quadraticExtremum$$1(y0, y1, y2), 1), 0
  11219. );
  11220. var x = quadraticAt$$1(x0, x1, x2, tx);
  11221. var y = quadraticAt$$1(y0, y1, y2, ty);
  11222. min$$1[0] = mathMin$3(x0, x2, x);
  11223. min$$1[1] = mathMin$3(y0, y2, y);
  11224. max$$1[0] = mathMax$3(x0, x2, x);
  11225. max$$1[1] = mathMax$3(y0, y2, y);
  11226. }
  11227. /**
  11228. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  11229. * @method
  11230. * @memberOf module:zrender/core/bbox
  11231. * @param {number} x
  11232. * @param {number} y
  11233. * @param {number} rx
  11234. * @param {number} ry
  11235. * @param {number} startAngle
  11236. * @param {number} endAngle
  11237. * @param {number} anticlockwise
  11238. * @param {Array.<number>} min
  11239. * @param {Array.<number>} max
  11240. */
  11241. function fromArc(
  11242. x, y, rx, ry, startAngle, endAngle, anticlockwise, min$$1, max$$1
  11243. ) {
  11244. var vec2Min = min;
  11245. var vec2Max = max;
  11246. var diff = Math.abs(startAngle - endAngle);
  11247. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  11248. // Is a circle
  11249. min$$1[0] = x - rx;
  11250. min$$1[1] = y - ry;
  11251. max$$1[0] = x + rx;
  11252. max$$1[1] = y + ry;
  11253. return;
  11254. }
  11255. start[0] = mathCos$2(startAngle) * rx + x;
  11256. start[1] = mathSin$2(startAngle) * ry + y;
  11257. end[0] = mathCos$2(endAngle) * rx + x;
  11258. end[1] = mathSin$2(endAngle) * ry + y;
  11259. vec2Min(min$$1, start, end);
  11260. vec2Max(max$$1, start, end);
  11261. // Thresh to [0, Math.PI * 2]
  11262. startAngle = startAngle % (PI2);
  11263. if (startAngle < 0) {
  11264. startAngle = startAngle + PI2;
  11265. }
  11266. endAngle = endAngle % (PI2);
  11267. if (endAngle < 0) {
  11268. endAngle = endAngle + PI2;
  11269. }
  11270. if (startAngle > endAngle && !anticlockwise) {
  11271. endAngle += PI2;
  11272. }
  11273. else if (startAngle < endAngle && anticlockwise) {
  11274. startAngle += PI2;
  11275. }
  11276. if (anticlockwise) {
  11277. var tmp = endAngle;
  11278. endAngle = startAngle;
  11279. startAngle = tmp;
  11280. }
  11281. // var number = 0;
  11282. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  11283. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  11284. if (angle > startAngle) {
  11285. extremity[0] = mathCos$2(angle) * rx + x;
  11286. extremity[1] = mathSin$2(angle) * ry + y;
  11287. vec2Min(min$$1, extremity, min$$1);
  11288. vec2Max(max$$1, extremity, max$$1);
  11289. }
  11290. }
  11291. }
  11292. /**
  11293. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  11294. * 可以用于 isInsidePath 判断以及获取boundingRect
  11295. *
  11296. * @module zrender/core/PathProxy
  11297. * @author Yi Shen (http://www.github.com/pissang)
  11298. */
  11299. // TODO getTotalLength, getPointAtLength
  11300. var CMD = {
  11301. M: 1,
  11302. L: 2,
  11303. C: 3,
  11304. Q: 4,
  11305. A: 5,
  11306. Z: 6,
  11307. // Rect
  11308. R: 7
  11309. };
  11310. // var CMD_MEM_SIZE = {
  11311. // M: 3,
  11312. // L: 3,
  11313. // C: 7,
  11314. // Q: 5,
  11315. // A: 9,
  11316. // R: 5,
  11317. // Z: 1
  11318. // };
  11319. var min$1 = [];
  11320. var max$1 = [];
  11321. var min2 = [];
  11322. var max2 = [];
  11323. var mathMin$2 = Math.min;
  11324. var mathMax$2 = Math.max;
  11325. var mathCos$1 = Math.cos;
  11326. var mathSin$1 = Math.sin;
  11327. var mathSqrt$1 = Math.sqrt;
  11328. var mathAbs = Math.abs;
  11329. var hasTypedArray = typeof Float32Array !== 'undefined';
  11330. /**
  11331. * @alias module:zrender/core/PathProxy
  11332. * @constructor
  11333. */
  11334. var PathProxy = function (notSaveData) {
  11335. this._saveData = !(notSaveData || false);
  11336. if (this._saveData) {
  11337. /**
  11338. * Path data. Stored as flat array
  11339. * @type {Array.<Object>}
  11340. */
  11341. this.data = [];
  11342. }
  11343. this._ctx = null;
  11344. };
  11345. /**
  11346. * 快速计算Path包围盒(并不是最小包围盒)
  11347. * @return {Object}
  11348. */
  11349. PathProxy.prototype = {
  11350. constructor: PathProxy,
  11351. _xi: 0,
  11352. _yi: 0,
  11353. _x0: 0,
  11354. _y0: 0,
  11355. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  11356. _ux: 0,
  11357. _uy: 0,
  11358. _len: 0,
  11359. _lineDash: null,
  11360. _dashOffset: 0,
  11361. _dashIdx: 0,
  11362. _dashSum: 0,
  11363. /**
  11364. * @readOnly
  11365. */
  11366. setScale: function (sx, sy) {
  11367. this._ux = mathAbs(1 / devicePixelRatio / sx) || 0;
  11368. this._uy = mathAbs(1 / devicePixelRatio / sy) || 0;
  11369. },
  11370. getContext: function () {
  11371. return this._ctx;
  11372. },
  11373. /**
  11374. * @param {CanvasRenderingContext2D} ctx
  11375. * @return {module:zrender/core/PathProxy}
  11376. */
  11377. beginPath: function (ctx) {
  11378. this._ctx = ctx;
  11379. ctx && ctx.beginPath();
  11380. ctx && (this.dpr = ctx.dpr);
  11381. // Reset
  11382. if (this._saveData) {
  11383. this._len = 0;
  11384. }
  11385. if (this._lineDash) {
  11386. this._lineDash = null;
  11387. this._dashOffset = 0;
  11388. }
  11389. return this;
  11390. },
  11391. /**
  11392. * @param {number} x
  11393. * @param {number} y
  11394. * @return {module:zrender/core/PathProxy}
  11395. */
  11396. moveTo: function (x, y) {
  11397. this.addData(CMD.M, x, y);
  11398. this._ctx && this._ctx.moveTo(x, y);
  11399. // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  11400. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  11401. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  11402. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  11403. this._x0 = x;
  11404. this._y0 = y;
  11405. this._xi = x;
  11406. this._yi = y;
  11407. return this;
  11408. },
  11409. /**
  11410. * @param {number} x
  11411. * @param {number} y
  11412. * @return {module:zrender/core/PathProxy}
  11413. */
  11414. lineTo: function (x, y) {
  11415. var exceedUnit = mathAbs(x - this._xi) > this._ux
  11416. || mathAbs(y - this._yi) > this._uy
  11417. // Force draw the first segment
  11418. || this._len < 5;
  11419. this.addData(CMD.L, x, y);
  11420. if (this._ctx && exceedUnit) {
  11421. this._needsDash() ? this._dashedLineTo(x, y)
  11422. : this._ctx.lineTo(x, y);
  11423. }
  11424. if (exceedUnit) {
  11425. this._xi = x;
  11426. this._yi = y;
  11427. }
  11428. return this;
  11429. },
  11430. /**
  11431. * @param {number} x1
  11432. * @param {number} y1
  11433. * @param {number} x2
  11434. * @param {number} y2
  11435. * @param {number} x3
  11436. * @param {number} y3
  11437. * @return {module:zrender/core/PathProxy}
  11438. */
  11439. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  11440. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  11441. if (this._ctx) {
  11442. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  11443. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11444. }
  11445. this._xi = x3;
  11446. this._yi = y3;
  11447. return this;
  11448. },
  11449. /**
  11450. * @param {number} x1
  11451. * @param {number} y1
  11452. * @param {number} x2
  11453. * @param {number} y2
  11454. * @return {module:zrender/core/PathProxy}
  11455. */
  11456. quadraticCurveTo: function (x1, y1, x2, y2) {
  11457. this.addData(CMD.Q, x1, y1, x2, y2);
  11458. if (this._ctx) {
  11459. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
  11460. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  11461. }
  11462. this._xi = x2;
  11463. this._yi = y2;
  11464. return this;
  11465. },
  11466. /**
  11467. * @param {number} cx
  11468. * @param {number} cy
  11469. * @param {number} r
  11470. * @param {number} startAngle
  11471. * @param {number} endAngle
  11472. * @param {boolean} anticlockwise
  11473. * @return {module:zrender/core/PathProxy}
  11474. */
  11475. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  11476. this.addData(
  11477. CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1
  11478. );
  11479. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  11480. this._xi = mathCos$1(endAngle) * r + cx;
  11481. this._yi = mathSin$1(endAngle) * r + cy;
  11482. return this;
  11483. },
  11484. // TODO
  11485. arcTo: function (x1, y1, x2, y2, radius) {
  11486. if (this._ctx) {
  11487. this._ctx.arcTo(x1, y1, x2, y2, radius);
  11488. }
  11489. return this;
  11490. },
  11491. // TODO
  11492. rect: function (x, y, w, h) {
  11493. this._ctx && this._ctx.rect(x, y, w, h);
  11494. this.addData(CMD.R, x, y, w, h);
  11495. return this;
  11496. },
  11497. /**
  11498. * @return {module:zrender/core/PathProxy}
  11499. */
  11500. closePath: function () {
  11501. this.addData(CMD.Z);
  11502. var ctx = this._ctx;
  11503. var x0 = this._x0;
  11504. var y0 = this._y0;
  11505. if (ctx) {
  11506. this._needsDash() && this._dashedLineTo(x0, y0);
  11507. ctx.closePath();
  11508. }
  11509. this._xi = x0;
  11510. this._yi = y0;
  11511. return this;
  11512. },
  11513. /**
  11514. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  11515. * stroke 同样
  11516. * @param {CanvasRenderingContext2D} ctx
  11517. * @return {module:zrender/core/PathProxy}
  11518. */
  11519. fill: function (ctx) {
  11520. ctx && ctx.fill();
  11521. this.toStatic();
  11522. },
  11523. /**
  11524. * @param {CanvasRenderingContext2D} ctx
  11525. * @return {module:zrender/core/PathProxy}
  11526. */
  11527. stroke: function (ctx) {
  11528. ctx && ctx.stroke();
  11529. this.toStatic();
  11530. },
  11531. /**
  11532. * 必须在其它绘制命令前调用
  11533. * Must be invoked before all other path drawing methods
  11534. * @return {module:zrender/core/PathProxy}
  11535. */
  11536. setLineDash: function (lineDash) {
  11537. if (lineDash instanceof Array) {
  11538. this._lineDash = lineDash;
  11539. this._dashIdx = 0;
  11540. var lineDashSum = 0;
  11541. for (var i = 0; i < lineDash.length; i++) {
  11542. lineDashSum += lineDash[i];
  11543. }
  11544. this._dashSum = lineDashSum;
  11545. }
  11546. return this;
  11547. },
  11548. /**
  11549. * 必须在其它绘制命令前调用
  11550. * Must be invoked before all other path drawing methods
  11551. * @return {module:zrender/core/PathProxy}
  11552. */
  11553. setLineDashOffset: function (offset) {
  11554. this._dashOffset = offset;
  11555. return this;
  11556. },
  11557. /**
  11558. *
  11559. * @return {boolean}
  11560. */
  11561. len: function () {
  11562. return this._len;
  11563. },
  11564. /**
  11565. * 直接设置 Path 数据
  11566. */
  11567. setData: function (data) {
  11568. var len$$1 = data.length;
  11569. if (!(this.data && this.data.length === len$$1) && hasTypedArray) {
  11570. this.data = new Float32Array(len$$1);
  11571. }
  11572. for (var i = 0; i < len$$1; i++) {
  11573. this.data[i] = data[i];
  11574. }
  11575. this._len = len$$1;
  11576. },
  11577. /**
  11578. * 添加子路径
  11579. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  11580. */
  11581. appendPath: function (path) {
  11582. if (!(path instanceof Array)) {
  11583. path = [path];
  11584. }
  11585. var len$$1 = path.length;
  11586. var appendSize = 0;
  11587. var offset = this._len;
  11588. for (var i = 0; i < len$$1; i++) {
  11589. appendSize += path[i].len();
  11590. }
  11591. if (hasTypedArray && (this.data instanceof Float32Array)) {
  11592. this.data = new Float32Array(offset + appendSize);
  11593. }
  11594. for (var i = 0; i < len$$1; i++) {
  11595. var appendPathData = path[i].data;
  11596. for (var k = 0; k < appendPathData.length; k++) {
  11597. this.data[offset++] = appendPathData[k];
  11598. }
  11599. }
  11600. this._len = offset;
  11601. },
  11602. /**
  11603. * 填充 Path 数据。
  11604. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  11605. */
  11606. addData: function (cmd) {
  11607. if (!this._saveData) {
  11608. return;
  11609. }
  11610. var data = this.data;
  11611. if (this._len + arguments.length > data.length) {
  11612. // 因为之前的数组已经转换成静态的 Float32Array
  11613. // 所以不够用时需要扩展一个新的动态数组
  11614. this._expandData();
  11615. data = this.data;
  11616. }
  11617. for (var i = 0; i < arguments.length; i++) {
  11618. data[this._len++] = arguments[i];
  11619. }
  11620. this._prevCmd = cmd;
  11621. },
  11622. _expandData: function () {
  11623. // Only if data is Float32Array
  11624. if (!(this.data instanceof Array)) {
  11625. var newData = [];
  11626. for (var i = 0; i < this._len; i++) {
  11627. newData[i] = this.data[i];
  11628. }
  11629. this.data = newData;
  11630. }
  11631. },
  11632. /**
  11633. * If needs js implemented dashed line
  11634. * @return {boolean}
  11635. * @private
  11636. */
  11637. _needsDash: function () {
  11638. return this._lineDash;
  11639. },
  11640. _dashedLineTo: function (x1, y1) {
  11641. var dashSum = this._dashSum;
  11642. var offset = this._dashOffset;
  11643. var lineDash = this._lineDash;
  11644. var ctx = this._ctx;
  11645. var x0 = this._xi;
  11646. var y0 = this._yi;
  11647. var dx = x1 - x0;
  11648. var dy = y1 - y0;
  11649. var dist$$1 = mathSqrt$1(dx * dx + dy * dy);
  11650. var x = x0;
  11651. var y = y0;
  11652. var dash;
  11653. var nDash = lineDash.length;
  11654. var idx;
  11655. dx /= dist$$1;
  11656. dy /= dist$$1;
  11657. if (offset < 0) {
  11658. // Convert to positive offset
  11659. offset = dashSum + offset;
  11660. }
  11661. offset %= dashSum;
  11662. x -= offset * dx;
  11663. y -= offset * dy;
  11664. while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)
  11665. || (dx === 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {
  11666. idx = this._dashIdx;
  11667. dash = lineDash[idx];
  11668. x += dx * dash;
  11669. y += dy * dash;
  11670. this._dashIdx = (idx + 1) % nDash;
  11671. // Skip positive offset
  11672. if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {
  11673. continue;
  11674. }
  11675. ctx[idx % 2 ? 'moveTo' : 'lineTo'](
  11676. dx >= 0 ? mathMin$2(x, x1) : mathMax$2(x, x1),
  11677. dy >= 0 ? mathMin$2(y, y1) : mathMax$2(y, y1)
  11678. );
  11679. }
  11680. // Offset for next lineTo
  11681. dx = x - x1;
  11682. dy = y - y1;
  11683. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11684. },
  11685. // Not accurate dashed line to
  11686. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  11687. var dashSum = this._dashSum;
  11688. var offset = this._dashOffset;
  11689. var lineDash = this._lineDash;
  11690. var ctx = this._ctx;
  11691. var x0 = this._xi;
  11692. var y0 = this._yi;
  11693. var t;
  11694. var dx;
  11695. var dy;
  11696. var cubicAt$$1 = cubicAt;
  11697. var bezierLen = 0;
  11698. var idx = this._dashIdx;
  11699. var nDash = lineDash.length;
  11700. var x;
  11701. var y;
  11702. var tmpLen = 0;
  11703. if (offset < 0) {
  11704. // Convert to positive offset
  11705. offset = dashSum + offset;
  11706. }
  11707. offset %= dashSum;
  11708. // Bezier approx length
  11709. for (t = 0; t < 1; t += 0.1) {
  11710. dx = cubicAt$$1(x0, x1, x2, x3, t + 0.1)
  11711. - cubicAt$$1(x0, x1, x2, x3, t);
  11712. dy = cubicAt$$1(y0, y1, y2, y3, t + 0.1)
  11713. - cubicAt$$1(y0, y1, y2, y3, t);
  11714. bezierLen += mathSqrt$1(dx * dx + dy * dy);
  11715. }
  11716. // Find idx after add offset
  11717. for (; idx < nDash; idx++) {
  11718. tmpLen += lineDash[idx];
  11719. if (tmpLen > offset) {
  11720. break;
  11721. }
  11722. }
  11723. t = (tmpLen - offset) / bezierLen;
  11724. while (t <= 1) {
  11725. x = cubicAt$$1(x0, x1, x2, x3, t);
  11726. y = cubicAt$$1(y0, y1, y2, y3, t);
  11727. // Use line to approximate dashed bezier
  11728. // Bad result if dash is long
  11729. idx % 2 ? ctx.moveTo(x, y)
  11730. : ctx.lineTo(x, y);
  11731. t += lineDash[idx] / bezierLen;
  11732. idx = (idx + 1) % nDash;
  11733. }
  11734. // Finish the last segment and calculate the new offset
  11735. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  11736. dx = x3 - x;
  11737. dy = y3 - y;
  11738. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11739. },
  11740. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  11741. // Convert quadratic to cubic using degree elevation
  11742. var x3 = x2;
  11743. var y3 = y2;
  11744. x2 = (x2 + 2 * x1) / 3;
  11745. y2 = (y2 + 2 * y1) / 3;
  11746. x1 = (this._xi + 2 * x1) / 3;
  11747. y1 = (this._yi + 2 * y1) / 3;
  11748. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  11749. },
  11750. /**
  11751. * 转成静态的 Float32Array 减少堆内存占用
  11752. * Convert dynamic array to static Float32Array
  11753. */
  11754. toStatic: function () {
  11755. var data = this.data;
  11756. if (data instanceof Array) {
  11757. data.length = this._len;
  11758. if (hasTypedArray) {
  11759. this.data = new Float32Array(data);
  11760. }
  11761. }
  11762. },
  11763. /**
  11764. * @return {module:zrender/core/BoundingRect}
  11765. */
  11766. getBoundingRect: function () {
  11767. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  11768. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  11769. var data = this.data;
  11770. var xi = 0;
  11771. var yi = 0;
  11772. var x0 = 0;
  11773. var y0 = 0;
  11774. for (var i = 0; i < data.length;) {
  11775. var cmd = data[i++];
  11776. if (i === 1) {
  11777. // 如果第一个命令是 L, C, Q
  11778. // 则 previous point 同绘制命令的第一个 point
  11779. //
  11780. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11781. xi = data[i];
  11782. yi = data[i + 1];
  11783. x0 = xi;
  11784. y0 = yi;
  11785. }
  11786. switch (cmd) {
  11787. case CMD.M:
  11788. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11789. // 在 closePath 的时候使用
  11790. x0 = data[i++];
  11791. y0 = data[i++];
  11792. xi = x0;
  11793. yi = y0;
  11794. min2[0] = x0;
  11795. min2[1] = y0;
  11796. max2[0] = x0;
  11797. max2[1] = y0;
  11798. break;
  11799. case CMD.L:
  11800. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  11801. xi = data[i++];
  11802. yi = data[i++];
  11803. break;
  11804. case CMD.C:
  11805. fromCubic(
  11806. xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  11807. min2, max2
  11808. );
  11809. xi = data[i++];
  11810. yi = data[i++];
  11811. break;
  11812. case CMD.Q:
  11813. fromQuadratic(
  11814. xi, yi, data[i++], data[i++], data[i], data[i + 1],
  11815. min2, max2
  11816. );
  11817. xi = data[i++];
  11818. yi = data[i++];
  11819. break;
  11820. case CMD.A:
  11821. // TODO Arc 判断的开销比较大
  11822. var cx = data[i++];
  11823. var cy = data[i++];
  11824. var rx = data[i++];
  11825. var ry = data[i++];
  11826. var startAngle = data[i++];
  11827. var endAngle = data[i++] + startAngle;
  11828. // TODO Arc 旋转
  11829. i += 1;
  11830. var anticlockwise = 1 - data[i++];
  11831. if (i === 1) {
  11832. // 直接使用 arc 命令
  11833. // 第一个命令起点还未定义
  11834. x0 = mathCos$1(startAngle) * rx + cx;
  11835. y0 = mathSin$1(startAngle) * ry + cy;
  11836. }
  11837. fromArc(
  11838. cx, cy, rx, ry, startAngle, endAngle,
  11839. anticlockwise, min2, max2
  11840. );
  11841. xi = mathCos$1(endAngle) * rx + cx;
  11842. yi = mathSin$1(endAngle) * ry + cy;
  11843. break;
  11844. case CMD.R:
  11845. x0 = xi = data[i++];
  11846. y0 = yi = data[i++];
  11847. var width = data[i++];
  11848. var height = data[i++];
  11849. // Use fromLine
  11850. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  11851. break;
  11852. case CMD.Z:
  11853. xi = x0;
  11854. yi = y0;
  11855. break;
  11856. }
  11857. // Union
  11858. min(min$1, min$1, min2);
  11859. max(max$1, max$1, max2);
  11860. }
  11861. // No data
  11862. if (i === 0) {
  11863. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  11864. }
  11865. return new BoundingRect(
  11866. min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]
  11867. );
  11868. },
  11869. /**
  11870. * Rebuild path from current data
  11871. * Rebuild path will not consider javascript implemented line dash.
  11872. * @param {CanvasRenderingContext2D} ctx
  11873. */
  11874. rebuildPath: function (ctx) {
  11875. var d = this.data;
  11876. var x0, y0;
  11877. var xi, yi;
  11878. var x, y;
  11879. var ux = this._ux;
  11880. var uy = this._uy;
  11881. var len$$1 = this._len;
  11882. for (var i = 0; i < len$$1;) {
  11883. var cmd = d[i++];
  11884. if (i === 1) {
  11885. // 如果第一个命令是 L, C, Q
  11886. // 则 previous point 同绘制命令的第一个 point
  11887. //
  11888. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11889. xi = d[i];
  11890. yi = d[i + 1];
  11891. x0 = xi;
  11892. y0 = yi;
  11893. }
  11894. switch (cmd) {
  11895. case CMD.M:
  11896. x0 = xi = d[i++];
  11897. y0 = yi = d[i++];
  11898. ctx.moveTo(xi, yi);
  11899. break;
  11900. case CMD.L:
  11901. x = d[i++];
  11902. y = d[i++];
  11903. // Not draw too small seg between
  11904. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len$$1 - 1) {
  11905. ctx.lineTo(x, y);
  11906. xi = x;
  11907. yi = y;
  11908. }
  11909. break;
  11910. case CMD.C:
  11911. ctx.bezierCurveTo(
  11912. d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]
  11913. );
  11914. xi = d[i - 2];
  11915. yi = d[i - 1];
  11916. break;
  11917. case CMD.Q:
  11918. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  11919. xi = d[i - 2];
  11920. yi = d[i - 1];
  11921. break;
  11922. case CMD.A:
  11923. var cx = d[i++];
  11924. var cy = d[i++];
  11925. var rx = d[i++];
  11926. var ry = d[i++];
  11927. var theta = d[i++];
  11928. var dTheta = d[i++];
  11929. var psi = d[i++];
  11930. var fs = d[i++];
  11931. var r = (rx > ry) ? rx : ry;
  11932. var scaleX = (rx > ry) ? 1 : rx / ry;
  11933. var scaleY = (rx > ry) ? ry / rx : 1;
  11934. var isEllipse = Math.abs(rx - ry) > 1e-3;
  11935. var endAngle = theta + dTheta;
  11936. if (isEllipse) {
  11937. ctx.translate(cx, cy);
  11938. ctx.rotate(psi);
  11939. ctx.scale(scaleX, scaleY);
  11940. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  11941. ctx.scale(1 / scaleX, 1 / scaleY);
  11942. ctx.rotate(-psi);
  11943. ctx.translate(-cx, -cy);
  11944. }
  11945. else {
  11946. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  11947. }
  11948. if (i === 1) {
  11949. // 直接使用 arc 命令
  11950. // 第一个命令起点还未定义
  11951. x0 = mathCos$1(theta) * rx + cx;
  11952. y0 = mathSin$1(theta) * ry + cy;
  11953. }
  11954. xi = mathCos$1(endAngle) * rx + cx;
  11955. yi = mathSin$1(endAngle) * ry + cy;
  11956. break;
  11957. case CMD.R:
  11958. x0 = xi = d[i];
  11959. y0 = yi = d[i + 1];
  11960. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  11961. break;
  11962. case CMD.Z:
  11963. ctx.closePath();
  11964. xi = x0;
  11965. yi = y0;
  11966. }
  11967. }
  11968. }
  11969. };
  11970. PathProxy.CMD = CMD;
  11971. /**
  11972. * 线段包含判断
  11973. * @param {number} x0
  11974. * @param {number} y0
  11975. * @param {number} x1
  11976. * @param {number} y1
  11977. * @param {number} lineWidth
  11978. * @param {number} x
  11979. * @param {number} y
  11980. * @return {boolean}
  11981. */
  11982. function containStroke$1(x0, y0, x1, y1, lineWidth, x, y) {
  11983. if (lineWidth === 0) {
  11984. return false;
  11985. }
  11986. var _l = lineWidth;
  11987. var _a = 0;
  11988. var _b = x0;
  11989. // Quick reject
  11990. if (
  11991. (y > y0 + _l && y > y1 + _l)
  11992. || (y < y0 - _l && y < y1 - _l)
  11993. || (x > x0 + _l && x > x1 + _l)
  11994. || (x < x0 - _l && x < x1 - _l)
  11995. ) {
  11996. return false;
  11997. }
  11998. if (x0 !== x1) {
  11999. _a = (y0 - y1) / (x0 - x1);
  12000. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  12001. }
  12002. else {
  12003. return Math.abs(x - x0) <= _l / 2;
  12004. }
  12005. var tmp = _a * x - y + _b;
  12006. var _s = tmp * tmp / (_a * _a + 1);
  12007. return _s <= _l / 2 * _l / 2;
  12008. }
  12009. /**
  12010. * 三次贝塞尔曲线描边包含判断
  12011. * @param {number} x0
  12012. * @param {number} y0
  12013. * @param {number} x1
  12014. * @param {number} y1
  12015. * @param {number} x2
  12016. * @param {number} y2
  12017. * @param {number} x3
  12018. * @param {number} y3
  12019. * @param {number} lineWidth
  12020. * @param {number} x
  12021. * @param {number} y
  12022. * @return {boolean}
  12023. */
  12024. function containStroke$2(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  12025. if (lineWidth === 0) {
  12026. return false;
  12027. }
  12028. var _l = lineWidth;
  12029. // Quick reject
  12030. if (
  12031. (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  12032. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  12033. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  12034. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
  12035. ) {
  12036. return false;
  12037. }
  12038. var d = cubicProjectPoint(
  12039. x0, y0, x1, y1, x2, y2, x3, y3,
  12040. x, y, null
  12041. );
  12042. return d <= _l / 2;
  12043. }
  12044. /**
  12045. * 二次贝塞尔曲线描边包含判断
  12046. * @param {number} x0
  12047. * @param {number} y0
  12048. * @param {number} x1
  12049. * @param {number} y1
  12050. * @param {number} x2
  12051. * @param {number} y2
  12052. * @param {number} lineWidth
  12053. * @param {number} x
  12054. * @param {number} y
  12055. * @return {boolean}
  12056. */
  12057. function containStroke$3(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  12058. if (lineWidth === 0) {
  12059. return false;
  12060. }
  12061. var _l = lineWidth;
  12062. // Quick reject
  12063. if (
  12064. (y > y0 + _l && y > y1 + _l && y > y2 + _l)
  12065. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  12066. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  12067. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)
  12068. ) {
  12069. return false;
  12070. }
  12071. var d = quadraticProjectPoint(
  12072. x0, y0, x1, y1, x2, y2,
  12073. x, y, null
  12074. );
  12075. return d <= _l / 2;
  12076. }
  12077. var PI2$3 = Math.PI * 2;
  12078. function normalizeRadian(angle) {
  12079. angle %= PI2$3;
  12080. if (angle < 0) {
  12081. angle += PI2$3;
  12082. }
  12083. return angle;
  12084. }
  12085. var PI2$2 = Math.PI * 2;
  12086. /**
  12087. * 圆弧描边包含判断
  12088. * @param {number} cx
  12089. * @param {number} cy
  12090. * @param {number} r
  12091. * @param {number} startAngle
  12092. * @param {number} endAngle
  12093. * @param {boolean} anticlockwise
  12094. * @param {number} lineWidth
  12095. * @param {number} x
  12096. * @param {number} y
  12097. * @return {Boolean}
  12098. */
  12099. function containStroke$4(
  12100. cx, cy, r, startAngle, endAngle, anticlockwise,
  12101. lineWidth, x, y
  12102. ) {
  12103. if (lineWidth === 0) {
  12104. return false;
  12105. }
  12106. var _l = lineWidth;
  12107. x -= cx;
  12108. y -= cy;
  12109. var d = Math.sqrt(x * x + y * y);
  12110. if ((d - _l > r) || (d + _l < r)) {
  12111. return false;
  12112. }
  12113. if (Math.abs(startAngle - endAngle) % PI2$2 < 1e-4) {
  12114. // Is a circle
  12115. return true;
  12116. }
  12117. if (anticlockwise) {
  12118. var tmp = startAngle;
  12119. startAngle = normalizeRadian(endAngle);
  12120. endAngle = normalizeRadian(tmp);
  12121. }
  12122. else {
  12123. startAngle = normalizeRadian(startAngle);
  12124. endAngle = normalizeRadian(endAngle);
  12125. }
  12126. if (startAngle > endAngle) {
  12127. endAngle += PI2$2;
  12128. }
  12129. var angle = Math.atan2(y, x);
  12130. if (angle < 0) {
  12131. angle += PI2$2;
  12132. }
  12133. return (angle >= startAngle && angle <= endAngle)
  12134. || (angle + PI2$2 >= startAngle && angle + PI2$2 <= endAngle);
  12135. }
  12136. function windingLine(x0, y0, x1, y1, x, y) {
  12137. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  12138. return 0;
  12139. }
  12140. // Ignore horizontal line
  12141. if (y1 === y0) {
  12142. return 0;
  12143. }
  12144. var dir = y1 < y0 ? 1 : -1;
  12145. var t = (y - y0) / (y1 - y0);
  12146. // Avoid winding error when intersection point is the connect point of two line of polygon
  12147. if (t === 1 || t === 0) {
  12148. dir = y1 < y0 ? 0.5 : -0.5;
  12149. }
  12150. var x_ = t * (x1 - x0) + x0;
  12151. // If (x, y) on the line, considered as "contain".
  12152. return x_ === x ? Infinity : x_ > x ? dir : 0;
  12153. }
  12154. var CMD$1 = PathProxy.CMD;
  12155. var PI2$1 = Math.PI * 2;
  12156. var EPSILON$2 = 1e-4;
  12157. function isAroundEqual(a, b) {
  12158. return Math.abs(a - b) < EPSILON$2;
  12159. }
  12160. // 临时数组
  12161. var roots = [-1, -1, -1];
  12162. var extrema = [-1, -1];
  12163. function swapExtrema() {
  12164. var tmp = extrema[0];
  12165. extrema[0] = extrema[1];
  12166. extrema[1] = tmp;
  12167. }
  12168. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  12169. // Quick reject
  12170. if (
  12171. (y > y0 && y > y1 && y > y2 && y > y3)
  12172. || (y < y0 && y < y1 && y < y2 && y < y3)
  12173. ) {
  12174. return 0;
  12175. }
  12176. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  12177. if (nRoots === 0) {
  12178. return 0;
  12179. }
  12180. else {
  12181. var w = 0;
  12182. var nExtrema = -1;
  12183. var y0_;
  12184. var y1_;
  12185. for (var i = 0; i < nRoots; i++) {
  12186. var t = roots[i];
  12187. // Avoid winding error when intersection point is the connect point of two line of polygon
  12188. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  12189. var x_ = cubicAt(x0, x1, x2, x3, t);
  12190. if (x_ < x) { // Quick reject
  12191. continue;
  12192. }
  12193. if (nExtrema < 0) {
  12194. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  12195. if (extrema[1] < extrema[0] && nExtrema > 1) {
  12196. swapExtrema();
  12197. }
  12198. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  12199. if (nExtrema > 1) {
  12200. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  12201. }
  12202. }
  12203. if (nExtrema === 2) {
  12204. // 分成三段单调函数
  12205. if (t < extrema[0]) {
  12206. w += y0_ < y0 ? unit : -unit;
  12207. }
  12208. else if (t < extrema[1]) {
  12209. w += y1_ < y0_ ? unit : -unit;
  12210. }
  12211. else {
  12212. w += y3 < y1_ ? unit : -unit;
  12213. }
  12214. }
  12215. else {
  12216. // 分成两段单调函数
  12217. if (t < extrema[0]) {
  12218. w += y0_ < y0 ? unit : -unit;
  12219. }
  12220. else {
  12221. w += y3 < y0_ ? unit : -unit;
  12222. }
  12223. }
  12224. }
  12225. return w;
  12226. }
  12227. }
  12228. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  12229. // Quick reject
  12230. if (
  12231. (y > y0 && y > y1 && y > y2)
  12232. || (y < y0 && y < y1 && y < y2)
  12233. ) {
  12234. return 0;
  12235. }
  12236. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  12237. if (nRoots === 0) {
  12238. return 0;
  12239. }
  12240. else {
  12241. var t = quadraticExtremum(y0, y1, y2);
  12242. if (t >= 0 && t <= 1) {
  12243. var w = 0;
  12244. var y_ = quadraticAt(y0, y1, y2, t);
  12245. for (var i = 0; i < nRoots; i++) {
  12246. // Remove one endpoint.
  12247. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  12248. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  12249. if (x_ < x) { // Quick reject
  12250. continue;
  12251. }
  12252. if (roots[i] < t) {
  12253. w += y_ < y0 ? unit : -unit;
  12254. }
  12255. else {
  12256. w += y2 < y_ ? unit : -unit;
  12257. }
  12258. }
  12259. return w;
  12260. }
  12261. else {
  12262. // Remove one endpoint.
  12263. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  12264. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  12265. if (x_ < x) { // Quick reject
  12266. return 0;
  12267. }
  12268. return y2 < y0 ? unit : -unit;
  12269. }
  12270. }
  12271. }
  12272. // TODO
  12273. // Arc 旋转
  12274. function windingArc(
  12275. cx, cy, r, startAngle, endAngle, anticlockwise, x, y
  12276. ) {
  12277. y -= cy;
  12278. if (y > r || y < -r) {
  12279. return 0;
  12280. }
  12281. var tmp = Math.sqrt(r * r - y * y);
  12282. roots[0] = -tmp;
  12283. roots[1] = tmp;
  12284. var diff = Math.abs(startAngle - endAngle);
  12285. if (diff < 1e-4) {
  12286. return 0;
  12287. }
  12288. if (diff % PI2$1 < 1e-4) {
  12289. // Is a circle
  12290. startAngle = 0;
  12291. endAngle = PI2$1;
  12292. var dir = anticlockwise ? 1 : -1;
  12293. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  12294. return dir;
  12295. }
  12296. else {
  12297. return 0;
  12298. }
  12299. }
  12300. if (anticlockwise) {
  12301. var tmp = startAngle;
  12302. startAngle = normalizeRadian(endAngle);
  12303. endAngle = normalizeRadian(tmp);
  12304. }
  12305. else {
  12306. startAngle = normalizeRadian(startAngle);
  12307. endAngle = normalizeRadian(endAngle);
  12308. }
  12309. if (startAngle > endAngle) {
  12310. endAngle += PI2$1;
  12311. }
  12312. var w = 0;
  12313. for (var i = 0; i < 2; i++) {
  12314. var x_ = roots[i];
  12315. if (x_ + cx > x) {
  12316. var angle = Math.atan2(y, x_);
  12317. var dir = anticlockwise ? 1 : -1;
  12318. if (angle < 0) {
  12319. angle = PI2$1 + angle;
  12320. }
  12321. if (
  12322. (angle >= startAngle && angle <= endAngle)
  12323. || (angle + PI2$1 >= startAngle && angle + PI2$1 <= endAngle)
  12324. ) {
  12325. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  12326. dir = -dir;
  12327. }
  12328. w += dir;
  12329. }
  12330. }
  12331. }
  12332. return w;
  12333. }
  12334. function containPath(data, lineWidth, isStroke, x, y) {
  12335. var w = 0;
  12336. var xi = 0;
  12337. var yi = 0;
  12338. var x0 = 0;
  12339. var y0 = 0;
  12340. for (var i = 0; i < data.length;) {
  12341. var cmd = data[i++];
  12342. // Begin a new subpath
  12343. if (cmd === CMD$1.M && i > 1) {
  12344. // Close previous subpath
  12345. if (!isStroke) {
  12346. w += windingLine(xi, yi, x0, y0, x, y);
  12347. }
  12348. // 如果被任何一个 subpath 包含
  12349. // if (w !== 0) {
  12350. // return true;
  12351. // }
  12352. }
  12353. if (i === 1) {
  12354. // 如果第一个命令是 L, C, Q
  12355. // 则 previous point 同绘制命令的第一个 point
  12356. //
  12357. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12358. xi = data[i];
  12359. yi = data[i + 1];
  12360. x0 = xi;
  12361. y0 = yi;
  12362. }
  12363. switch (cmd) {
  12364. case CMD$1.M:
  12365. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  12366. // 在 closePath 的时候使用
  12367. x0 = data[i++];
  12368. y0 = data[i++];
  12369. xi = x0;
  12370. yi = y0;
  12371. break;
  12372. case CMD$1.L:
  12373. if (isStroke) {
  12374. if (containStroke$1(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  12375. return true;
  12376. }
  12377. }
  12378. else {
  12379. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  12380. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  12381. }
  12382. xi = data[i++];
  12383. yi = data[i++];
  12384. break;
  12385. case CMD$1.C:
  12386. if (isStroke) {
  12387. if (containStroke$2(xi, yi,
  12388. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12389. lineWidth, x, y
  12390. )) {
  12391. return true;
  12392. }
  12393. }
  12394. else {
  12395. w += windingCubic(
  12396. xi, yi,
  12397. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12398. x, y
  12399. ) || 0;
  12400. }
  12401. xi = data[i++];
  12402. yi = data[i++];
  12403. break;
  12404. case CMD$1.Q:
  12405. if (isStroke) {
  12406. if (containStroke$3(xi, yi,
  12407. data[i++], data[i++], data[i], data[i + 1],
  12408. lineWidth, x, y
  12409. )) {
  12410. return true;
  12411. }
  12412. }
  12413. else {
  12414. w += windingQuadratic(
  12415. xi, yi,
  12416. data[i++], data[i++], data[i], data[i + 1],
  12417. x, y
  12418. ) || 0;
  12419. }
  12420. xi = data[i++];
  12421. yi = data[i++];
  12422. break;
  12423. case CMD$1.A:
  12424. // TODO Arc 判断的开销比较大
  12425. var cx = data[i++];
  12426. var cy = data[i++];
  12427. var rx = data[i++];
  12428. var ry = data[i++];
  12429. var theta = data[i++];
  12430. var dTheta = data[i++];
  12431. // TODO Arc 旋转
  12432. i += 1;
  12433. var anticlockwise = 1 - data[i++];
  12434. var x1 = Math.cos(theta) * rx + cx;
  12435. var y1 = Math.sin(theta) * ry + cy;
  12436. // 不是直接使用 arc 命令
  12437. if (i > 1) {
  12438. w += windingLine(xi, yi, x1, y1, x, y);
  12439. }
  12440. else {
  12441. // 第一个命令起点还未定义
  12442. x0 = x1;
  12443. y0 = y1;
  12444. }
  12445. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  12446. var _x = (x - cx) * ry / rx + cx;
  12447. if (isStroke) {
  12448. if (containStroke$4(
  12449. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  12450. lineWidth, _x, y
  12451. )) {
  12452. return true;
  12453. }
  12454. }
  12455. else {
  12456. w += windingArc(
  12457. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  12458. _x, y
  12459. );
  12460. }
  12461. xi = Math.cos(theta + dTheta) * rx + cx;
  12462. yi = Math.sin(theta + dTheta) * ry + cy;
  12463. break;
  12464. case CMD$1.R:
  12465. x0 = xi = data[i++];
  12466. y0 = yi = data[i++];
  12467. var width = data[i++];
  12468. var height = data[i++];
  12469. var x1 = x0 + width;
  12470. var y1 = y0 + height;
  12471. if (isStroke) {
  12472. if (containStroke$1(x0, y0, x1, y0, lineWidth, x, y)
  12473. || containStroke$1(x1, y0, x1, y1, lineWidth, x, y)
  12474. || containStroke$1(x1, y1, x0, y1, lineWidth, x, y)
  12475. || containStroke$1(x0, y1, x0, y0, lineWidth, x, y)
  12476. ) {
  12477. return true;
  12478. }
  12479. }
  12480. else {
  12481. // FIXME Clockwise ?
  12482. w += windingLine(x1, y0, x1, y1, x, y);
  12483. w += windingLine(x0, y1, x0, y0, x, y);
  12484. }
  12485. break;
  12486. case CMD$1.Z:
  12487. if (isStroke) {
  12488. if (containStroke$1(
  12489. xi, yi, x0, y0, lineWidth, x, y
  12490. )) {
  12491. return true;
  12492. }
  12493. }
  12494. else {
  12495. // Close a subpath
  12496. w += windingLine(xi, yi, x0, y0, x, y);
  12497. // 如果被任何一个 subpath 包含
  12498. // FIXME subpaths may overlap
  12499. // if (w !== 0) {
  12500. // return true;
  12501. // }
  12502. }
  12503. xi = x0;
  12504. yi = y0;
  12505. break;
  12506. }
  12507. }
  12508. if (!isStroke && !isAroundEqual(yi, y0)) {
  12509. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  12510. }
  12511. return w !== 0;
  12512. }
  12513. function contain(pathData, x, y) {
  12514. return containPath(pathData, 0, false, x, y);
  12515. }
  12516. function containStroke(pathData, lineWidth, x, y) {
  12517. return containPath(pathData, lineWidth, true, x, y);
  12518. }
  12519. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  12520. var abs = Math.abs;
  12521. var pathProxyForDraw = new PathProxy(true);
  12522. /**
  12523. * @alias module:zrender/graphic/Path
  12524. * @extends module:zrender/graphic/Displayable
  12525. * @constructor
  12526. * @param {Object} opts
  12527. */
  12528. function Path(opts) {
  12529. Displayable.call(this, opts);
  12530. /**
  12531. * @type {module:zrender/core/PathProxy}
  12532. * @readOnly
  12533. */
  12534. this.path = null;
  12535. }
  12536. Path.prototype = {
  12537. constructor: Path,
  12538. type: 'path',
  12539. __dirtyPath: true,
  12540. strokeContainThreshold: 5,
  12541. /**
  12542. * See `module:zrender/src/graphic/helper/subPixelOptimize`.
  12543. * @type {boolean}
  12544. */
  12545. subPixelOptimize: false,
  12546. brush: function (ctx, prevEl) {
  12547. var style = this.style;
  12548. var path = this.path || pathProxyForDraw;
  12549. var hasStroke = style.hasStroke();
  12550. var hasFill = style.hasFill();
  12551. var fill = style.fill;
  12552. var stroke = style.stroke;
  12553. var hasFillGradient = hasFill && !!(fill.colorStops);
  12554. var hasStrokeGradient = hasStroke && !!(stroke.colorStops);
  12555. var hasFillPattern = hasFill && !!(fill.image);
  12556. var hasStrokePattern = hasStroke && !!(stroke.image);
  12557. style.bind(ctx, this, prevEl);
  12558. this.setTransform(ctx);
  12559. if (this.__dirty) {
  12560. var rect;
  12561. // Update gradient because bounding rect may changed
  12562. if (hasFillGradient) {
  12563. rect = rect || this.getBoundingRect();
  12564. this._fillGradient = style.getGradient(ctx, fill, rect);
  12565. }
  12566. if (hasStrokeGradient) {
  12567. rect = rect || this.getBoundingRect();
  12568. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  12569. }
  12570. }
  12571. // Use the gradient or pattern
  12572. if (hasFillGradient) {
  12573. // PENDING If may have affect the state
  12574. ctx.fillStyle = this._fillGradient;
  12575. }
  12576. else if (hasFillPattern) {
  12577. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  12578. }
  12579. if (hasStrokeGradient) {
  12580. ctx.strokeStyle = this._strokeGradient;
  12581. }
  12582. else if (hasStrokePattern) {
  12583. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  12584. }
  12585. var lineDash = style.lineDash;
  12586. var lineDashOffset = style.lineDashOffset;
  12587. var ctxLineDash = !!ctx.setLineDash;
  12588. // Update path sx, sy
  12589. var scale = this.getGlobalScale();
  12590. path.setScale(scale[0], scale[1]);
  12591. // Proxy context
  12592. // Rebuild path in following 2 cases
  12593. // 1. Path is dirty
  12594. // 2. Path needs javascript implemented lineDash stroking.
  12595. // In this case, lineDash information will not be saved in PathProxy
  12596. if (this.__dirtyPath
  12597. || (lineDash && !ctxLineDash && hasStroke)
  12598. ) {
  12599. path.beginPath(ctx);
  12600. // Setting line dash before build path
  12601. if (lineDash && !ctxLineDash) {
  12602. path.setLineDash(lineDash);
  12603. path.setLineDashOffset(lineDashOffset);
  12604. }
  12605. this.buildPath(path, this.shape, false);
  12606. // Clear path dirty flag
  12607. if (this.path) {
  12608. this.__dirtyPath = false;
  12609. }
  12610. }
  12611. else {
  12612. // Replay path building
  12613. ctx.beginPath();
  12614. this.path.rebuildPath(ctx);
  12615. }
  12616. if (hasFill) {
  12617. if (style.fillOpacity != null) {
  12618. var originalGlobalAlpha = ctx.globalAlpha;
  12619. ctx.globalAlpha = style.fillOpacity * style.opacity;
  12620. path.fill(ctx);
  12621. ctx.globalAlpha = originalGlobalAlpha;
  12622. }
  12623. else {
  12624. path.fill(ctx);
  12625. }
  12626. }
  12627. if (lineDash && ctxLineDash) {
  12628. ctx.setLineDash(lineDash);
  12629. ctx.lineDashOffset = lineDashOffset;
  12630. }
  12631. if (hasStroke) {
  12632. if (style.strokeOpacity != null) {
  12633. var originalGlobalAlpha = ctx.globalAlpha;
  12634. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  12635. path.stroke(ctx);
  12636. ctx.globalAlpha = originalGlobalAlpha;
  12637. }
  12638. else {
  12639. path.stroke(ctx);
  12640. }
  12641. }
  12642. if (lineDash && ctxLineDash) {
  12643. // PENDING
  12644. // Remove lineDash
  12645. ctx.setLineDash([]);
  12646. }
  12647. // Draw rect text
  12648. if (style.text != null) {
  12649. // Only restore transform when needs draw text.
  12650. this.restoreTransform(ctx);
  12651. this.drawRectText(ctx, this.getBoundingRect());
  12652. }
  12653. },
  12654. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  12655. // Like in circle
  12656. buildPath: function (ctx, shapeCfg, inBundle) {},
  12657. createPathProxy: function () {
  12658. this.path = new PathProxy();
  12659. },
  12660. getBoundingRect: function () {
  12661. var rect = this._rect;
  12662. var style = this.style;
  12663. var needsUpdateRect = !rect;
  12664. if (needsUpdateRect) {
  12665. var path = this.path;
  12666. if (!path) {
  12667. // Create path on demand.
  12668. path = this.path = new PathProxy();
  12669. }
  12670. if (this.__dirtyPath) {
  12671. path.beginPath();
  12672. this.buildPath(path, this.shape, false);
  12673. }
  12674. rect = path.getBoundingRect();
  12675. }
  12676. this._rect = rect;
  12677. if (style.hasStroke()) {
  12678. // Needs update rect with stroke lineWidth when
  12679. // 1. Element changes scale or lineWidth
  12680. // 2. Shape is changed
  12681. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  12682. if (this.__dirty || needsUpdateRect) {
  12683. rectWithStroke.copy(rect);
  12684. // FIXME Must after updateTransform
  12685. var w = style.lineWidth;
  12686. // PENDING, Min line width is needed when line is horizontal or vertical
  12687. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  12688. // Only add extra hover lineWidth when there are no fill
  12689. if (!style.hasFill()) {
  12690. w = Math.max(w, this.strokeContainThreshold || 4);
  12691. }
  12692. // Consider line width
  12693. // Line scale can't be 0;
  12694. if (lineScale > 1e-10) {
  12695. rectWithStroke.width += w / lineScale;
  12696. rectWithStroke.height += w / lineScale;
  12697. rectWithStroke.x -= w / lineScale / 2;
  12698. rectWithStroke.y -= w / lineScale / 2;
  12699. }
  12700. }
  12701. // Return rect with stroke
  12702. return rectWithStroke;
  12703. }
  12704. return rect;
  12705. },
  12706. contain: function (x, y) {
  12707. var localPos = this.transformCoordToLocal(x, y);
  12708. var rect = this.getBoundingRect();
  12709. var style = this.style;
  12710. x = localPos[0];
  12711. y = localPos[1];
  12712. if (rect.contain(x, y)) {
  12713. var pathData = this.path.data;
  12714. if (style.hasStroke()) {
  12715. var lineWidth = style.lineWidth;
  12716. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  12717. // Line scale can't be 0;
  12718. if (lineScale > 1e-10) {
  12719. // Only add extra hover lineWidth when there are no fill
  12720. if (!style.hasFill()) {
  12721. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  12722. }
  12723. if (containStroke(
  12724. pathData, lineWidth / lineScale, x, y
  12725. )) {
  12726. return true;
  12727. }
  12728. }
  12729. }
  12730. if (style.hasFill()) {
  12731. return contain(pathData, x, y);
  12732. }
  12733. }
  12734. return false;
  12735. },
  12736. /**
  12737. * @param {boolean} dirtyPath
  12738. */
  12739. dirty: function (dirtyPath) {
  12740. if (dirtyPath == null) {
  12741. dirtyPath = true;
  12742. }
  12743. // Only mark dirty, not mark clean
  12744. if (dirtyPath) {
  12745. this.__dirtyPath = dirtyPath;
  12746. this._rect = null;
  12747. }
  12748. this.__dirty = this.__dirtyText = true;
  12749. this.__zr && this.__zr.refresh();
  12750. // Used as a clipping path
  12751. if (this.__clipTarget) {
  12752. this.__clipTarget.dirty();
  12753. }
  12754. },
  12755. /**
  12756. * Alias for animate('shape')
  12757. * @param {boolean} loop
  12758. */
  12759. animateShape: function (loop) {
  12760. return this.animate('shape', loop);
  12761. },
  12762. // Overwrite attrKV
  12763. attrKV: function (key, value) {
  12764. // FIXME
  12765. if (key === 'shape') {
  12766. this.setShape(value);
  12767. this.__dirtyPath = true;
  12768. this._rect = null;
  12769. }
  12770. else {
  12771. Displayable.prototype.attrKV.call(this, key, value);
  12772. }
  12773. },
  12774. /**
  12775. * @param {Object|string} key
  12776. * @param {*} value
  12777. */
  12778. setShape: function (key, value) {
  12779. var shape = this.shape;
  12780. // Path from string may not have shape
  12781. if (shape) {
  12782. if (isObject$1(key)) {
  12783. for (var name in key) {
  12784. if (key.hasOwnProperty(name)) {
  12785. shape[name] = key[name];
  12786. }
  12787. }
  12788. }
  12789. else {
  12790. shape[key] = value;
  12791. }
  12792. this.dirty(true);
  12793. }
  12794. return this;
  12795. },
  12796. getLineScale: function () {
  12797. var m = this.transform;
  12798. // Get the line scale.
  12799. // Determinant of `m` means how much the area is enlarged by the
  12800. // transformation. So its square root can be used as a scale factor
  12801. // for width.
  12802. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  12803. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  12804. : 1;
  12805. }
  12806. };
  12807. /**
  12808. * 扩展一个 Path element, 比如星形,圆等。
  12809. * Extend a path element
  12810. * @param {Object} props
  12811. * @param {string} props.type Path type
  12812. * @param {Function} props.init Initialize
  12813. * @param {Function} props.buildPath Overwrite buildPath method
  12814. * @param {Object} [props.style] Extended default style config
  12815. * @param {Object} [props.shape] Extended default shape config
  12816. */
  12817. Path.extend = function (defaults$$1) {
  12818. var Sub = function (opts) {
  12819. Path.call(this, opts);
  12820. if (defaults$$1.style) {
  12821. // Extend default style
  12822. this.style.extendFrom(defaults$$1.style, false);
  12823. }
  12824. // Extend default shape
  12825. var defaultShape = defaults$$1.shape;
  12826. if (defaultShape) {
  12827. this.shape = this.shape || {};
  12828. var thisShape = this.shape;
  12829. for (var name in defaultShape) {
  12830. if (
  12831. !thisShape.hasOwnProperty(name)
  12832. && defaultShape.hasOwnProperty(name)
  12833. ) {
  12834. thisShape[name] = defaultShape[name];
  12835. }
  12836. }
  12837. }
  12838. defaults$$1.init && defaults$$1.init.call(this, opts);
  12839. };
  12840. inherits(Sub, Path);
  12841. // FIXME 不能 extend position, rotation 等引用对象
  12842. for (var name in defaults$$1) {
  12843. // Extending prototype values and methods
  12844. if (name !== 'style' && name !== 'shape') {
  12845. Sub.prototype[name] = defaults$$1[name];
  12846. }
  12847. }
  12848. return Sub;
  12849. };
  12850. inherits(Path, Displayable);
  12851. var CMD$2 = PathProxy.CMD;
  12852. var points = [[], [], []];
  12853. var mathSqrt$3 = Math.sqrt;
  12854. var mathAtan2 = Math.atan2;
  12855. var transformPath = function (path, m) {
  12856. var data = path.data;
  12857. var cmd;
  12858. var nPoint;
  12859. var i;
  12860. var j;
  12861. var k;
  12862. var p;
  12863. var M = CMD$2.M;
  12864. var C = CMD$2.C;
  12865. var L = CMD$2.L;
  12866. var R = CMD$2.R;
  12867. var A = CMD$2.A;
  12868. var Q = CMD$2.Q;
  12869. for (i = 0, j = 0; i < data.length;) {
  12870. cmd = data[i++];
  12871. j = i;
  12872. nPoint = 0;
  12873. switch (cmd) {
  12874. case M:
  12875. nPoint = 1;
  12876. break;
  12877. case L:
  12878. nPoint = 1;
  12879. break;
  12880. case C:
  12881. nPoint = 3;
  12882. break;
  12883. case Q:
  12884. nPoint = 2;
  12885. break;
  12886. case A:
  12887. var x = m[4];
  12888. var y = m[5];
  12889. var sx = mathSqrt$3(m[0] * m[0] + m[1] * m[1]);
  12890. var sy = mathSqrt$3(m[2] * m[2] + m[3] * m[3]);
  12891. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  12892. // cx
  12893. data[i] *= sx;
  12894. data[i++] += x;
  12895. // cy
  12896. data[i] *= sy;
  12897. data[i++] += y;
  12898. // Scale rx and ry
  12899. // FIXME Assume psi is 0 here
  12900. data[i++] *= sx;
  12901. data[i++] *= sy;
  12902. // Start angle
  12903. data[i++] += angle;
  12904. // end angle
  12905. data[i++] += angle;
  12906. // FIXME psi
  12907. i += 2;
  12908. j = i;
  12909. break;
  12910. case R:
  12911. // x0, y0
  12912. p[0] = data[i++];
  12913. p[1] = data[i++];
  12914. applyTransform(p, p, m);
  12915. data[j++] = p[0];
  12916. data[j++] = p[1];
  12917. // x1, y1
  12918. p[0] += data[i++];
  12919. p[1] += data[i++];
  12920. applyTransform(p, p, m);
  12921. data[j++] = p[0];
  12922. data[j++] = p[1];
  12923. }
  12924. for (k = 0; k < nPoint; k++) {
  12925. var p = points[k];
  12926. p[0] = data[i++];
  12927. p[1] = data[i++];
  12928. applyTransform(p, p, m);
  12929. // Write back
  12930. data[j++] = p[0];
  12931. data[j++] = p[1];
  12932. }
  12933. }
  12934. };
  12935. // command chars
  12936. // var cc = [
  12937. // 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  12938. // 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  12939. // ];
  12940. var mathSqrt = Math.sqrt;
  12941. var mathSin = Math.sin;
  12942. var mathCos = Math.cos;
  12943. var PI = Math.PI;
  12944. var vMag = function (v) {
  12945. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  12946. };
  12947. var vRatio = function (u, v) {
  12948. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  12949. };
  12950. var vAngle = function (u, v) {
  12951. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  12952. * Math.acos(vRatio(u, v));
  12953. };
  12954. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  12955. var psi = psiDeg * (PI / 180.0);
  12956. var xp = mathCos(psi) * (x1 - x2) / 2.0
  12957. + mathSin(psi) * (y1 - y2) / 2.0;
  12958. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0
  12959. + mathCos(psi) * (y1 - y2) / 2.0;
  12960. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  12961. if (lambda > 1) {
  12962. rx *= mathSqrt(lambda);
  12963. ry *= mathSqrt(lambda);
  12964. }
  12965. var f = (fa === fs ? -1 : 1)
  12966. * mathSqrt((((rx * rx) * (ry * ry))
  12967. - ((rx * rx) * (yp * yp))
  12968. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  12969. + (ry * ry) * (xp * xp))
  12970. ) || 0;
  12971. var cxp = f * rx * yp / ry;
  12972. var cyp = f * -ry * xp / rx;
  12973. var cx = (x1 + x2) / 2.0
  12974. + mathCos(psi) * cxp
  12975. - mathSin(psi) * cyp;
  12976. var cy = (y1 + y2) / 2.0
  12977. + mathSin(psi) * cxp
  12978. + mathCos(psi) * cyp;
  12979. var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);
  12980. var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];
  12981. var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];
  12982. var dTheta = vAngle(u, v);
  12983. if (vRatio(u, v) <= -1) {
  12984. dTheta = PI;
  12985. }
  12986. if (vRatio(u, v) >= 1) {
  12987. dTheta = 0;
  12988. }
  12989. if (fs === 0 && dTheta > 0) {
  12990. dTheta = dTheta - 2 * PI;
  12991. }
  12992. if (fs === 1 && dTheta < 0) {
  12993. dTheta = dTheta + 2 * PI;
  12994. }
  12995. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  12996. }
  12997. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  12998. // Consider case:
  12999. // (1) delimiter can be comma or space, where continuous commas
  13000. // or spaces should be seen as one comma.
  13001. // (2) value can be like:
  13002. // '2e-4', 'l.5.9' (ignore 0), 'M-10-10', 'l-2.43e-1,34.9983',
  13003. // 'l-.5E1,54', '121-23-44-11' (no delimiter)
  13004. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  13005. // var valueSplitReg = /[\s,]+/;
  13006. function createPathProxyFromString(data) {
  13007. if (!data) {
  13008. return new PathProxy();
  13009. }
  13010. // var data = data.replace(/-/g, ' -')
  13011. // .replace(/ /g, ' ')
  13012. // .replace(/ /g, ',')
  13013. // .replace(/,,/g, ',');
  13014. // var n;
  13015. // create pipes so that we can split the data
  13016. // for (n = 0; n < cc.length; n++) {
  13017. // cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  13018. // }
  13019. // data = data.replace(/-/g, ',-');
  13020. // create array
  13021. // var arr = cs.split('|');
  13022. // init context point
  13023. var cpx = 0;
  13024. var cpy = 0;
  13025. var subpathX = cpx;
  13026. var subpathY = cpy;
  13027. var prevCmd;
  13028. var path = new PathProxy();
  13029. var CMD = PathProxy.CMD;
  13030. // commandReg.lastIndex = 0;
  13031. // var cmdResult;
  13032. // while ((cmdResult = commandReg.exec(data)) != null) {
  13033. // var cmdStr = cmdResult[1];
  13034. // var cmdContent = cmdResult[2];
  13035. var cmdList = data.match(commandReg);
  13036. for (var l = 0; l < cmdList.length; l++) {
  13037. var cmdText = cmdList[l];
  13038. var cmdStr = cmdText.charAt(0);
  13039. var cmd;
  13040. // String#split is faster a little bit than String#replace or RegExp#exec.
  13041. // var p = cmdContent.split(valueSplitReg);
  13042. // var pLen = 0;
  13043. // for (var i = 0; i < p.length; i++) {
  13044. // // '' and other invalid str => NaN
  13045. // var val = parseFloat(p[i]);
  13046. // !isNaN(val) && (p[pLen++] = val);
  13047. // }
  13048. var p = cmdText.match(numberReg) || [];
  13049. var pLen = p.length;
  13050. for (var i = 0; i < pLen; i++) {
  13051. p[i] = parseFloat(p[i]);
  13052. }
  13053. var off = 0;
  13054. while (off < pLen) {
  13055. var ctlPtx;
  13056. var ctlPty;
  13057. var rx;
  13058. var ry;
  13059. var psi;
  13060. var fa;
  13061. var fs;
  13062. var x1 = cpx;
  13063. var y1 = cpy;
  13064. // convert l, H, h, V, and v to L
  13065. switch (cmdStr) {
  13066. case 'l':
  13067. cpx += p[off++];
  13068. cpy += p[off++];
  13069. cmd = CMD.L;
  13070. path.addData(cmd, cpx, cpy);
  13071. break;
  13072. case 'L':
  13073. cpx = p[off++];
  13074. cpy = p[off++];
  13075. cmd = CMD.L;
  13076. path.addData(cmd, cpx, cpy);
  13077. break;
  13078. case 'm':
  13079. cpx += p[off++];
  13080. cpy += p[off++];
  13081. cmd = CMD.M;
  13082. path.addData(cmd, cpx, cpy);
  13083. subpathX = cpx;
  13084. subpathY = cpy;
  13085. cmdStr = 'l';
  13086. break;
  13087. case 'M':
  13088. cpx = p[off++];
  13089. cpy = p[off++];
  13090. cmd = CMD.M;
  13091. path.addData(cmd, cpx, cpy);
  13092. subpathX = cpx;
  13093. subpathY = cpy;
  13094. cmdStr = 'L';
  13095. break;
  13096. case 'h':
  13097. cpx += p[off++];
  13098. cmd = CMD.L;
  13099. path.addData(cmd, cpx, cpy);
  13100. break;
  13101. case 'H':
  13102. cpx = p[off++];
  13103. cmd = CMD.L;
  13104. path.addData(cmd, cpx, cpy);
  13105. break;
  13106. case 'v':
  13107. cpy += p[off++];
  13108. cmd = CMD.L;
  13109. path.addData(cmd, cpx, cpy);
  13110. break;
  13111. case 'V':
  13112. cpy = p[off++];
  13113. cmd = CMD.L;
  13114. path.addData(cmd, cpx, cpy);
  13115. break;
  13116. case 'C':
  13117. cmd = CMD.C;
  13118. path.addData(
  13119. cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]
  13120. );
  13121. cpx = p[off - 2];
  13122. cpy = p[off - 1];
  13123. break;
  13124. case 'c':
  13125. cmd = CMD.C;
  13126. path.addData(
  13127. cmd,
  13128. p[off++] + cpx, p[off++] + cpy,
  13129. p[off++] + cpx, p[off++] + cpy,
  13130. p[off++] + cpx, p[off++] + cpy
  13131. );
  13132. cpx += p[off - 2];
  13133. cpy += p[off - 1];
  13134. break;
  13135. case 'S':
  13136. ctlPtx = cpx;
  13137. ctlPty = cpy;
  13138. var len = path.len();
  13139. var pathData = path.data;
  13140. if (prevCmd === CMD.C) {
  13141. ctlPtx += cpx - pathData[len - 4];
  13142. ctlPty += cpy - pathData[len - 3];
  13143. }
  13144. cmd = CMD.C;
  13145. x1 = p[off++];
  13146. y1 = p[off++];
  13147. cpx = p[off++];
  13148. cpy = p[off++];
  13149. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13150. break;
  13151. case 's':
  13152. ctlPtx = cpx;
  13153. ctlPty = cpy;
  13154. var len = path.len();
  13155. var pathData = path.data;
  13156. if (prevCmd === CMD.C) {
  13157. ctlPtx += cpx - pathData[len - 4];
  13158. ctlPty += cpy - pathData[len - 3];
  13159. }
  13160. cmd = CMD.C;
  13161. x1 = cpx + p[off++];
  13162. y1 = cpy + p[off++];
  13163. cpx += p[off++];
  13164. cpy += p[off++];
  13165. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13166. break;
  13167. case 'Q':
  13168. x1 = p[off++];
  13169. y1 = p[off++];
  13170. cpx = p[off++];
  13171. cpy = p[off++];
  13172. cmd = CMD.Q;
  13173. path.addData(cmd, x1, y1, cpx, cpy);
  13174. break;
  13175. case 'q':
  13176. x1 = p[off++] + cpx;
  13177. y1 = p[off++] + cpy;
  13178. cpx += p[off++];
  13179. cpy += p[off++];
  13180. cmd = CMD.Q;
  13181. path.addData(cmd, x1, y1, cpx, cpy);
  13182. break;
  13183. case 'T':
  13184. ctlPtx = cpx;
  13185. ctlPty = cpy;
  13186. var len = path.len();
  13187. var pathData = path.data;
  13188. if (prevCmd === CMD.Q) {
  13189. ctlPtx += cpx - pathData[len - 4];
  13190. ctlPty += cpy - pathData[len - 3];
  13191. }
  13192. cpx = p[off++];
  13193. cpy = p[off++];
  13194. cmd = CMD.Q;
  13195. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13196. break;
  13197. case 't':
  13198. ctlPtx = cpx;
  13199. ctlPty = cpy;
  13200. var len = path.len();
  13201. var pathData = path.data;
  13202. if (prevCmd === CMD.Q) {
  13203. ctlPtx += cpx - pathData[len - 4];
  13204. ctlPty += cpy - pathData[len - 3];
  13205. }
  13206. cpx += p[off++];
  13207. cpy += p[off++];
  13208. cmd = CMD.Q;
  13209. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13210. break;
  13211. case 'A':
  13212. rx = p[off++];
  13213. ry = p[off++];
  13214. psi = p[off++];
  13215. fa = p[off++];
  13216. fs = p[off++];
  13217. x1 = cpx, y1 = cpy;
  13218. cpx = p[off++];
  13219. cpy = p[off++];
  13220. cmd = CMD.A;
  13221. processArc(
  13222. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  13223. );
  13224. break;
  13225. case 'a':
  13226. rx = p[off++];
  13227. ry = p[off++];
  13228. psi = p[off++];
  13229. fa = p[off++];
  13230. fs = p[off++];
  13231. x1 = cpx, y1 = cpy;
  13232. cpx += p[off++];
  13233. cpy += p[off++];
  13234. cmd = CMD.A;
  13235. processArc(
  13236. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  13237. );
  13238. break;
  13239. }
  13240. }
  13241. if (cmdStr === 'z' || cmdStr === 'Z') {
  13242. cmd = CMD.Z;
  13243. path.addData(cmd);
  13244. // z may be in the middle of the path.
  13245. cpx = subpathX;
  13246. cpy = subpathY;
  13247. }
  13248. prevCmd = cmd;
  13249. }
  13250. path.toStatic();
  13251. return path;
  13252. }
  13253. // TODO Optimize double memory cost problem
  13254. function createPathOptions(str, opts) {
  13255. var pathProxy = createPathProxyFromString(str);
  13256. opts = opts || {};
  13257. opts.buildPath = function (path) {
  13258. if (path.setData) {
  13259. path.setData(pathProxy.data);
  13260. // Svg and vml renderer don't have context
  13261. var ctx = path.getContext();
  13262. if (ctx) {
  13263. path.rebuildPath(ctx);
  13264. }
  13265. }
  13266. else {
  13267. var ctx = path;
  13268. pathProxy.rebuildPath(ctx);
  13269. }
  13270. };
  13271. opts.applyTransform = function (m) {
  13272. transformPath(pathProxy, m);
  13273. this.dirty(true);
  13274. };
  13275. return opts;
  13276. }
  13277. /**
  13278. * Create a Path object from path string data
  13279. * http://www.w3.org/TR/SVG/paths.html#PathData
  13280. * @param {Object} opts Other options
  13281. */
  13282. function createFromString(str, opts) {
  13283. return new Path(createPathOptions(str, opts));
  13284. }
  13285. /**
  13286. * Create a Path class from path string data
  13287. * @param {string} str
  13288. * @param {Object} opts Other options
  13289. */
  13290. function extendFromString(str, opts) {
  13291. return Path.extend(createPathOptions(str, opts));
  13292. }
  13293. /**
  13294. * Merge multiple paths
  13295. */
  13296. // TODO Apply transform
  13297. // TODO stroke dash
  13298. // TODO Optimize double memory cost problem
  13299. function mergePath$1(pathEls, opts) {
  13300. var pathList = [];
  13301. var len = pathEls.length;
  13302. for (var i = 0; i < len; i++) {
  13303. var pathEl = pathEls[i];
  13304. if (!pathEl.path) {
  13305. pathEl.createPathProxy();
  13306. }
  13307. if (pathEl.__dirtyPath) {
  13308. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  13309. }
  13310. pathList.push(pathEl.path);
  13311. }
  13312. var pathBundle = new Path(opts);
  13313. // Need path proxy.
  13314. pathBundle.createPathProxy();
  13315. pathBundle.buildPath = function (path) {
  13316. path.appendPath(pathList);
  13317. // Svg and vml renderer don't have context
  13318. var ctx = path.getContext();
  13319. if (ctx) {
  13320. path.rebuildPath(ctx);
  13321. }
  13322. };
  13323. return pathBundle;
  13324. }
  13325. /**
  13326. * @alias zrender/graphic/Text
  13327. * @extends module:zrender/graphic/Displayable
  13328. * @constructor
  13329. * @param {Object} opts
  13330. */
  13331. var Text = function (opts) { // jshint ignore:line
  13332. Displayable.call(this, opts);
  13333. };
  13334. Text.prototype = {
  13335. constructor: Text,
  13336. type: 'text',
  13337. brush: function (ctx, prevEl) {
  13338. var style = this.style;
  13339. // Optimize, avoid normalize every time.
  13340. this.__dirty && normalizeTextStyle(style, true);
  13341. // Use props with prefix 'text'.
  13342. style.fill = style.stroke = style.shadowBlur = style.shadowColor =
  13343. style.shadowOffsetX = style.shadowOffsetY = null;
  13344. var text = style.text;
  13345. // Convert to string
  13346. text != null && (text += '');
  13347. // Do not apply style.bind in Text node. Because the real bind job
  13348. // is in textHelper.renderText, and performance of text render should
  13349. // be considered.
  13350. // style.bind(ctx, this, prevEl);
  13351. if (!needDrawText(text, style)) {
  13352. // The current el.style is not applied
  13353. // and should not be used as cache.
  13354. ctx.__attrCachedBy = ContextCachedBy.NONE;
  13355. return;
  13356. }
  13357. this.setTransform(ctx);
  13358. renderText(this, ctx, text, style, null, prevEl);
  13359. this.restoreTransform(ctx);
  13360. },
  13361. getBoundingRect: function () {
  13362. var style = this.style;
  13363. // Optimize, avoid normalize every time.
  13364. this.__dirty && normalizeTextStyle(style, true);
  13365. if (!this._rect) {
  13366. var text = style.text;
  13367. text != null ? (text += '') : (text = '');
  13368. var rect = getBoundingRect(
  13369. style.text + '',
  13370. style.font,
  13371. style.textAlign,
  13372. style.textVerticalAlign,
  13373. style.textPadding,
  13374. style.textLineHeight,
  13375. style.rich
  13376. );
  13377. rect.x += style.x || 0;
  13378. rect.y += style.y || 0;
  13379. if (getStroke(style.textStroke, style.textStrokeWidth)) {
  13380. var w = style.textStrokeWidth;
  13381. rect.x -= w / 2;
  13382. rect.y -= w / 2;
  13383. rect.width += w;
  13384. rect.height += w;
  13385. }
  13386. this._rect = rect;
  13387. }
  13388. return this._rect;
  13389. }
  13390. };
  13391. inherits(Text, Displayable);
  13392. /**
  13393. * 圆形
  13394. * @module zrender/shape/Circle
  13395. */
  13396. var Circle = Path.extend({
  13397. type: 'circle',
  13398. shape: {
  13399. cx: 0,
  13400. cy: 0,
  13401. r: 0
  13402. },
  13403. buildPath: function (ctx, shape, inBundle) {
  13404. // Better stroking in ShapeBundle
  13405. // Always do it may have performence issue ( fill may be 2x more cost)
  13406. if (inBundle) {
  13407. ctx.moveTo(shape.cx + shape.r, shape.cy);
  13408. }
  13409. // else {
  13410. // if (ctx.allocate && !ctx.data.length) {
  13411. // ctx.allocate(ctx.CMD_MEM_SIZE.A);
  13412. // }
  13413. // }
  13414. // Better stroking in ShapeBundle
  13415. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  13416. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  13417. }
  13418. });
  13419. // Fix weird bug in some version of IE11 (like 11.0.9600.178**),
  13420. // where exception "unexpected call to method or property access"
  13421. // might be thrown when calling ctx.fill or ctx.stroke after a path
  13422. // whose area size is zero is drawn and ctx.clip() is called and
  13423. // shadowBlur is set. See #4572, #3112, #5777.
  13424. // (e.g.,
  13425. // ctx.moveTo(10, 10);
  13426. // ctx.lineTo(20, 10);
  13427. // ctx.closePath();
  13428. // ctx.clip();
  13429. // ctx.shadowBlur = 10;
  13430. // ...
  13431. // ctx.fill();
  13432. // )
  13433. var shadowTemp = [
  13434. ['shadowBlur', 0],
  13435. ['shadowColor', '#000'],
  13436. ['shadowOffsetX', 0],
  13437. ['shadowOffsetY', 0]
  13438. ];
  13439. var fixClipWithShadow = function (orignalBrush) {
  13440. // version string can be: '11.0'
  13441. return (env$1.browser.ie && env$1.browser.version >= 11)
  13442. ? function () {
  13443. var clipPaths = this.__clipPaths;
  13444. var style = this.style;
  13445. var modified;
  13446. if (clipPaths) {
  13447. for (var i = 0; i < clipPaths.length; i++) {
  13448. var clipPath = clipPaths[i];
  13449. var shape = clipPath && clipPath.shape;
  13450. var type = clipPath && clipPath.type;
  13451. if (shape && (
  13452. (type === 'sector' && shape.startAngle === shape.endAngle)
  13453. || (type === 'rect' && (!shape.width || !shape.height))
  13454. )) {
  13455. for (var j = 0; j < shadowTemp.length; j++) {
  13456. // It is save to put shadowTemp static, because shadowTemp
  13457. // will be all modified each item brush called.
  13458. shadowTemp[j][2] = style[shadowTemp[j][0]];
  13459. style[shadowTemp[j][0]] = shadowTemp[j][1];
  13460. }
  13461. modified = true;
  13462. break;
  13463. }
  13464. }
  13465. }
  13466. orignalBrush.apply(this, arguments);
  13467. if (modified) {
  13468. for (var j = 0; j < shadowTemp.length; j++) {
  13469. style[shadowTemp[j][0]] = shadowTemp[j][2];
  13470. }
  13471. }
  13472. }
  13473. : orignalBrush;
  13474. };
  13475. /**
  13476. * 扇形
  13477. * @module zrender/graphic/shape/Sector
  13478. */
  13479. var Sector = Path.extend({
  13480. type: 'sector',
  13481. shape: {
  13482. cx: 0,
  13483. cy: 0,
  13484. r0: 0,
  13485. r: 0,
  13486. startAngle: 0,
  13487. endAngle: Math.PI * 2,
  13488. clockwise: true
  13489. },
  13490. brush: fixClipWithShadow(Path.prototype.brush),
  13491. buildPath: function (ctx, shape) {
  13492. var x = shape.cx;
  13493. var y = shape.cy;
  13494. var r0 = Math.max(shape.r0 || 0, 0);
  13495. var r = Math.max(shape.r, 0);
  13496. var startAngle = shape.startAngle;
  13497. var endAngle = shape.endAngle;
  13498. var clockwise = shape.clockwise;
  13499. var unitX = Math.cos(startAngle);
  13500. var unitY = Math.sin(startAngle);
  13501. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  13502. ctx.lineTo(unitX * r + x, unitY * r + y);
  13503. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13504. ctx.lineTo(
  13505. Math.cos(endAngle) * r0 + x,
  13506. Math.sin(endAngle) * r0 + y
  13507. );
  13508. if (r0 !== 0) {
  13509. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  13510. }
  13511. ctx.closePath();
  13512. }
  13513. });
  13514. /**
  13515. * 圆环
  13516. * @module zrender/graphic/shape/Ring
  13517. */
  13518. var Ring = Path.extend({
  13519. type: 'ring',
  13520. shape: {
  13521. cx: 0,
  13522. cy: 0,
  13523. r: 0,
  13524. r0: 0
  13525. },
  13526. buildPath: function (ctx, shape) {
  13527. var x = shape.cx;
  13528. var y = shape.cy;
  13529. var PI2 = Math.PI * 2;
  13530. ctx.moveTo(x + shape.r, y);
  13531. ctx.arc(x, y, shape.r, 0, PI2, false);
  13532. ctx.moveTo(x + shape.r0, y);
  13533. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13534. }
  13535. });
  13536. /**
  13537. * Catmull-Rom spline 插值折线
  13538. * @module zrender/shape/util/smoothSpline
  13539. * @author pissang (https://www.github.com/pissang)
  13540. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13541. * errorrik (errorrik@gmail.com)
  13542. */
  13543. /**
  13544. * @inner
  13545. */
  13546. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  13547. var v0 = (p2 - p0) * 0.5;
  13548. var v1 = (p3 - p1) * 0.5;
  13549. return (2 * (p1 - p2) + v0 + v1) * t3
  13550. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  13551. + v0 * t + p1;
  13552. }
  13553. /**
  13554. * @alias module:zrender/shape/util/smoothSpline
  13555. * @param {Array} points 线段顶点数组
  13556. * @param {boolean} isLoop
  13557. * @return {Array}
  13558. */
  13559. var smoothSpline = function (points, isLoop) {
  13560. var len$$1 = points.length;
  13561. var ret = [];
  13562. var distance$$1 = 0;
  13563. for (var i = 1; i < len$$1; i++) {
  13564. distance$$1 += distance(points[i - 1], points[i]);
  13565. }
  13566. var segs = distance$$1 / 2;
  13567. segs = segs < len$$1 ? len$$1 : segs;
  13568. for (var i = 0; i < segs; i++) {
  13569. var pos = i / (segs - 1) * (isLoop ? len$$1 : len$$1 - 1);
  13570. var idx = Math.floor(pos);
  13571. var w = pos - idx;
  13572. var p0;
  13573. var p1 = points[idx % len$$1];
  13574. var p2;
  13575. var p3;
  13576. if (!isLoop) {
  13577. p0 = points[idx === 0 ? idx : idx - 1];
  13578. p2 = points[idx > len$$1 - 2 ? len$$1 - 1 : idx + 1];
  13579. p3 = points[idx > len$$1 - 3 ? len$$1 - 1 : idx + 2];
  13580. }
  13581. else {
  13582. p0 = points[(idx - 1 + len$$1) % len$$1];
  13583. p2 = points[(idx + 1) % len$$1];
  13584. p3 = points[(idx + 2) % len$$1];
  13585. }
  13586. var w2 = w * w;
  13587. var w3 = w * w2;
  13588. ret.push([
  13589. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  13590. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  13591. ]);
  13592. }
  13593. return ret;
  13594. };
  13595. /**
  13596. * 贝塞尔平滑曲线
  13597. * @module zrender/shape/util/smoothBezier
  13598. * @author pissang (https://www.github.com/pissang)
  13599. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13600. * errorrik (errorrik@gmail.com)
  13601. */
  13602. /**
  13603. * 贝塞尔平滑曲线
  13604. * @alias module:zrender/shape/util/smoothBezier
  13605. * @param {Array} points 线段顶点数组
  13606. * @param {number} smooth 平滑等级, 0-1
  13607. * @param {boolean} isLoop
  13608. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  13609. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  13610. * 整个折线的包围盒做一个并集用来约束控制点。
  13611. * @param {Array} 计算出来的控制点数组
  13612. */
  13613. var smoothBezier = function (points, smooth, isLoop, constraint) {
  13614. var cps = [];
  13615. var v = [];
  13616. var v1 = [];
  13617. var v2 = [];
  13618. var prevPoint;
  13619. var nextPoint;
  13620. var min$$1;
  13621. var max$$1;
  13622. if (constraint) {
  13623. min$$1 = [Infinity, Infinity];
  13624. max$$1 = [-Infinity, -Infinity];
  13625. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13626. min(min$$1, min$$1, points[i]);
  13627. max(max$$1, max$$1, points[i]);
  13628. }
  13629. // 与指定的包围盒做并集
  13630. min(min$$1, min$$1, constraint[0]);
  13631. max(max$$1, max$$1, constraint[1]);
  13632. }
  13633. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13634. var point = points[i];
  13635. if (isLoop) {
  13636. prevPoint = points[i ? i - 1 : len$$1 - 1];
  13637. nextPoint = points[(i + 1) % len$$1];
  13638. }
  13639. else {
  13640. if (i === 0 || i === len$$1 - 1) {
  13641. cps.push(clone$1(points[i]));
  13642. continue;
  13643. }
  13644. else {
  13645. prevPoint = points[i - 1];
  13646. nextPoint = points[i + 1];
  13647. }
  13648. }
  13649. sub(v, nextPoint, prevPoint);
  13650. // use degree to scale the handle length
  13651. scale(v, v, smooth);
  13652. var d0 = distance(point, prevPoint);
  13653. var d1 = distance(point, nextPoint);
  13654. var sum = d0 + d1;
  13655. if (sum !== 0) {
  13656. d0 /= sum;
  13657. d1 /= sum;
  13658. }
  13659. scale(v1, v, -d0);
  13660. scale(v2, v, d1);
  13661. var cp0 = add([], point, v1);
  13662. var cp1 = add([], point, v2);
  13663. if (constraint) {
  13664. max(cp0, cp0, min$$1);
  13665. min(cp0, cp0, max$$1);
  13666. max(cp1, cp1, min$$1);
  13667. min(cp1, cp1, max$$1);
  13668. }
  13669. cps.push(cp0);
  13670. cps.push(cp1);
  13671. }
  13672. if (isLoop) {
  13673. cps.push(cps.shift());
  13674. }
  13675. return cps;
  13676. };
  13677. function buildPath$1(ctx, shape, closePath) {
  13678. var points = shape.points;
  13679. var smooth = shape.smooth;
  13680. if (points && points.length >= 2) {
  13681. if (smooth && smooth !== 'spline') {
  13682. var controlPoints = smoothBezier(
  13683. points, smooth, closePath, shape.smoothConstraint
  13684. );
  13685. ctx.moveTo(points[0][0], points[0][1]);
  13686. var len = points.length;
  13687. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  13688. var cp1 = controlPoints[i * 2];
  13689. var cp2 = controlPoints[i * 2 + 1];
  13690. var p = points[(i + 1) % len];
  13691. ctx.bezierCurveTo(
  13692. cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]
  13693. );
  13694. }
  13695. }
  13696. else {
  13697. if (smooth === 'spline') {
  13698. points = smoothSpline(points, closePath);
  13699. }
  13700. ctx.moveTo(points[0][0], points[0][1]);
  13701. for (var i = 1, l = points.length; i < l; i++) {
  13702. ctx.lineTo(points[i][0], points[i][1]);
  13703. }
  13704. }
  13705. closePath && ctx.closePath();
  13706. }
  13707. }
  13708. /**
  13709. * 多边形
  13710. * @module zrender/shape/Polygon
  13711. */
  13712. var Polygon = Path.extend({
  13713. type: 'polygon',
  13714. shape: {
  13715. points: null,
  13716. smooth: false,
  13717. smoothConstraint: null
  13718. },
  13719. buildPath: function (ctx, shape) {
  13720. buildPath$1(ctx, shape, true);
  13721. }
  13722. });
  13723. /**
  13724. * @module zrender/graphic/shape/Polyline
  13725. */
  13726. var Polyline = Path.extend({
  13727. type: 'polyline',
  13728. shape: {
  13729. points: null,
  13730. smooth: false,
  13731. smoothConstraint: null
  13732. },
  13733. style: {
  13734. stroke: '#000',
  13735. fill: null
  13736. },
  13737. buildPath: function (ctx, shape) {
  13738. buildPath$1(ctx, shape, false);
  13739. }
  13740. });
  13741. /**
  13742. * Sub-pixel optimize for canvas rendering, prevent from blur
  13743. * when rendering a thin vertical/horizontal line.
  13744. */
  13745. var round$1 = Math.round;
  13746. /**
  13747. * Sub pixel optimize line for canvas
  13748. *
  13749. * @param {Object} outputShape The modification will be performed on `outputShape`.
  13750. * `outputShape` and `inputShape` can be the same object.
  13751. * `outputShape` object can be used repeatly, because all of
  13752. * the `x1`, `x2`, `y1`, `y2` will be assigned in this method.
  13753. * @param {Object} [inputShape]
  13754. * @param {number} [inputShape.x1]
  13755. * @param {number} [inputShape.y1]
  13756. * @param {number} [inputShape.x2]
  13757. * @param {number} [inputShape.y2]
  13758. * @param {Object} [style]
  13759. * @param {number} [style.lineWidth]
  13760. */
  13761. function subPixelOptimizeLine$1(outputShape, inputShape, style) {
  13762. var lineWidth = style && style.lineWidth;
  13763. if (!inputShape || !lineWidth) {
  13764. return;
  13765. }
  13766. var x1 = inputShape.x1;
  13767. var x2 = inputShape.x2;
  13768. var y1 = inputShape.y1;
  13769. var y2 = inputShape.y2;
  13770. if (round$1(x1 * 2) === round$1(x2 * 2)) {
  13771. outputShape.x1 = outputShape.x2 = subPixelOptimize$1(x1, lineWidth, true);
  13772. }
  13773. else {
  13774. outputShape.x1 = x1;
  13775. outputShape.x2 = x2;
  13776. }
  13777. if (round$1(y1 * 2) === round$1(y2 * 2)) {
  13778. outputShape.y1 = outputShape.y2 = subPixelOptimize$1(y1, lineWidth, true);
  13779. }
  13780. else {
  13781. outputShape.y1 = y1;
  13782. outputShape.y2 = y2;
  13783. }
  13784. }
  13785. /**
  13786. * Sub pixel optimize rect for canvas
  13787. *
  13788. * @param {Object} outputShape The modification will be performed on `outputShape`.
  13789. * `outputShape` and `inputShape` can be the same object.
  13790. * `outputShape` object can be used repeatly, because all of
  13791. * the `x`, `y`, `width`, `height` will be assigned in this method.
  13792. * @param {Object} [inputShape]
  13793. * @param {number} [inputShape.x]
  13794. * @param {number} [inputShape.y]
  13795. * @param {number} [inputShape.width]
  13796. * @param {number} [inputShape.height]
  13797. * @param {Object} [style]
  13798. * @param {number} [style.lineWidth]
  13799. */
  13800. function subPixelOptimizeRect$1(outputShape, inputShape, style) {
  13801. var lineWidth = style && style.lineWidth;
  13802. if (!inputShape || !lineWidth) {
  13803. return;
  13804. }
  13805. var originX = inputShape.x;
  13806. var originY = inputShape.y;
  13807. var originWidth = inputShape.width;
  13808. var originHeight = inputShape.height;
  13809. outputShape.x = subPixelOptimize$1(originX, lineWidth, true);
  13810. outputShape.y = subPixelOptimize$1(originY, lineWidth, true);
  13811. outputShape.width = Math.max(
  13812. subPixelOptimize$1(originX + originWidth, lineWidth, false) - outputShape.x,
  13813. originWidth === 0 ? 0 : 1
  13814. );
  13815. outputShape.height = Math.max(
  13816. subPixelOptimize$1(originY + originHeight, lineWidth, false) - outputShape.y,
  13817. originHeight === 0 ? 0 : 1
  13818. );
  13819. }
  13820. /**
  13821. * Sub pixel optimize for canvas
  13822. *
  13823. * @param {number} position Coordinate, such as x, y
  13824. * @param {number} lineWidth Should be nonnegative integer.
  13825. * @param {boolean=} positiveOrNegative Default false (negative).
  13826. * @return {number} Optimized position.
  13827. */
  13828. function subPixelOptimize$1(position, lineWidth, positiveOrNegative) {
  13829. // Assure that (position + lineWidth / 2) is near integer edge,
  13830. // otherwise line will be fuzzy in canvas.
  13831. var doubledPosition = round$1(position * 2);
  13832. return (doubledPosition + round$1(lineWidth)) % 2 === 0
  13833. ? doubledPosition / 2
  13834. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  13835. }
  13836. /**
  13837. * 矩形
  13838. * @module zrender/graphic/shape/Rect
  13839. */
  13840. // Avoid create repeatly.
  13841. var subPixelOptimizeOutputShape = {};
  13842. var Rect = Path.extend({
  13843. type: 'rect',
  13844. shape: {
  13845. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  13846. // r缩写为1 相当于 [1, 1, 1, 1]
  13847. // r缩写为[1] 相当于 [1, 1, 1, 1]
  13848. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  13849. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  13850. r: 0,
  13851. x: 0,
  13852. y: 0,
  13853. width: 0,
  13854. height: 0
  13855. },
  13856. buildPath: function (ctx, shape) {
  13857. var x;
  13858. var y;
  13859. var width;
  13860. var height;
  13861. if (this.subPixelOptimize) {
  13862. subPixelOptimizeRect$1(subPixelOptimizeOutputShape, shape, this.style);
  13863. x = subPixelOptimizeOutputShape.x;
  13864. y = subPixelOptimizeOutputShape.y;
  13865. width = subPixelOptimizeOutputShape.width;
  13866. height = subPixelOptimizeOutputShape.height;
  13867. subPixelOptimizeOutputShape.r = shape.r;
  13868. shape = subPixelOptimizeOutputShape;
  13869. }
  13870. else {
  13871. x = shape.x;
  13872. y = shape.y;
  13873. width = shape.width;
  13874. height = shape.height;
  13875. }
  13876. if (!shape.r) {
  13877. ctx.rect(x, y, width, height);
  13878. }
  13879. else {
  13880. buildPath(ctx, shape);
  13881. }
  13882. ctx.closePath();
  13883. return;
  13884. }
  13885. });
  13886. /**
  13887. * 直线
  13888. * @module zrender/graphic/shape/Line
  13889. */
  13890. // Avoid create repeatly.
  13891. var subPixelOptimizeOutputShape$1 = {};
  13892. var Line = Path.extend({
  13893. type: 'line',
  13894. shape: {
  13895. // Start point
  13896. x1: 0,
  13897. y1: 0,
  13898. // End point
  13899. x2: 0,
  13900. y2: 0,
  13901. percent: 1
  13902. },
  13903. style: {
  13904. stroke: '#000',
  13905. fill: null
  13906. },
  13907. buildPath: function (ctx, shape) {
  13908. var x1;
  13909. var y1;
  13910. var x2;
  13911. var y2;
  13912. if (this.subPixelOptimize) {
  13913. subPixelOptimizeLine$1(subPixelOptimizeOutputShape$1, shape, this.style);
  13914. x1 = subPixelOptimizeOutputShape$1.x1;
  13915. y1 = subPixelOptimizeOutputShape$1.y1;
  13916. x2 = subPixelOptimizeOutputShape$1.x2;
  13917. y2 = subPixelOptimizeOutputShape$1.y2;
  13918. }
  13919. else {
  13920. x1 = shape.x1;
  13921. y1 = shape.y1;
  13922. x2 = shape.x2;
  13923. y2 = shape.y2;
  13924. }
  13925. var percent = shape.percent;
  13926. if (percent === 0) {
  13927. return;
  13928. }
  13929. ctx.moveTo(x1, y1);
  13930. if (percent < 1) {
  13931. x2 = x1 * (1 - percent) + x2 * percent;
  13932. y2 = y1 * (1 - percent) + y2 * percent;
  13933. }
  13934. ctx.lineTo(x2, y2);
  13935. },
  13936. /**
  13937. * Get point at percent
  13938. * @param {number} percent
  13939. * @return {Array.<number>}
  13940. */
  13941. pointAt: function (p) {
  13942. var shape = this.shape;
  13943. return [
  13944. shape.x1 * (1 - p) + shape.x2 * p,
  13945. shape.y1 * (1 - p) + shape.y2 * p
  13946. ];
  13947. }
  13948. });
  13949. /**
  13950. * 贝塞尔曲线
  13951. * @module zrender/shape/BezierCurve
  13952. */
  13953. var out = [];
  13954. function someVectorAt(shape, t, isTangent) {
  13955. var cpx2 = shape.cpx2;
  13956. var cpy2 = shape.cpy2;
  13957. if (cpx2 === null || cpy2 === null) {
  13958. return [
  13959. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13960. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13961. ];
  13962. }
  13963. else {
  13964. return [
  13965. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13966. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13967. ];
  13968. }
  13969. }
  13970. var BezierCurve = Path.extend({
  13971. type: 'bezier-curve',
  13972. shape: {
  13973. x1: 0,
  13974. y1: 0,
  13975. x2: 0,
  13976. y2: 0,
  13977. cpx1: 0,
  13978. cpy1: 0,
  13979. // cpx2: 0,
  13980. // cpy2: 0
  13981. // Curve show percent, for animating
  13982. percent: 1
  13983. },
  13984. style: {
  13985. stroke: '#000',
  13986. fill: null
  13987. },
  13988. buildPath: function (ctx, shape) {
  13989. var x1 = shape.x1;
  13990. var y1 = shape.y1;
  13991. var x2 = shape.x2;
  13992. var y2 = shape.y2;
  13993. var cpx1 = shape.cpx1;
  13994. var cpy1 = shape.cpy1;
  13995. var cpx2 = shape.cpx2;
  13996. var cpy2 = shape.cpy2;
  13997. var percent = shape.percent;
  13998. if (percent === 0) {
  13999. return;
  14000. }
  14001. ctx.moveTo(x1, y1);
  14002. if (cpx2 == null || cpy2 == null) {
  14003. if (percent < 1) {
  14004. quadraticSubdivide(
  14005. x1, cpx1, x2, percent, out
  14006. );
  14007. cpx1 = out[1];
  14008. x2 = out[2];
  14009. quadraticSubdivide(
  14010. y1, cpy1, y2, percent, out
  14011. );
  14012. cpy1 = out[1];
  14013. y2 = out[2];
  14014. }
  14015. ctx.quadraticCurveTo(
  14016. cpx1, cpy1,
  14017. x2, y2
  14018. );
  14019. }
  14020. else {
  14021. if (percent < 1) {
  14022. cubicSubdivide(
  14023. x1, cpx1, cpx2, x2, percent, out
  14024. );
  14025. cpx1 = out[1];
  14026. cpx2 = out[2];
  14027. x2 = out[3];
  14028. cubicSubdivide(
  14029. y1, cpy1, cpy2, y2, percent, out
  14030. );
  14031. cpy1 = out[1];
  14032. cpy2 = out[2];
  14033. y2 = out[3];
  14034. }
  14035. ctx.bezierCurveTo(
  14036. cpx1, cpy1,
  14037. cpx2, cpy2,
  14038. x2, y2
  14039. );
  14040. }
  14041. },
  14042. /**
  14043. * Get point at percent
  14044. * @param {number} t
  14045. * @return {Array.<number>}
  14046. */
  14047. pointAt: function (t) {
  14048. return someVectorAt(this.shape, t, false);
  14049. },
  14050. /**
  14051. * Get tangent at percent
  14052. * @param {number} t
  14053. * @return {Array.<number>}
  14054. */
  14055. tangentAt: function (t) {
  14056. var p = someVectorAt(this.shape, t, true);
  14057. return normalize(p, p);
  14058. }
  14059. });
  14060. /**
  14061. * 圆弧
  14062. * @module zrender/graphic/shape/Arc
  14063. */
  14064. var Arc = Path.extend({
  14065. type: 'arc',
  14066. shape: {
  14067. cx: 0,
  14068. cy: 0,
  14069. r: 0,
  14070. startAngle: 0,
  14071. endAngle: Math.PI * 2,
  14072. clockwise: true
  14073. },
  14074. style: {
  14075. stroke: '#000',
  14076. fill: null
  14077. },
  14078. buildPath: function (ctx, shape) {
  14079. var x = shape.cx;
  14080. var y = shape.cy;
  14081. var r = Math.max(shape.r, 0);
  14082. var startAngle = shape.startAngle;
  14083. var endAngle = shape.endAngle;
  14084. var clockwise = shape.clockwise;
  14085. var unitX = Math.cos(startAngle);
  14086. var unitY = Math.sin(startAngle);
  14087. ctx.moveTo(unitX * r + x, unitY * r + y);
  14088. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  14089. }
  14090. });
  14091. // CompoundPath to improve performance
  14092. var CompoundPath = Path.extend({
  14093. type: 'compound',
  14094. shape: {
  14095. paths: null
  14096. },
  14097. _updatePathDirty: function () {
  14098. var dirtyPath = this.__dirtyPath;
  14099. var paths = this.shape.paths;
  14100. for (var i = 0; i < paths.length; i++) {
  14101. // Mark as dirty if any subpath is dirty
  14102. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  14103. }
  14104. this.__dirtyPath = dirtyPath;
  14105. this.__dirty = this.__dirty || dirtyPath;
  14106. },
  14107. beforeBrush: function () {
  14108. this._updatePathDirty();
  14109. var paths = this.shape.paths || [];
  14110. var scale = this.getGlobalScale();
  14111. // Update path scale
  14112. for (var i = 0; i < paths.length; i++) {
  14113. if (!paths[i].path) {
  14114. paths[i].createPathProxy();
  14115. }
  14116. paths[i].path.setScale(scale[0], scale[1]);
  14117. }
  14118. },
  14119. buildPath: function (ctx, shape) {
  14120. var paths = shape.paths || [];
  14121. for (var i = 0; i < paths.length; i++) {
  14122. paths[i].buildPath(ctx, paths[i].shape, true);
  14123. }
  14124. },
  14125. afterBrush: function () {
  14126. var paths = this.shape.paths || [];
  14127. for (var i = 0; i < paths.length; i++) {
  14128. paths[i].__dirtyPath = false;
  14129. }
  14130. },
  14131. getBoundingRect: function () {
  14132. this._updatePathDirty();
  14133. return Path.prototype.getBoundingRect.call(this);
  14134. }
  14135. });
  14136. /**
  14137. * @param {Array.<Object>} colorStops
  14138. */
  14139. var Gradient = function (colorStops) {
  14140. this.colorStops = colorStops || [];
  14141. };
  14142. Gradient.prototype = {
  14143. constructor: Gradient,
  14144. addColorStop: function (offset, color) {
  14145. this.colorStops.push({
  14146. offset: offset,
  14147. color: color
  14148. });
  14149. }
  14150. };
  14151. /**
  14152. * x, y, x2, y2 are all percent from 0 to 1
  14153. * @param {number} [x=0]
  14154. * @param {number} [y=0]
  14155. * @param {number} [x2=1]
  14156. * @param {number} [y2=0]
  14157. * @param {Array.<Object>} colorStops
  14158. * @param {boolean} [globalCoord=false]
  14159. */
  14160. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  14161. // Should do nothing more in this constructor. Because gradient can be
  14162. // declard by `color: {type: 'linear', colorStops: ...}`, where
  14163. // this constructor will not be called.
  14164. this.x = x == null ? 0 : x;
  14165. this.y = y == null ? 0 : y;
  14166. this.x2 = x2 == null ? 1 : x2;
  14167. this.y2 = y2 == null ? 0 : y2;
  14168. // Can be cloned
  14169. this.type = 'linear';
  14170. // If use global coord
  14171. this.global = globalCoord || false;
  14172. Gradient.call(this, colorStops);
  14173. };
  14174. LinearGradient.prototype = {
  14175. constructor: LinearGradient
  14176. };
  14177. inherits(LinearGradient, Gradient);
  14178. /**
  14179. * x, y, r are all percent from 0 to 1
  14180. * @param {number} [x=0.5]
  14181. * @param {number} [y=0.5]
  14182. * @param {number} [r=0.5]
  14183. * @param {Array.<Object>} [colorStops]
  14184. * @param {boolean} [globalCoord=false]
  14185. */
  14186. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  14187. // Should do nothing more in this constructor. Because gradient can be
  14188. // declard by `color: {type: 'radial', colorStops: ...}`, where
  14189. // this constructor will not be called.
  14190. this.x = x == null ? 0.5 : x;
  14191. this.y = y == null ? 0.5 : y;
  14192. this.r = r == null ? 0.5 : r;
  14193. // Can be cloned
  14194. this.type = 'radial';
  14195. // If use global coord
  14196. this.global = globalCoord || false;
  14197. Gradient.call(this, colorStops);
  14198. };
  14199. RadialGradient.prototype = {
  14200. constructor: RadialGradient
  14201. };
  14202. inherits(RadialGradient, Gradient);
  14203. /**
  14204. * Displayable for incremental rendering. It will be rendered in a separate layer
  14205. * IncrementalDisplay have two main methods. `clearDisplayables` and `addDisplayables`
  14206. * addDisplayables will render the added displayables incremetally.
  14207. *
  14208. * It use a not clearFlag to tell the painter don't clear the layer if it's the first element.
  14209. */
  14210. // TODO Style override ?
  14211. function IncrementalDisplayble(opts) {
  14212. Displayable.call(this, opts);
  14213. this._displayables = [];
  14214. this._temporaryDisplayables = [];
  14215. this._cursor = 0;
  14216. this.notClear = true;
  14217. }
  14218. IncrementalDisplayble.prototype.incremental = true;
  14219. IncrementalDisplayble.prototype.clearDisplaybles = function () {
  14220. this._displayables = [];
  14221. this._temporaryDisplayables = [];
  14222. this._cursor = 0;
  14223. this.dirty();
  14224. this.notClear = false;
  14225. };
  14226. IncrementalDisplayble.prototype.addDisplayable = function (displayable, notPersistent) {
  14227. if (notPersistent) {
  14228. this._temporaryDisplayables.push(displayable);
  14229. }
  14230. else {
  14231. this._displayables.push(displayable);
  14232. }
  14233. this.dirty();
  14234. };
  14235. IncrementalDisplayble.prototype.addDisplayables = function (displayables, notPersistent) {
  14236. notPersistent = notPersistent || false;
  14237. for (var i = 0; i < displayables.length; i++) {
  14238. this.addDisplayable(displayables[i], notPersistent);
  14239. }
  14240. };
  14241. IncrementalDisplayble.prototype.eachPendingDisplayable = function (cb) {
  14242. for (var i = this._cursor; i < this._displayables.length; i++) {
  14243. cb && cb(this._displayables[i]);
  14244. }
  14245. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14246. cb && cb(this._temporaryDisplayables[i]);
  14247. }
  14248. };
  14249. IncrementalDisplayble.prototype.update = function () {
  14250. this.updateTransform();
  14251. for (var i = this._cursor; i < this._displayables.length; i++) {
  14252. var displayable = this._displayables[i];
  14253. // PENDING
  14254. displayable.parent = this;
  14255. displayable.update();
  14256. displayable.parent = null;
  14257. }
  14258. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14259. var displayable = this._temporaryDisplayables[i];
  14260. // PENDING
  14261. displayable.parent = this;
  14262. displayable.update();
  14263. displayable.parent = null;
  14264. }
  14265. };
  14266. IncrementalDisplayble.prototype.brush = function (ctx, prevEl) {
  14267. // Render persistant displayables.
  14268. for (var i = this._cursor; i < this._displayables.length; i++) {
  14269. var displayable = this._displayables[i];
  14270. displayable.beforeBrush && displayable.beforeBrush(ctx);
  14271. displayable.brush(ctx, i === this._cursor ? null : this._displayables[i - 1]);
  14272. displayable.afterBrush && displayable.afterBrush(ctx);
  14273. }
  14274. this._cursor = i;
  14275. // Render temporary displayables.
  14276. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14277. var displayable = this._temporaryDisplayables[i];
  14278. displayable.beforeBrush && displayable.beforeBrush(ctx);
  14279. displayable.brush(ctx, i === 0 ? null : this._temporaryDisplayables[i - 1]);
  14280. displayable.afterBrush && displayable.afterBrush(ctx);
  14281. }
  14282. this._temporaryDisplayables = [];
  14283. this.notClear = true;
  14284. };
  14285. var m = [];
  14286. IncrementalDisplayble.prototype.getBoundingRect = function () {
  14287. if (!this._rect) {
  14288. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  14289. for (var i = 0; i < this._displayables.length; i++) {
  14290. var displayable = this._displayables[i];
  14291. var childRect = displayable.getBoundingRect().clone();
  14292. if (displayable.needLocalTransform()) {
  14293. childRect.applyTransform(displayable.getLocalTransform(m));
  14294. }
  14295. rect.union(childRect);
  14296. }
  14297. this._rect = rect;
  14298. }
  14299. return this._rect;
  14300. };
  14301. IncrementalDisplayble.prototype.contain = function (x, y) {
  14302. var localPos = this.transformCoordToLocal(x, y);
  14303. var rect = this.getBoundingRect();
  14304. if (rect.contain(localPos[0], localPos[1])) {
  14305. for (var i = 0; i < this._displayables.length; i++) {
  14306. var displayable = this._displayables[i];
  14307. if (displayable.contain(x, y)) {
  14308. return true;
  14309. }
  14310. }
  14311. }
  14312. return false;
  14313. };
  14314. inherits(IncrementalDisplayble, Displayable);
  14315. /*
  14316. * Licensed to the Apache Software Foundation (ASF) under one
  14317. * or more contributor license agreements. See the NOTICE file
  14318. * distributed with this work for additional information
  14319. * regarding copyright ownership. The ASF licenses this file
  14320. * to you under the Apache License, Version 2.0 (the
  14321. * "License"); you may not use this file except in compliance
  14322. * with the License. You may obtain a copy of the License at
  14323. *
  14324. * http://www.apache.org/licenses/LICENSE-2.0
  14325. *
  14326. * Unless required by applicable law or agreed to in writing,
  14327. * software distributed under the License is distributed on an
  14328. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14329. * KIND, either express or implied. See the License for the
  14330. * specific language governing permissions and limitations
  14331. * under the License.
  14332. */
  14333. var round = Math.round;
  14334. var mathMax$1 = Math.max;
  14335. var mathMin$1 = Math.min;
  14336. var EMPTY_OBJ = {};
  14337. var Z2_EMPHASIS_LIFT = 1;
  14338. /**
  14339. * Extend shape with parameters
  14340. */
  14341. function extendShape(opts) {
  14342. return Path.extend(opts);
  14343. }
  14344. /**
  14345. * Extend path
  14346. */
  14347. function extendPath(pathData, opts) {
  14348. return extendFromString(pathData, opts);
  14349. }
  14350. /**
  14351. * Create a path element from path data string
  14352. * @param {string} pathData
  14353. * @param {Object} opts
  14354. * @param {module:zrender/core/BoundingRect} rect
  14355. * @param {string} [layout=cover] 'center' or 'cover'
  14356. */
  14357. function makePath(pathData, opts, rect, layout) {
  14358. var path = createFromString(pathData, opts);
  14359. if (rect) {
  14360. if (layout === 'center') {
  14361. rect = centerGraphic(rect, path.getBoundingRect());
  14362. }
  14363. resizePath(path, rect);
  14364. }
  14365. return path;
  14366. }
  14367. /**
  14368. * Create a image element from image url
  14369. * @param {string} imageUrl image url
  14370. * @param {Object} opts options
  14371. * @param {module:zrender/core/BoundingRect} rect constrain rect
  14372. * @param {string} [layout=cover] 'center' or 'cover'
  14373. */
  14374. function makeImage(imageUrl, rect, layout) {
  14375. var path = new ZImage({
  14376. style: {
  14377. image: imageUrl,
  14378. x: rect.x,
  14379. y: rect.y,
  14380. width: rect.width,
  14381. height: rect.height
  14382. },
  14383. onload: function (img) {
  14384. if (layout === 'center') {
  14385. var boundingRect = {
  14386. width: img.width,
  14387. height: img.height
  14388. };
  14389. path.setStyle(centerGraphic(rect, boundingRect));
  14390. }
  14391. }
  14392. });
  14393. return path;
  14394. }
  14395. /**
  14396. * Get position of centered element in bounding box.
  14397. *
  14398. * @param {Object} rect element local bounding box
  14399. * @param {Object} boundingRect constraint bounding box
  14400. * @return {Object} element position containing x, y, width, and height
  14401. */
  14402. function centerGraphic(rect, boundingRect) {
  14403. // Set rect to center, keep width / height ratio.
  14404. var aspect = boundingRect.width / boundingRect.height;
  14405. var width = rect.height * aspect;
  14406. var height;
  14407. if (width <= rect.width) {
  14408. height = rect.height;
  14409. }
  14410. else {
  14411. width = rect.width;
  14412. height = width / aspect;
  14413. }
  14414. var cx = rect.x + rect.width / 2;
  14415. var cy = rect.y + rect.height / 2;
  14416. return {
  14417. x: cx - width / 2,
  14418. y: cy - height / 2,
  14419. width: width,
  14420. height: height
  14421. };
  14422. }
  14423. var mergePath = mergePath$1;
  14424. /**
  14425. * Resize a path to fit the rect
  14426. * @param {module:zrender/graphic/Path} path
  14427. * @param {Object} rect
  14428. */
  14429. function resizePath(path, rect) {
  14430. if (!path.applyTransform) {
  14431. return;
  14432. }
  14433. var pathRect = path.getBoundingRect();
  14434. var m = pathRect.calculateTransform(rect);
  14435. path.applyTransform(m);
  14436. }
  14437. /**
  14438. * Sub pixel optimize line for canvas
  14439. *
  14440. * @param {Object} param
  14441. * @param {Object} [param.shape]
  14442. * @param {number} [param.shape.x1]
  14443. * @param {number} [param.shape.y1]
  14444. * @param {number} [param.shape.x2]
  14445. * @param {number} [param.shape.y2]
  14446. * @param {Object} [param.style]
  14447. * @param {number} [param.style.lineWidth]
  14448. * @return {Object} Modified param
  14449. */
  14450. function subPixelOptimizeLine(param) {
  14451. var shape = param.shape;
  14452. var lineWidth = param.style.lineWidth;
  14453. if (round(shape.x1 * 2) === round(shape.x2 * 2)) {
  14454. shape.x1 = shape.x2 = subPixelOptimize(shape.x1, lineWidth, true);
  14455. }
  14456. if (round(shape.y1 * 2) === round(shape.y2 * 2)) {
  14457. shape.y1 = shape.y2 = subPixelOptimize(shape.y1, lineWidth, true);
  14458. }
  14459. return param;
  14460. }
  14461. /**
  14462. * Sub pixel optimize rect for canvas
  14463. *
  14464. * @param {Object} param
  14465. * @param {Object} [param.shape]
  14466. * @param {number} [param.shape.x]
  14467. * @param {number} [param.shape.y]
  14468. * @param {number} [param.shape.width]
  14469. * @param {number} [param.shape.height]
  14470. * @param {Object} [param.style]
  14471. * @param {number} [param.style.lineWidth]
  14472. * @return {Object} Modified param
  14473. */
  14474. function subPixelOptimizeRect(param) {
  14475. var shape = param.shape;
  14476. var lineWidth = param.style.lineWidth;
  14477. var originX = shape.x;
  14478. var originY = shape.y;
  14479. var originWidth = shape.width;
  14480. var originHeight = shape.height;
  14481. shape.x = subPixelOptimize(shape.x, lineWidth, true);
  14482. shape.y = subPixelOptimize(shape.y, lineWidth, true);
  14483. shape.width = Math.max(
  14484. subPixelOptimize(originX + originWidth, lineWidth, false) - shape.x,
  14485. originWidth === 0 ? 0 : 1
  14486. );
  14487. shape.height = Math.max(
  14488. subPixelOptimize(originY + originHeight, lineWidth, false) - shape.y,
  14489. originHeight === 0 ? 0 : 1
  14490. );
  14491. return param;
  14492. }
  14493. /**
  14494. * Sub pixel optimize for canvas
  14495. *
  14496. * @param {number} position Coordinate, such as x, y
  14497. * @param {number} lineWidth Should be nonnegative integer.
  14498. * @param {boolean=} positiveOrNegative Default false (negative).
  14499. * @return {number} Optimized position.
  14500. */
  14501. function subPixelOptimize(position, lineWidth, positiveOrNegative) {
  14502. // Assure that (position + lineWidth / 2) is near integer edge,
  14503. // otherwise line will be fuzzy in canvas.
  14504. var doubledPosition = round(position * 2);
  14505. return (doubledPosition + round(lineWidth)) % 2 === 0
  14506. ? doubledPosition / 2
  14507. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  14508. }
  14509. function hasFillOrStroke(fillOrStroke) {
  14510. return fillOrStroke != null && fillOrStroke !== 'none';
  14511. }
  14512. // Most lifted color are duplicated.
  14513. var liftedColorMap = createHashMap();
  14514. var liftedColorCount = 0;
  14515. function liftColor(color) {
  14516. if (typeof color !== 'string') {
  14517. return color;
  14518. }
  14519. var liftedColor = liftedColorMap.get(color);
  14520. if (!liftedColor) {
  14521. liftedColor = lift(color, -0.1);
  14522. if (liftedColorCount < 10000) {
  14523. liftedColorMap.set(color, liftedColor);
  14524. liftedColorCount++;
  14525. }
  14526. }
  14527. return liftedColor;
  14528. }
  14529. function cacheElementStl(el) {
  14530. if (!el.__hoverStlDirty) {
  14531. return;
  14532. }
  14533. el.__hoverStlDirty = false;
  14534. var hoverStyle = el.__hoverStl;
  14535. if (!hoverStyle) {
  14536. el.__cachedNormalStl = el.__cachedNormalZ2 = null;
  14537. return;
  14538. }
  14539. var normalStyle = el.__cachedNormalStl = {};
  14540. el.__cachedNormalZ2 = el.z2;
  14541. var elStyle = el.style;
  14542. for (var name in hoverStyle) {
  14543. // See comment in `doSingleEnterHover`.
  14544. if (hoverStyle[name] != null) {
  14545. normalStyle[name] = elStyle[name];
  14546. }
  14547. }
  14548. // Always cache fill and stroke to normalStyle for lifting color.
  14549. normalStyle.fill = elStyle.fill;
  14550. normalStyle.stroke = elStyle.stroke;
  14551. }
  14552. function doSingleEnterHover(el) {
  14553. var hoverStl = el.__hoverStl;
  14554. if (!hoverStl || el.__highlighted) {
  14555. return;
  14556. }
  14557. var useHoverLayer = el.useHoverLayer;
  14558. el.__highlighted = useHoverLayer ? 'layer' : 'plain';
  14559. var zr = el.__zr;
  14560. if (!zr && useHoverLayer) {
  14561. return;
  14562. }
  14563. var elTarget = el;
  14564. var targetStyle = el.style;
  14565. if (useHoverLayer) {
  14566. elTarget = zr.addHover(el);
  14567. targetStyle = elTarget.style;
  14568. }
  14569. rollbackDefaultTextStyle(targetStyle);
  14570. if (!useHoverLayer) {
  14571. cacheElementStl(elTarget);
  14572. }
  14573. // styles can be:
  14574. // {
  14575. // label: {
  14576. // show: false,
  14577. // position: 'outside',
  14578. // fontSize: 18
  14579. // },
  14580. // emphasis: {
  14581. // label: {
  14582. // show: true
  14583. // }
  14584. // }
  14585. // },
  14586. // where properties of `emphasis` may not appear in `normal`. We previously use
  14587. // module:echarts/util/model#defaultEmphasis to merge `normal` to `emphasis`.
  14588. // But consider rich text and setOption in merge mode, it is impossible to cover
  14589. // all properties in merge. So we use merge mode when setting style here, where
  14590. // only properties that is not `null/undefined` can be set. The disadventage:
  14591. // null/undefined can not be used to remove style any more in `emphasis`.
  14592. targetStyle.extendFrom(hoverStl);
  14593. setDefaultHoverFillStroke(targetStyle, hoverStl, 'fill');
  14594. setDefaultHoverFillStroke(targetStyle, hoverStl, 'stroke');
  14595. applyDefaultTextStyle(targetStyle);
  14596. if (!useHoverLayer) {
  14597. el.dirty(false);
  14598. el.z2 += Z2_EMPHASIS_LIFT;
  14599. }
  14600. }
  14601. function setDefaultHoverFillStroke(targetStyle, hoverStyle, prop) {
  14602. if (!hasFillOrStroke(hoverStyle[prop]) && hasFillOrStroke(targetStyle[prop])) {
  14603. targetStyle[prop] = liftColor(targetStyle[prop]);
  14604. }
  14605. }
  14606. function doSingleLeaveHover(el) {
  14607. var highlighted = el.__highlighted;
  14608. if (!highlighted) {
  14609. return;
  14610. }
  14611. el.__highlighted = false;
  14612. if (highlighted === 'layer') {
  14613. el.__zr && el.__zr.removeHover(el);
  14614. }
  14615. else if (highlighted) {
  14616. var style = el.style;
  14617. var normalStl = el.__cachedNormalStl;
  14618. if (normalStl) {
  14619. rollbackDefaultTextStyle(style);
  14620. // Consider null/undefined value, should use
  14621. // `setStyle` but not `extendFrom(stl, true)`.
  14622. el.setStyle(normalStl);
  14623. applyDefaultTextStyle(style);
  14624. }
  14625. // `__cachedNormalZ2` will not be reset if calling `setElementHoverStyle`
  14626. // when `el` is on emphasis state. So here by comparing with 1, we try
  14627. // hard to make the bug case rare.
  14628. var normalZ2 = el.__cachedNormalZ2;
  14629. if (normalZ2 != null && el.z2 - normalZ2 === Z2_EMPHASIS_LIFT) {
  14630. el.z2 = normalZ2;
  14631. }
  14632. }
  14633. }
  14634. function traverseCall(el, method) {
  14635. el.isGroup
  14636. ? el.traverse(function (child) {
  14637. !child.isGroup && method(child);
  14638. })
  14639. : method(el);
  14640. }
  14641. /**
  14642. * Set hover style (namely "emphasis style") of element, based on the current
  14643. * style of the given `el`.
  14644. * This method should be called after all of the normal styles have been adopted
  14645. * to the `el`. See the reason on `setHoverStyle`.
  14646. *
  14647. * @param {module:zrender/Element} el Should not be `zrender/container/Group`.
  14648. * @param {Object|boolean} [hoverStl] The specified hover style.
  14649. * If set as `false`, disable the hover style.
  14650. * Similarly, The `el.hoverStyle` can alse be set
  14651. * as `false` to disable the hover style.
  14652. * Otherwise, use the default hover style if not provided.
  14653. * @param {Object} [opt]
  14654. * @param {boolean} [opt.hoverSilentOnTouch=false] See `graphic.setAsHoverStyleTrigger`
  14655. */
  14656. function setElementHoverStyle(el, hoverStl) {
  14657. // For performance consideration, it might be better to make the "hover style" only the
  14658. // difference properties from the "normal style", but not a entire copy of all styles.
  14659. hoverStl = el.__hoverStl = hoverStl !== false && (hoverStl || {});
  14660. el.__hoverStlDirty = true;
  14661. // FIXME
  14662. // It is not completely right to save "normal"/"emphasis" flag on elements.
  14663. // It probably should be saved on `data` of series. Consider the cases:
  14664. // (1) A highlighted elements are moved out of the view port and re-enter
  14665. // again by dataZoom.
  14666. // (2) call `setOption` and replace elements totally when they are highlighted.
  14667. if (el.__highlighted) {
  14668. // Consider the case:
  14669. // The styles of a highlighted `el` is being updated. The new "emphasis style"
  14670. // should be adapted to the `el`. Notice here new "normal styles" should have
  14671. // been set outside and the cached "normal style" is out of date.
  14672. el.__cachedNormalStl = null;
  14673. // Do not clear `__cachedNormalZ2` here, because setting `z2` is not a constraint
  14674. // of this method. In most cases, `z2` is not set and hover style should be able
  14675. // to rollback. Of course, that would bring bug, but only in a rare case, see
  14676. // `doSingleLeaveHover` for details.
  14677. doSingleLeaveHover(el);
  14678. doSingleEnterHover(el);
  14679. }
  14680. }
  14681. /**
  14682. * Emphasis (called by API) has higher priority than `mouseover`.
  14683. * When element has been called to be entered emphasis, mouse over
  14684. * should not trigger the highlight effect (for example, animation
  14685. * scale) again, and `mouseout` should not downplay the highlight
  14686. * effect. So the listener of `mouseover` and `mouseout` should
  14687. * check `isInEmphasis`.
  14688. *
  14689. * @param {module:zrender/Element} el
  14690. * @return {boolean}
  14691. */
  14692. function isInEmphasis(el) {
  14693. return el && el.__isEmphasisEntered;
  14694. }
  14695. function onElementMouseOver(e) {
  14696. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  14697. return;
  14698. }
  14699. // Only if element is not in emphasis status
  14700. !this.__isEmphasisEntered && traverseCall(this, doSingleEnterHover);
  14701. }
  14702. function onElementMouseOut(e) {
  14703. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  14704. return;
  14705. }
  14706. // Only if element is not in emphasis status
  14707. !this.__isEmphasisEntered && traverseCall(this, doSingleLeaveHover);
  14708. }
  14709. function enterEmphasis() {
  14710. this.__isEmphasisEntered = true;
  14711. traverseCall(this, doSingleEnterHover);
  14712. }
  14713. function leaveEmphasis() {
  14714. this.__isEmphasisEntered = false;
  14715. traverseCall(this, doSingleLeaveHover);
  14716. }
  14717. /**
  14718. * Set hover style (namely "emphasis style") of element,
  14719. * based on the current style of the given `el`.
  14720. *
  14721. * (1)
  14722. * **CONSTRAINTS** for this method:
  14723. * <A> This method MUST be called after all of the normal styles having been adopted
  14724. * to the `el`.
  14725. * <B> The input `hoverStyle` (that is, "emphasis style") MUST be the subset of the
  14726. * "normal style" having been set to the el.
  14727. * <C> `color` MUST be one of the "normal styles" (because color might be lifted as
  14728. * a default hover style).
  14729. *
  14730. * The reason: this method treat the current style of the `el` as the "normal style"
  14731. * and cache them when enter/update the "emphasis style". Consider the case: the `el`
  14732. * is in "emphasis" state and `setOption`/`dispatchAction` trigger the style updating
  14733. * logic, where the el should shift from the original emphasis style to the new
  14734. * "emphasis style" and should be able to "downplay" back to the new "normal style".
  14735. *
  14736. * Indeed, it is error-prone to make a interface has so many constraints, but I have
  14737. * not found a better solution yet to fit the backward compatibility, performance and
  14738. * the current programming style.
  14739. *
  14740. * (2)
  14741. * Call the method for a "root" element once. Do not call it for each descendants.
  14742. * If the descendants elemenets of a group has itself hover style different from the
  14743. * root group, we can simply mount the style on `el.hoverStyle` for them, but should
  14744. * not call this method for them.
  14745. *
  14746. * @param {module:zrender/Element} el
  14747. * @param {Object|boolean} [hoverStyle] See `graphic.setElementHoverStyle`.
  14748. * @param {Object} [opt]
  14749. * @param {boolean} [opt.hoverSilentOnTouch=false] See `graphic.setAsHoverStyleTrigger`.
  14750. */
  14751. function setHoverStyle(el, hoverStyle, opt) {
  14752. el.isGroup
  14753. ? el.traverse(function (child) {
  14754. // If element has sepcified hoverStyle, then use it instead of given hoverStyle
  14755. // Often used when item group has a label element and it's hoverStyle is different
  14756. !child.isGroup && setElementHoverStyle(child, child.hoverStyle || hoverStyle);
  14757. })
  14758. : setElementHoverStyle(el, el.hoverStyle || hoverStyle);
  14759. setAsHoverStyleTrigger(el, opt);
  14760. }
  14761. /**
  14762. * @param {Object|boolean} [opt] If `false`, means disable trigger.
  14763. * @param {boolean} [opt.hoverSilentOnTouch=false]
  14764. * In touch device, mouseover event will be trigger on touchstart event
  14765. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  14766. * conveniently use hoverStyle when tap on touch screen without additional
  14767. * code for compatibility.
  14768. * But if the chart/component has select feature, which usually also use
  14769. * hoverStyle, there might be conflict between 'select-highlight' and
  14770. * 'hover-highlight' especially when roam is enabled (see geo for example).
  14771. * In this case, hoverSilentOnTouch should be used to disable hover-highlight
  14772. * on touch device.
  14773. */
  14774. function setAsHoverStyleTrigger(el, opt) {
  14775. var disable = opt === false;
  14776. el.__hoverSilentOnTouch = opt != null && opt.hoverSilentOnTouch;
  14777. // Simple optimize, since this method might be
  14778. // called for each elements of a group in some cases.
  14779. if (!disable || el.__hoverStyleTrigger) {
  14780. var method = disable ? 'off' : 'on';
  14781. // Duplicated function will be auto-ignored, see Eventful.js.
  14782. el[method]('mouseover', onElementMouseOver)[method]('mouseout', onElementMouseOut);
  14783. // Emphasis, normal can be triggered manually
  14784. el[method]('emphasis', enterEmphasis)[method]('normal', leaveEmphasis);
  14785. el.__hoverStyleTrigger = !disable;
  14786. }
  14787. }
  14788. /**
  14789. * See more info in `setTextStyleCommon`.
  14790. * @param {Object|module:zrender/graphic/Style} normalStyle
  14791. * @param {Object} emphasisStyle
  14792. * @param {module:echarts/model/Model} normalModel
  14793. * @param {module:echarts/model/Model} emphasisModel
  14794. * @param {Object} opt Check `opt` of `setTextStyleCommon` to find other props.
  14795. * @param {string|Function} [opt.defaultText]
  14796. * @param {module:echarts/model/Model} [opt.labelFetcher] Fetch text by
  14797. * `opt.labelFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  14798. * @param {module:echarts/model/Model} [opt.labelDataIndex] Fetch text by
  14799. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  14800. * @param {module:echarts/model/Model} [opt.labelDimIndex] Fetch text by
  14801. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  14802. * @param {Object} [normalSpecified]
  14803. * @param {Object} [emphasisSpecified]
  14804. */
  14805. function setLabelStyle(
  14806. normalStyle, emphasisStyle,
  14807. normalModel, emphasisModel,
  14808. opt,
  14809. normalSpecified, emphasisSpecified
  14810. ) {
  14811. opt = opt || EMPTY_OBJ;
  14812. var labelFetcher = opt.labelFetcher;
  14813. var labelDataIndex = opt.labelDataIndex;
  14814. var labelDimIndex = opt.labelDimIndex;
  14815. // This scenario, `label.normal.show = true; label.emphasis.show = false`,
  14816. // is not supported util someone requests.
  14817. var showNormal = normalModel.getShallow('show');
  14818. var showEmphasis = emphasisModel.getShallow('show');
  14819. // Consider performance, only fetch label when necessary.
  14820. // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set,
  14821. // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`.
  14822. var baseText;
  14823. if (showNormal || showEmphasis) {
  14824. if (labelFetcher) {
  14825. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex);
  14826. }
  14827. if (baseText == null) {
  14828. baseText = isFunction$1(opt.defaultText) ? opt.defaultText(labelDataIndex, opt) : opt.defaultText;
  14829. }
  14830. }
  14831. var normalStyleText = showNormal ? baseText : null;
  14832. var emphasisStyleText = showEmphasis
  14833. ? retrieve2(
  14834. labelFetcher
  14835. ? labelFetcher.getFormattedLabel(labelDataIndex, 'emphasis', null, labelDimIndex)
  14836. : null,
  14837. baseText
  14838. )
  14839. : null;
  14840. // Optimize: If style.text is null, text will not be drawn.
  14841. if (normalStyleText != null || emphasisStyleText != null) {
  14842. // Always set `textStyle` even if `normalStyle.text` is null, because default
  14843. // values have to be set on `normalStyle`.
  14844. // If we set default values on `emphasisStyle`, consider case:
  14845. // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);`
  14846. // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);`
  14847. // Then the 'red' will not work on emphasis.
  14848. setTextStyle(normalStyle, normalModel, normalSpecified, opt);
  14849. setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true);
  14850. }
  14851. normalStyle.text = normalStyleText;
  14852. emphasisStyle.text = emphasisStyleText;
  14853. }
  14854. /**
  14855. * Set basic textStyle properties.
  14856. * See more info in `setTextStyleCommon`.
  14857. * @param {Object|module:zrender/graphic/Style} textStyle
  14858. * @param {module:echarts/model/Model} model
  14859. * @param {Object} [specifiedTextStyle] Can be overrided by settings in model.
  14860. * @param {Object} [opt] See `opt` of `setTextStyleCommon`.
  14861. * @param {boolean} [isEmphasis]
  14862. */
  14863. function setTextStyle(
  14864. textStyle, textStyleModel, specifiedTextStyle, opt, isEmphasis
  14865. ) {
  14866. setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis);
  14867. specifiedTextStyle && extend(textStyle, specifiedTextStyle);
  14868. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14869. return textStyle;
  14870. }
  14871. /**
  14872. * Set text option in the style.
  14873. * See more info in `setTextStyleCommon`.
  14874. * @deprecated
  14875. * @param {Object} textStyle
  14876. * @param {module:echarts/model/Model} labelModel
  14877. * @param {string|boolean} defaultColor Default text color.
  14878. * If set as false, it will be processed as a emphasis style.
  14879. */
  14880. function setText(textStyle, labelModel, defaultColor) {
  14881. var opt = {isRectText: true};
  14882. var isEmphasis;
  14883. if (defaultColor === false) {
  14884. isEmphasis = true;
  14885. }
  14886. else {
  14887. // Support setting color as 'auto' to get visual color.
  14888. opt.autoColor = defaultColor;
  14889. }
  14890. setTextStyleCommon(textStyle, labelModel, opt, isEmphasis);
  14891. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14892. }
  14893. /**
  14894. * The uniform entry of set text style, that is, retrieve style definitions
  14895. * from `model` and set to `textStyle` object.
  14896. *
  14897. * Never in merge mode, but in overwrite mode, that is, all of the text style
  14898. * properties will be set. (Consider the states of normal and emphasis and
  14899. * default value can be adopted, merge would make the logic too complicated
  14900. * to manage.)
  14901. *
  14902. * The `textStyle` object can either be a plain object or an instance of
  14903. * `zrender/src/graphic/Style`, and either be the style of normal or emphasis.
  14904. * After this mothod called, the `textStyle` object can then be used in
  14905. * `el.setStyle(textStyle)` or `el.hoverStyle = textStyle`.
  14906. *
  14907. * Default value will be adopted and `insideRollbackOpt` will be created.
  14908. * See `applyDefaultTextStyle` `rollbackDefaultTextStyle` for more details.
  14909. *
  14910. * opt: {
  14911. * disableBox: boolean, Whether diable drawing box of block (outer most).
  14912. * isRectText: boolean,
  14913. * autoColor: string, specify a color when color is 'auto',
  14914. * for textFill, textStroke, textBackgroundColor, and textBorderColor.
  14915. * If autoColor specified, it is used as default textFill.
  14916. * useInsideStyle:
  14917. * `true`: Use inside style (textFill, textStroke, textStrokeWidth)
  14918. * if `textFill` is not specified.
  14919. * `false`: Do not use inside style.
  14920. * `null/undefined`: use inside style if `isRectText` is true and
  14921. * `textFill` is not specified and textPosition contains `'inside'`.
  14922. * forceRich: boolean
  14923. * }
  14924. */
  14925. function setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis) {
  14926. // Consider there will be abnormal when merge hover style to normal style if given default value.
  14927. opt = opt || EMPTY_OBJ;
  14928. if (opt.isRectText) {
  14929. var textPosition = textStyleModel.getShallow('position')
  14930. || (isEmphasis ? null : 'inside');
  14931. // 'outside' is not a valid zr textPostion value, but used
  14932. // in bar series, and magric type should be considered.
  14933. textPosition === 'outside' && (textPosition = 'top');
  14934. textStyle.textPosition = textPosition;
  14935. textStyle.textOffset = textStyleModel.getShallow('offset');
  14936. var labelRotate = textStyleModel.getShallow('rotate');
  14937. labelRotate != null && (labelRotate *= Math.PI / 180);
  14938. textStyle.textRotation = labelRotate;
  14939. textStyle.textDistance = retrieve2(
  14940. textStyleModel.getShallow('distance'), isEmphasis ? null : 5
  14941. );
  14942. }
  14943. var ecModel = textStyleModel.ecModel;
  14944. var globalTextStyle = ecModel && ecModel.option.textStyle;
  14945. // Consider case:
  14946. // {
  14947. // data: [{
  14948. // value: 12,
  14949. // label: {
  14950. // rich: {
  14951. // // no 'a' here but using parent 'a'.
  14952. // }
  14953. // }
  14954. // }],
  14955. // rich: {
  14956. // a: { ... }
  14957. // }
  14958. // }
  14959. var richItemNames = getRichItemNames(textStyleModel);
  14960. var richResult;
  14961. if (richItemNames) {
  14962. richResult = {};
  14963. for (var name in richItemNames) {
  14964. if (richItemNames.hasOwnProperty(name)) {
  14965. // Cascade is supported in rich.
  14966. var richTextStyle = textStyleModel.getModel(['rich', name]);
  14967. // In rich, never `disableBox`.
  14968. setTokenTextStyle(richResult[name] = {}, richTextStyle, globalTextStyle, opt, isEmphasis);
  14969. }
  14970. }
  14971. }
  14972. textStyle.rich = richResult;
  14973. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, true);
  14974. if (opt.forceRich && !opt.textStyle) {
  14975. opt.textStyle = {};
  14976. }
  14977. return textStyle;
  14978. }
  14979. // Consider case:
  14980. // {
  14981. // data: [{
  14982. // value: 12,
  14983. // label: {
  14984. // rich: {
  14985. // // no 'a' here but using parent 'a'.
  14986. // }
  14987. // }
  14988. // }],
  14989. // rich: {
  14990. // a: { ... }
  14991. // }
  14992. // }
  14993. function getRichItemNames(textStyleModel) {
  14994. // Use object to remove duplicated names.
  14995. var richItemNameMap;
  14996. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  14997. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  14998. if (rich) {
  14999. richItemNameMap = richItemNameMap || {};
  15000. for (var name in rich) {
  15001. if (rich.hasOwnProperty(name)) {
  15002. richItemNameMap[name] = 1;
  15003. }
  15004. }
  15005. }
  15006. textStyleModel = textStyleModel.parentModel;
  15007. }
  15008. return richItemNameMap;
  15009. }
  15010. function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, isBlock) {
  15011. // In merge mode, default value should not be given.
  15012. globalTextStyle = !isEmphasis && globalTextStyle || EMPTY_OBJ;
  15013. textStyle.textFill = getAutoColor(textStyleModel.getShallow('color'), opt)
  15014. || globalTextStyle.color;
  15015. textStyle.textStroke = getAutoColor(textStyleModel.getShallow('textBorderColor'), opt)
  15016. || globalTextStyle.textBorderColor;
  15017. textStyle.textStrokeWidth = retrieve2(
  15018. textStyleModel.getShallow('textBorderWidth'),
  15019. globalTextStyle.textBorderWidth
  15020. );
  15021. // Save original textPosition, because style.textPosition will be repalced by
  15022. // real location (like [10, 30]) in zrender.
  15023. textStyle.insideRawTextPosition = textStyle.textPosition;
  15024. if (!isEmphasis) {
  15025. if (isBlock) {
  15026. textStyle.insideRollbackOpt = opt;
  15027. applyDefaultTextStyle(textStyle);
  15028. }
  15029. // Set default finally.
  15030. if (textStyle.textFill == null) {
  15031. textStyle.textFill = opt.autoColor;
  15032. }
  15033. }
  15034. // Do not use `getFont` here, because merge should be supported, where
  15035. // part of these properties may be changed in emphasis style, and the
  15036. // others should remain their original value got from normal style.
  15037. textStyle.fontStyle = textStyleModel.getShallow('fontStyle') || globalTextStyle.fontStyle;
  15038. textStyle.fontWeight = textStyleModel.getShallow('fontWeight') || globalTextStyle.fontWeight;
  15039. textStyle.fontSize = textStyleModel.getShallow('fontSize') || globalTextStyle.fontSize;
  15040. textStyle.fontFamily = textStyleModel.getShallow('fontFamily') || globalTextStyle.fontFamily;
  15041. textStyle.textAlign = textStyleModel.getShallow('align');
  15042. textStyle.textVerticalAlign = textStyleModel.getShallow('verticalAlign')
  15043. || textStyleModel.getShallow('baseline');
  15044. textStyle.textLineHeight = textStyleModel.getShallow('lineHeight');
  15045. textStyle.textWidth = textStyleModel.getShallow('width');
  15046. textStyle.textHeight = textStyleModel.getShallow('height');
  15047. textStyle.textTag = textStyleModel.getShallow('tag');
  15048. if (!isBlock || !opt.disableBox) {
  15049. textStyle.textBackgroundColor = getAutoColor(textStyleModel.getShallow('backgroundColor'), opt);
  15050. textStyle.textPadding = textStyleModel.getShallow('padding');
  15051. textStyle.textBorderColor = getAutoColor(textStyleModel.getShallow('borderColor'), opt);
  15052. textStyle.textBorderWidth = textStyleModel.getShallow('borderWidth');
  15053. textStyle.textBorderRadius = textStyleModel.getShallow('borderRadius');
  15054. textStyle.textBoxShadowColor = textStyleModel.getShallow('shadowColor');
  15055. textStyle.textBoxShadowBlur = textStyleModel.getShallow('shadowBlur');
  15056. textStyle.textBoxShadowOffsetX = textStyleModel.getShallow('shadowOffsetX');
  15057. textStyle.textBoxShadowOffsetY = textStyleModel.getShallow('shadowOffsetY');
  15058. }
  15059. textStyle.textShadowColor = textStyleModel.getShallow('textShadowColor')
  15060. || globalTextStyle.textShadowColor;
  15061. textStyle.textShadowBlur = textStyleModel.getShallow('textShadowBlur')
  15062. || globalTextStyle.textShadowBlur;
  15063. textStyle.textShadowOffsetX = textStyleModel.getShallow('textShadowOffsetX')
  15064. || globalTextStyle.textShadowOffsetX;
  15065. textStyle.textShadowOffsetY = textStyleModel.getShallow('textShadowOffsetY')
  15066. || globalTextStyle.textShadowOffsetY;
  15067. }
  15068. function getAutoColor(color, opt) {
  15069. return color !== 'auto' ? color : (opt && opt.autoColor) ? opt.autoColor : null;
  15070. }
  15071. /**
  15072. * Give some default value to the input `textStyle` object, based on the current settings
  15073. * in this `textStyle` object.
  15074. *
  15075. * The Scenario:
  15076. * when text position is `inside` and `textFill` is not specified, we show
  15077. * text border by default for better view. But it should be considered that text position
  15078. * might be changed when hovering or being emphasis, where the `insideRollback` is used to
  15079. * restore the style.
  15080. *
  15081. * Usage (& NOTICE):
  15082. * When a style object (eithor plain object or instance of `zrender/src/graphic/Style`) is
  15083. * about to be modified on its text related properties, `rollbackDefaultTextStyle` should
  15084. * be called before the modification and `applyDefaultTextStyle` should be called after that.
  15085. * (For the case that all of the text related properties is reset, like `setTextStyleCommon`
  15086. * does, `rollbackDefaultTextStyle` is not needed to be called).
  15087. */
  15088. function applyDefaultTextStyle(textStyle) {
  15089. var opt = textStyle.insideRollbackOpt;
  15090. // Only `insideRollbackOpt` created (in `setTextStyleCommon`),
  15091. // applyDefaultTextStyle works.
  15092. if (!opt || textStyle.textFill != null) {
  15093. return;
  15094. }
  15095. var useInsideStyle = opt.useInsideStyle;
  15096. var textPosition = textStyle.insideRawTextPosition;
  15097. var insideRollback;
  15098. var autoColor = opt.autoColor;
  15099. if (useInsideStyle !== false
  15100. && (useInsideStyle === true
  15101. || (opt.isRectText
  15102. && textPosition
  15103. // textPosition can be [10, 30]
  15104. && typeof textPosition === 'string'
  15105. && textPosition.indexOf('inside') >= 0
  15106. )
  15107. )
  15108. ) {
  15109. insideRollback = {
  15110. textFill: null,
  15111. textStroke: textStyle.textStroke,
  15112. textStrokeWidth: textStyle.textStrokeWidth
  15113. };
  15114. textStyle.textFill = '#fff';
  15115. // Consider text with #fff overflow its container.
  15116. if (textStyle.textStroke == null) {
  15117. textStyle.textStroke = autoColor;
  15118. textStyle.textStrokeWidth == null && (textStyle.textStrokeWidth = 2);
  15119. }
  15120. }
  15121. else if (autoColor != null) {
  15122. insideRollback = {textFill: null};
  15123. textStyle.textFill = autoColor;
  15124. }
  15125. // Always set `insideRollback`, for clearing previous.
  15126. if (insideRollback) {
  15127. textStyle.insideRollback = insideRollback;
  15128. }
  15129. }
  15130. /**
  15131. * Consider the case: in a scatter,
  15132. * label: {
  15133. * normal: {position: 'inside'},
  15134. * emphasis: {position: 'top'}
  15135. * }
  15136. * In the normal state, the `textFill` will be set as '#fff' for pretty view (see
  15137. * `applyDefaultTextStyle`), but when switching to emphasis state, the `textFill`
  15138. * should be retured to 'autoColor', but not keep '#fff'.
  15139. */
  15140. function rollbackDefaultTextStyle(style) {
  15141. var insideRollback = style.insideRollback;
  15142. if (insideRollback) {
  15143. style.textFill = insideRollback.textFill;
  15144. style.textStroke = insideRollback.textStroke;
  15145. style.textStrokeWidth = insideRollback.textStrokeWidth;
  15146. style.insideRollback = null;
  15147. }
  15148. }
  15149. function getFont(opt, ecModel) {
  15150. // ecModel or default text style model.
  15151. var gTextStyleModel = ecModel || ecModel.getModel('textStyle');
  15152. return trim([
  15153. // FIXME in node-canvas fontWeight is before fontStyle
  15154. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '',
  15155. opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '',
  15156. (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px',
  15157. opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'
  15158. ].join(' '));
  15159. }
  15160. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  15161. if (typeof dataIndex === 'function') {
  15162. cb = dataIndex;
  15163. dataIndex = null;
  15164. }
  15165. // Do not check 'animation' property directly here. Consider this case:
  15166. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  15167. // but its parent model (`seriesModel`) does.
  15168. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  15169. if (animationEnabled) {
  15170. var postfix = isUpdate ? 'Update' : '';
  15171. var duration = animatableModel.getShallow('animationDuration' + postfix);
  15172. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  15173. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  15174. if (typeof animationDelay === 'function') {
  15175. animationDelay = animationDelay(
  15176. dataIndex,
  15177. animatableModel.getAnimationDelayParams
  15178. ? animatableModel.getAnimationDelayParams(el, dataIndex)
  15179. : null
  15180. );
  15181. }
  15182. if (typeof duration === 'function') {
  15183. duration = duration(dataIndex);
  15184. }
  15185. duration > 0
  15186. ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb, !!cb)
  15187. : (el.stopAnimation(), el.attr(props), cb && cb());
  15188. }
  15189. else {
  15190. el.stopAnimation();
  15191. el.attr(props);
  15192. cb && cb();
  15193. }
  15194. }
  15195. /**
  15196. * Update graphic element properties with or without animation according to the
  15197. * configuration in series.
  15198. *
  15199. * Caution: this method will stop previous animation.
  15200. * So if do not use this method to one element twice before
  15201. * animation starts, unless you know what you are doing.
  15202. *
  15203. * @param {module:zrender/Element} el
  15204. * @param {Object} props
  15205. * @param {module:echarts/model/Model} [animatableModel]
  15206. * @param {number} [dataIndex]
  15207. * @param {Function} [cb]
  15208. * @example
  15209. * graphic.updateProps(el, {
  15210. * position: [100, 100]
  15211. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  15212. * // Or
  15213. * graphic.updateProps(el, {
  15214. * position: [100, 100]
  15215. * }, seriesModel, function () { console.log('Animation done!'); });
  15216. */
  15217. function updateProps(el, props, animatableModel, dataIndex, cb) {
  15218. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  15219. }
  15220. /**
  15221. * Init graphic element properties with or without animation according to the
  15222. * configuration in series.
  15223. *
  15224. * Caution: this method will stop previous animation.
  15225. * So if do not use this method to one element twice before
  15226. * animation starts, unless you know what you are doing.
  15227. *
  15228. * @param {module:zrender/Element} el
  15229. * @param {Object} props
  15230. * @param {module:echarts/model/Model} [animatableModel]
  15231. * @param {number} [dataIndex]
  15232. * @param {Function} cb
  15233. */
  15234. function initProps(el, props, animatableModel, dataIndex, cb) {
  15235. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  15236. }
  15237. /**
  15238. * Get transform matrix of target (param target),
  15239. * in coordinate of its ancestor (param ancestor)
  15240. *
  15241. * @param {module:zrender/mixin/Transformable} target
  15242. * @param {module:zrender/mixin/Transformable} [ancestor]
  15243. */
  15244. function getTransform(target, ancestor) {
  15245. var mat = identity([]);
  15246. while (target && target !== ancestor) {
  15247. mul$1(mat, target.getLocalTransform(), mat);
  15248. target = target.parent;
  15249. }
  15250. return mat;
  15251. }
  15252. /**
  15253. * Apply transform to an vertex.
  15254. * @param {Array.<number>} target [x, y]
  15255. * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:
  15256. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  15257. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  15258. * @param {boolean=} invert Whether use invert matrix.
  15259. * @return {Array.<number>} [x, y]
  15260. */
  15261. function applyTransform$1(target, transform, invert$$1) {
  15262. if (transform && !isArrayLike(transform)) {
  15263. transform = Transformable.getLocalTransform(transform);
  15264. }
  15265. if (invert$$1) {
  15266. transform = invert([], transform);
  15267. }
  15268. return applyTransform([], target, transform);
  15269. }
  15270. /**
  15271. * @param {string} direction 'left' 'right' 'top' 'bottom'
  15272. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  15273. * @param {boolean=} invert Whether use invert matrix.
  15274. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  15275. */
  15276. function transformDirection(direction, transform, invert$$1) {
  15277. // Pick a base, ensure that transform result will not be (0, 0).
  15278. var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)
  15279. ? 1 : Math.abs(2 * transform[4] / transform[0]);
  15280. var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)
  15281. ? 1 : Math.abs(2 * transform[4] / transform[2]);
  15282. var vertex = [
  15283. direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
  15284. direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0
  15285. ];
  15286. vertex = applyTransform$1(vertex, transform, invert$$1);
  15287. return Math.abs(vertex[0]) > Math.abs(vertex[1])
  15288. ? (vertex[0] > 0 ? 'right' : 'left')
  15289. : (vertex[1] > 0 ? 'bottom' : 'top');
  15290. }
  15291. /**
  15292. * Apply group transition animation from g1 to g2.
  15293. * If no animatableModel, no animation.
  15294. */
  15295. function groupTransition(g1, g2, animatableModel, cb) {
  15296. if (!g1 || !g2) {
  15297. return;
  15298. }
  15299. function getElMap(g) {
  15300. var elMap = {};
  15301. g.traverse(function (el) {
  15302. if (!el.isGroup && el.anid) {
  15303. elMap[el.anid] = el;
  15304. }
  15305. });
  15306. return elMap;
  15307. }
  15308. function getAnimatableProps(el) {
  15309. var obj = {
  15310. position: clone$1(el.position),
  15311. rotation: el.rotation
  15312. };
  15313. if (el.shape) {
  15314. obj.shape = extend({}, el.shape);
  15315. }
  15316. return obj;
  15317. }
  15318. var elMap1 = getElMap(g1);
  15319. g2.traverse(function (el) {
  15320. if (!el.isGroup && el.anid) {
  15321. var oldEl = elMap1[el.anid];
  15322. if (oldEl) {
  15323. var newProp = getAnimatableProps(el);
  15324. el.attr(getAnimatableProps(oldEl));
  15325. updateProps(el, newProp, animatableModel, el.dataIndex);
  15326. }
  15327. // else {
  15328. // if (el.previousProps) {
  15329. // graphic.updateProps
  15330. // }
  15331. // }
  15332. }
  15333. });
  15334. }
  15335. /**
  15336. * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]
  15337. * @param {Object} rect {x, y, width, height}
  15338. * @return {Array.<Array.<number>>} A new clipped points.
  15339. */
  15340. function clipPointsByRect(points, rect) {
  15341. // FIXME: this way migth be incorrect when grpahic clipped by a corner.
  15342. // and when element have border.
  15343. return map(points, function (point) {
  15344. var x = point[0];
  15345. x = mathMax$1(x, rect.x);
  15346. x = mathMin$1(x, rect.x + rect.width);
  15347. var y = point[1];
  15348. y = mathMax$1(y, rect.y);
  15349. y = mathMin$1(y, rect.y + rect.height);
  15350. return [x, y];
  15351. });
  15352. }
  15353. /**
  15354. * @param {Object} targetRect {x, y, width, height}
  15355. * @param {Object} rect {x, y, width, height}
  15356. * @return {Object} A new clipped rect. If rect size are negative, return undefined.
  15357. */
  15358. function clipRectByRect(targetRect, rect) {
  15359. var x = mathMax$1(targetRect.x, rect.x);
  15360. var x2 = mathMin$1(targetRect.x + targetRect.width, rect.x + rect.width);
  15361. var y = mathMax$1(targetRect.y, rect.y);
  15362. var y2 = mathMin$1(targetRect.y + targetRect.height, rect.y + rect.height);
  15363. // If the total rect is cliped, nothing, including the border,
  15364. // should be painted. So return undefined.
  15365. if (x2 >= x && y2 >= y) {
  15366. return {
  15367. x: x,
  15368. y: y,
  15369. width: x2 - x,
  15370. height: y2 - y
  15371. };
  15372. }
  15373. }
  15374. /**
  15375. * @param {string} iconStr Support 'image://' or 'path://' or direct svg path.
  15376. * @param {Object} [opt] Properties of `module:zrender/Element`, except `style`.
  15377. * @param {Object} [rect] {x, y, width, height}
  15378. * @return {module:zrender/Element} Icon path or image element.
  15379. */
  15380. function createIcon(iconStr, opt, rect) {
  15381. opt = extend({rectHover: true}, opt);
  15382. var style = opt.style = {strokeNoScale: true};
  15383. rect = rect || {x: -1, y: -1, width: 2, height: 2};
  15384. if (iconStr) {
  15385. return iconStr.indexOf('image://') === 0
  15386. ? (
  15387. style.image = iconStr.slice(8),
  15388. defaults(style, rect),
  15389. new ZImage(opt)
  15390. )
  15391. : (
  15392. makePath(
  15393. iconStr.replace('path://', ''),
  15394. opt,
  15395. rect,
  15396. 'center'
  15397. )
  15398. );
  15399. }
  15400. }
  15401. var graphic = (Object.freeze || Object)({
  15402. Z2_EMPHASIS_LIFT: Z2_EMPHASIS_LIFT,
  15403. extendShape: extendShape,
  15404. extendPath: extendPath,
  15405. makePath: makePath,
  15406. makeImage: makeImage,
  15407. mergePath: mergePath,
  15408. resizePath: resizePath,
  15409. subPixelOptimizeLine: subPixelOptimizeLine,
  15410. subPixelOptimizeRect: subPixelOptimizeRect,
  15411. subPixelOptimize: subPixelOptimize,
  15412. setElementHoverStyle: setElementHoverStyle,
  15413. isInEmphasis: isInEmphasis,
  15414. setHoverStyle: setHoverStyle,
  15415. setAsHoverStyleTrigger: setAsHoverStyleTrigger,
  15416. setLabelStyle: setLabelStyle,
  15417. setTextStyle: setTextStyle,
  15418. setText: setText,
  15419. getFont: getFont,
  15420. updateProps: updateProps,
  15421. initProps: initProps,
  15422. getTransform: getTransform,
  15423. applyTransform: applyTransform$1,
  15424. transformDirection: transformDirection,
  15425. groupTransition: groupTransition,
  15426. clipPointsByRect: clipPointsByRect,
  15427. clipRectByRect: clipRectByRect,
  15428. createIcon: createIcon,
  15429. Group: Group,
  15430. Image: ZImage,
  15431. Text: Text,
  15432. Circle: Circle,
  15433. Sector: Sector,
  15434. Ring: Ring,
  15435. Polygon: Polygon,
  15436. Polyline: Polyline,
  15437. Rect: Rect,
  15438. Line: Line,
  15439. BezierCurve: BezierCurve,
  15440. Arc: Arc,
  15441. IncrementalDisplayable: IncrementalDisplayble,
  15442. CompoundPath: CompoundPath,
  15443. LinearGradient: LinearGradient,
  15444. RadialGradient: RadialGradient,
  15445. BoundingRect: BoundingRect
  15446. });
  15447. /*
  15448. * Licensed to the Apache Software Foundation (ASF) under one
  15449. * or more contributor license agreements. See the NOTICE file
  15450. * distributed with this work for additional information
  15451. * regarding copyright ownership. The ASF licenses this file
  15452. * to you under the Apache License, Version 2.0 (the
  15453. * "License"); you may not use this file except in compliance
  15454. * with the License. You may obtain a copy of the License at
  15455. *
  15456. * http://www.apache.org/licenses/LICENSE-2.0
  15457. *
  15458. * Unless required by applicable law or agreed to in writing,
  15459. * software distributed under the License is distributed on an
  15460. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15461. * KIND, either express or implied. See the License for the
  15462. * specific language governing permissions and limitations
  15463. * under the License.
  15464. */
  15465. var PATH_COLOR = ['textStyle', 'color'];
  15466. var textStyleMixin = {
  15467. /**
  15468. * Get color property or get color from option.textStyle.color
  15469. * @param {boolean} [isEmphasis]
  15470. * @return {string}
  15471. */
  15472. getTextColor: function (isEmphasis) {
  15473. var ecModel = this.ecModel;
  15474. return this.getShallow('color')
  15475. || (
  15476. (!isEmphasis && ecModel) ? ecModel.get(PATH_COLOR) : null
  15477. );
  15478. },
  15479. /**
  15480. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  15481. * @return {string}
  15482. */
  15483. getFont: function () {
  15484. return getFont({
  15485. fontStyle: this.getShallow('fontStyle'),
  15486. fontWeight: this.getShallow('fontWeight'),
  15487. fontSize: this.getShallow('fontSize'),
  15488. fontFamily: this.getShallow('fontFamily')
  15489. }, this.ecModel);
  15490. },
  15491. getTextRect: function (text) {
  15492. return getBoundingRect(
  15493. text,
  15494. this.getFont(),
  15495. this.getShallow('align'),
  15496. this.getShallow('verticalAlign') || this.getShallow('baseline'),
  15497. this.getShallow('padding'),
  15498. this.getShallow('lineHeight'),
  15499. this.getShallow('rich'),
  15500. this.getShallow('truncateText')
  15501. );
  15502. }
  15503. };
  15504. /*
  15505. * Licensed to the Apache Software Foundation (ASF) under one
  15506. * or more contributor license agreements. See the NOTICE file
  15507. * distributed with this work for additional information
  15508. * regarding copyright ownership. The ASF licenses this file
  15509. * to you under the Apache License, Version 2.0 (the
  15510. * "License"); you may not use this file except in compliance
  15511. * with the License. You may obtain a copy of the License at
  15512. *
  15513. * http://www.apache.org/licenses/LICENSE-2.0
  15514. *
  15515. * Unless required by applicable law or agreed to in writing,
  15516. * software distributed under the License is distributed on an
  15517. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15518. * KIND, either express or implied. See the License for the
  15519. * specific language governing permissions and limitations
  15520. * under the License.
  15521. */
  15522. var getItemStyle = makeStyleMapper(
  15523. [
  15524. ['fill', 'color'],
  15525. ['stroke', 'borderColor'],
  15526. ['lineWidth', 'borderWidth'],
  15527. ['opacity'],
  15528. ['shadowBlur'],
  15529. ['shadowOffsetX'],
  15530. ['shadowOffsetY'],
  15531. ['shadowColor'],
  15532. ['textPosition'],
  15533. ['textAlign']
  15534. ]
  15535. );
  15536. var itemStyleMixin = {
  15537. getItemStyle: function (excludes, includes) {
  15538. var style = getItemStyle(this, excludes, includes);
  15539. var lineDash = this.getBorderLineDash();
  15540. lineDash && (style.lineDash = lineDash);
  15541. return style;
  15542. },
  15543. getBorderLineDash: function () {
  15544. var lineType = this.get('borderType');
  15545. return (lineType === 'solid' || lineType == null) ? null
  15546. : (lineType === 'dashed' ? [5, 5] : [1, 1]);
  15547. }
  15548. };
  15549. /*
  15550. * Licensed to the Apache Software Foundation (ASF) under one
  15551. * or more contributor license agreements. See the NOTICE file
  15552. * distributed with this work for additional information
  15553. * regarding copyright ownership. The ASF licenses this file
  15554. * to you under the Apache License, Version 2.0 (the
  15555. * "License"); you may not use this file except in compliance
  15556. * with the License. You may obtain a copy of the License at
  15557. *
  15558. * http://www.apache.org/licenses/LICENSE-2.0
  15559. *
  15560. * Unless required by applicable law or agreed to in writing,
  15561. * software distributed under the License is distributed on an
  15562. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15563. * KIND, either express or implied. See the License for the
  15564. * specific language governing permissions and limitations
  15565. * under the License.
  15566. */
  15567. /**
  15568. * @module echarts/model/Model
  15569. */
  15570. var mixin$1 = mixin;
  15571. var inner = makeInner();
  15572. /**
  15573. * @alias module:echarts/model/Model
  15574. * @constructor
  15575. * @param {Object} [option]
  15576. * @param {module:echarts/model/Model} [parentModel]
  15577. * @param {module:echarts/model/Global} [ecModel]
  15578. */
  15579. function Model(option, parentModel, ecModel) {
  15580. /**
  15581. * @type {module:echarts/model/Model}
  15582. * @readOnly
  15583. */
  15584. this.parentModel = parentModel;
  15585. /**
  15586. * @type {module:echarts/model/Global}
  15587. * @readOnly
  15588. */
  15589. this.ecModel = ecModel;
  15590. /**
  15591. * @type {Object}
  15592. * @protected
  15593. */
  15594. this.option = option;
  15595. // Simple optimization
  15596. // if (this.init) {
  15597. // if (arguments.length <= 4) {
  15598. // this.init(option, parentModel, ecModel, extraOpt);
  15599. // }
  15600. // else {
  15601. // this.init.apply(this, arguments);
  15602. // }
  15603. // }
  15604. }
  15605. Model.prototype = {
  15606. constructor: Model,
  15607. /**
  15608. * Model 的初始化函数
  15609. * @param {Object} option
  15610. */
  15611. init: null,
  15612. /**
  15613. * 从新的 Option merge
  15614. */
  15615. mergeOption: function (option) {
  15616. merge(this.option, option, true);
  15617. },
  15618. /**
  15619. * @param {string|Array.<string>} path
  15620. * @param {boolean} [ignoreParent=false]
  15621. * @return {*}
  15622. */
  15623. get: function (path, ignoreParent) {
  15624. if (path == null) {
  15625. return this.option;
  15626. }
  15627. return doGet(
  15628. this.option,
  15629. this.parsePath(path),
  15630. !ignoreParent && getParent(this, path)
  15631. );
  15632. },
  15633. /**
  15634. * @param {string} key
  15635. * @param {boolean} [ignoreParent=false]
  15636. * @return {*}
  15637. */
  15638. getShallow: function (key, ignoreParent) {
  15639. var option = this.option;
  15640. var val = option == null ? option : option[key];
  15641. var parentModel = !ignoreParent && getParent(this, key);
  15642. if (val == null && parentModel) {
  15643. val = parentModel.getShallow(key);
  15644. }
  15645. return val;
  15646. },
  15647. /**
  15648. * @param {string|Array.<string>} [path]
  15649. * @param {module:echarts/model/Model} [parentModel]
  15650. * @return {module:echarts/model/Model}
  15651. */
  15652. getModel: function (path, parentModel) {
  15653. var obj = path == null
  15654. ? this.option
  15655. : doGet(this.option, path = this.parsePath(path));
  15656. var thisParentModel;
  15657. parentModel = parentModel || (
  15658. (thisParentModel = getParent(this, path))
  15659. && thisParentModel.getModel(path)
  15660. );
  15661. return new Model(obj, parentModel, this.ecModel);
  15662. },
  15663. /**
  15664. * If model has option
  15665. */
  15666. isEmpty: function () {
  15667. return this.option == null;
  15668. },
  15669. restoreData: function () {},
  15670. // Pending
  15671. clone: function () {
  15672. var Ctor = this.constructor;
  15673. return new Ctor(clone(this.option));
  15674. },
  15675. setReadOnly: function (properties) {
  15676. // clazzUtil.setReadOnly(this, properties);
  15677. },
  15678. // If path is null/undefined, return null/undefined.
  15679. parsePath: function (path) {
  15680. if (typeof path === 'string') {
  15681. path = path.split('.');
  15682. }
  15683. return path;
  15684. },
  15685. /**
  15686. * @param {Function} getParentMethod
  15687. * param {Array.<string>|string} path
  15688. * return {module:echarts/model/Model}
  15689. */
  15690. customizeGetParent: function (getParentMethod) {
  15691. inner(this).getParent = getParentMethod;
  15692. },
  15693. isAnimationEnabled: function () {
  15694. if (!env$1.node) {
  15695. if (this.option.animation != null) {
  15696. return !!this.option.animation;
  15697. }
  15698. else if (this.parentModel) {
  15699. return this.parentModel.isAnimationEnabled();
  15700. }
  15701. }
  15702. }
  15703. };
  15704. function doGet(obj, pathArr, parentModel) {
  15705. for (var i = 0; i < pathArr.length; i++) {
  15706. // Ignore empty
  15707. if (!pathArr[i]) {
  15708. continue;
  15709. }
  15710. // obj could be number/string/... (like 0)
  15711. obj = (obj && typeof obj === 'object') ? obj[pathArr[i]] : null;
  15712. if (obj == null) {
  15713. break;
  15714. }
  15715. }
  15716. if (obj == null && parentModel) {
  15717. obj = parentModel.get(pathArr);
  15718. }
  15719. return obj;
  15720. }
  15721. // `path` can be null/undefined
  15722. function getParent(model, path) {
  15723. var getParentMethod = inner(model).getParent;
  15724. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  15725. }
  15726. // Enable Model.extend.
  15727. enableClassExtend(Model);
  15728. enableClassCheck(Model);
  15729. mixin$1(Model, lineStyleMixin);
  15730. mixin$1(Model, areaStyleMixin);
  15731. mixin$1(Model, textStyleMixin);
  15732. mixin$1(Model, itemStyleMixin);
  15733. /*
  15734. * Licensed to the Apache Software Foundation (ASF) under one
  15735. * or more contributor license agreements. See the NOTICE file
  15736. * distributed with this work for additional information
  15737. * regarding copyright ownership. The ASF licenses this file
  15738. * to you under the Apache License, Version 2.0 (the
  15739. * "License"); you may not use this file except in compliance
  15740. * with the License. You may obtain a copy of the License at
  15741. *
  15742. * http://www.apache.org/licenses/LICENSE-2.0
  15743. *
  15744. * Unless required by applicable law or agreed to in writing,
  15745. * software distributed under the License is distributed on an
  15746. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15747. * KIND, either express or implied. See the License for the
  15748. * specific language governing permissions and limitations
  15749. * under the License.
  15750. */
  15751. var base = 0;
  15752. /**
  15753. * @public
  15754. * @param {string} type
  15755. * @return {string}
  15756. */
  15757. function getUID(type) {
  15758. // Considering the case of crossing js context,
  15759. // use Math.random to make id as unique as possible.
  15760. return [(type || ''), base++, Math.random().toFixed(5)].join('_');
  15761. }
  15762. /**
  15763. * @inner
  15764. */
  15765. function enableSubTypeDefaulter(entity) {
  15766. var subTypeDefaulters = {};
  15767. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  15768. componentType = parseClassType$1(componentType);
  15769. subTypeDefaulters[componentType.main] = defaulter;
  15770. };
  15771. entity.determineSubType = function (componentType, option) {
  15772. var type = option.type;
  15773. if (!type) {
  15774. var componentTypeMain = parseClassType$1(componentType).main;
  15775. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  15776. type = subTypeDefaulters[componentTypeMain](option);
  15777. }
  15778. }
  15779. return type;
  15780. };
  15781. return entity;
  15782. }
  15783. /**
  15784. * Topological travel on Activity Network (Activity On Vertices).
  15785. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  15786. *
  15787. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  15788. *
  15789. * If there is circle dependencey, Error will be thrown.
  15790. *
  15791. */
  15792. function enableTopologicalTravel(entity, dependencyGetter) {
  15793. /**
  15794. * @public
  15795. * @param {Array.<string>} targetNameList Target Component type list.
  15796. * Can be ['aa', 'bb', 'aa.xx']
  15797. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  15798. * @param {Function} callback Params: componentType, dependencies.
  15799. * @param {Object} context Scope of callback.
  15800. */
  15801. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  15802. if (!targetNameList.length) {
  15803. return;
  15804. }
  15805. var result = makeDepndencyGraph(fullNameList);
  15806. var graph = result.graph;
  15807. var stack = result.noEntryList;
  15808. var targetNameSet = {};
  15809. each$1(targetNameList, function (name) {
  15810. targetNameSet[name] = true;
  15811. });
  15812. while (stack.length) {
  15813. var currComponentType = stack.pop();
  15814. var currVertex = graph[currComponentType];
  15815. var isInTargetNameSet = !!targetNameSet[currComponentType];
  15816. if (isInTargetNameSet) {
  15817. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  15818. delete targetNameSet[currComponentType];
  15819. }
  15820. each$1(
  15821. currVertex.successor,
  15822. isInTargetNameSet ? removeEdgeAndAdd : removeEdge
  15823. );
  15824. }
  15825. each$1(targetNameSet, function () {
  15826. throw new Error('Circle dependency may exists');
  15827. });
  15828. function removeEdge(succComponentType) {
  15829. graph[succComponentType].entryCount--;
  15830. if (graph[succComponentType].entryCount === 0) {
  15831. stack.push(succComponentType);
  15832. }
  15833. }
  15834. // Consider this case: legend depends on series, and we call
  15835. // chart.setOption({series: [...]}), where only series is in option.
  15836. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  15837. // not be called, but only sereis.mergeOption is called. Thus legend
  15838. // have no chance to update its local record about series (like which
  15839. // name of series is available in legend).
  15840. function removeEdgeAndAdd(succComponentType) {
  15841. targetNameSet[succComponentType] = true;
  15842. removeEdge(succComponentType);
  15843. }
  15844. };
  15845. /**
  15846. * DepndencyGraph: {Object}
  15847. * key: conponentType,
  15848. * value: {
  15849. * successor: [conponentTypes...],
  15850. * originalDeps: [conponentTypes...],
  15851. * entryCount: {number}
  15852. * }
  15853. */
  15854. function makeDepndencyGraph(fullNameList) {
  15855. var graph = {};
  15856. var noEntryList = [];
  15857. each$1(fullNameList, function (name) {
  15858. var thisItem = createDependencyGraphItem(graph, name);
  15859. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  15860. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  15861. thisItem.entryCount = availableDeps.length;
  15862. if (thisItem.entryCount === 0) {
  15863. noEntryList.push(name);
  15864. }
  15865. each$1(availableDeps, function (dependentName) {
  15866. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  15867. thisItem.predecessor.push(dependentName);
  15868. }
  15869. var thatItem = createDependencyGraphItem(graph, dependentName);
  15870. if (indexOf(thatItem.successor, dependentName) < 0) {
  15871. thatItem.successor.push(name);
  15872. }
  15873. });
  15874. });
  15875. return {graph: graph, noEntryList: noEntryList};
  15876. }
  15877. function createDependencyGraphItem(graph, name) {
  15878. if (!graph[name]) {
  15879. graph[name] = {predecessor: [], successor: []};
  15880. }
  15881. return graph[name];
  15882. }
  15883. function getAvailableDependencies(originalDeps, fullNameList) {
  15884. var availableDeps = [];
  15885. each$1(originalDeps, function (dep) {
  15886. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  15887. });
  15888. return availableDeps;
  15889. }
  15890. }
  15891. /*
  15892. * Licensed to the Apache Software Foundation (ASF) under one
  15893. * or more contributor license agreements. See the NOTICE file
  15894. * distributed with this work for additional information
  15895. * regarding copyright ownership. The ASF licenses this file
  15896. * to you under the Apache License, Version 2.0 (the
  15897. * "License"); you may not use this file except in compliance
  15898. * with the License. You may obtain a copy of the License at
  15899. *
  15900. * http://www.apache.org/licenses/LICENSE-2.0
  15901. *
  15902. * Unless required by applicable law or agreed to in writing,
  15903. * software distributed under the License is distributed on an
  15904. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15905. * KIND, either express or implied. See the License for the
  15906. * specific language governing permissions and limitations
  15907. * under the License.
  15908. */
  15909. /*
  15910. * A third-party license is embeded for some of the code in this file:
  15911. * The method "quantile" was copied from "d3.js".
  15912. * (See more details in the comment of the method below.)
  15913. * The use of the source code of this file is also subject to the terms
  15914. * and consitions of the license of "d3.js" (BSD-3Clause, see
  15915. * </licenses/LICENSE-d3>).
  15916. */
  15917. var RADIAN_EPSILON = 1e-4;
  15918. function _trim(str) {
  15919. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  15920. }
  15921. /**
  15922. * Linear mapping a value from domain to range
  15923. * @memberOf module:echarts/util/number
  15924. * @param {(number|Array.<number>)} val
  15925. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  15926. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  15927. * @param {boolean} clamp
  15928. * @return {(number|Array.<number>}
  15929. */
  15930. function linearMap(val, domain, range, clamp) {
  15931. var subDomain = domain[1] - domain[0];
  15932. var subRange = range[1] - range[0];
  15933. if (subDomain === 0) {
  15934. return subRange === 0
  15935. ? range[0]
  15936. : (range[0] + range[1]) / 2;
  15937. }
  15938. // Avoid accuracy problem in edge, such as
  15939. // 146.39 - 62.83 === 83.55999999999999.
  15940. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  15941. // It is a little verbose for efficiency considering this method
  15942. // is a hotspot.
  15943. if (clamp) {
  15944. if (subDomain > 0) {
  15945. if (val <= domain[0]) {
  15946. return range[0];
  15947. }
  15948. else if (val >= domain[1]) {
  15949. return range[1];
  15950. }
  15951. }
  15952. else {
  15953. if (val >= domain[0]) {
  15954. return range[0];
  15955. }
  15956. else if (val <= domain[1]) {
  15957. return range[1];
  15958. }
  15959. }
  15960. }
  15961. else {
  15962. if (val === domain[0]) {
  15963. return range[0];
  15964. }
  15965. if (val === domain[1]) {
  15966. return range[1];
  15967. }
  15968. }
  15969. return (val - domain[0]) / subDomain * subRange + range[0];
  15970. }
  15971. /**
  15972. * Convert a percent string to absolute number.
  15973. * Returns NaN if percent is not a valid string or number
  15974. * @memberOf module:echarts/util/number
  15975. * @param {string|number} percent
  15976. * @param {number} all
  15977. * @return {number}
  15978. */
  15979. function parsePercent$1(percent, all) {
  15980. switch (percent) {
  15981. case 'center':
  15982. case 'middle':
  15983. percent = '50%';
  15984. break;
  15985. case 'left':
  15986. case 'top':
  15987. percent = '0%';
  15988. break;
  15989. case 'right':
  15990. case 'bottom':
  15991. percent = '100%';
  15992. break;
  15993. }
  15994. if (typeof percent === 'string') {
  15995. if (_trim(percent).match(/%$/)) {
  15996. return parseFloat(percent) / 100 * all;
  15997. }
  15998. return parseFloat(percent);
  15999. }
  16000. return percent == null ? NaN : +percent;
  16001. }
  16002. /**
  16003. * (1) Fix rounding error of float numbers.
  16004. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  16005. *
  16006. * @param {number} x
  16007. * @param {number} [precision]
  16008. * @param {boolean} [returnStr]
  16009. * @return {number|string}
  16010. */
  16011. function round$2(x, precision, returnStr) {
  16012. if (precision == null) {
  16013. precision = 10;
  16014. }
  16015. // Avoid range error
  16016. precision = Math.min(Math.max(0, precision), 20);
  16017. x = (+x).toFixed(precision);
  16018. return returnStr ? x : +x;
  16019. }
  16020. function asc(arr) {
  16021. arr.sort(function (a, b) {
  16022. return a - b;
  16023. });
  16024. return arr;
  16025. }
  16026. /**
  16027. * Get precision
  16028. * @param {number} val
  16029. */
  16030. function getPrecision(val) {
  16031. val = +val;
  16032. if (isNaN(val)) {
  16033. return 0;
  16034. }
  16035. // It is much faster than methods converting number to string as follows
  16036. // var tmp = val.toString();
  16037. // return tmp.length - 1 - tmp.indexOf('.');
  16038. // especially when precision is low
  16039. var e = 1;
  16040. var count = 0;
  16041. while (Math.round(val * e) / e !== val) {
  16042. e *= 10;
  16043. count++;
  16044. }
  16045. return count;
  16046. }
  16047. /**
  16048. * @param {string|number} val
  16049. * @return {number}
  16050. */
  16051. function getPrecisionSafe(val) {
  16052. var str = val.toString();
  16053. // Consider scientific notation: '3.4e-12' '3.4e+12'
  16054. var eIndex = str.indexOf('e');
  16055. if (eIndex > 0) {
  16056. var precision = +str.slice(eIndex + 1);
  16057. return precision < 0 ? -precision : 0;
  16058. }
  16059. else {
  16060. var dotIndex = str.indexOf('.');
  16061. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  16062. }
  16063. }
  16064. /**
  16065. * Minimal dicernible data precisioin according to a single pixel.
  16066. *
  16067. * @param {Array.<number>} dataExtent
  16068. * @param {Array.<number>} pixelExtent
  16069. * @return {number} precision
  16070. */
  16071. function getPixelPrecision(dataExtent, pixelExtent) {
  16072. var log = Math.log;
  16073. var LN10 = Math.LN10;
  16074. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  16075. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);
  16076. // toFixed() digits argument must be between 0 and 20.
  16077. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  16078. return !isFinite(precision) ? 20 : precision;
  16079. }
  16080. /**
  16081. * Get a data of given precision, assuring the sum of percentages
  16082. * in valueList is 1.
  16083. * The largest remainer method is used.
  16084. * https://en.wikipedia.org/wiki/Largest_remainder_method
  16085. *
  16086. * @param {Array.<number>} valueList a list of all data
  16087. * @param {number} idx index of the data to be processed in valueList
  16088. * @param {number} precision integer number showing digits of precision
  16089. * @return {number} percent ranging from 0 to 100
  16090. */
  16091. function getPercentWithPrecision(valueList, idx, precision) {
  16092. if (!valueList[idx]) {
  16093. return 0;
  16094. }
  16095. var sum = reduce(valueList, function (acc, val) {
  16096. return acc + (isNaN(val) ? 0 : val);
  16097. }, 0);
  16098. if (sum === 0) {
  16099. return 0;
  16100. }
  16101. var digits = Math.pow(10, precision);
  16102. var votesPerQuota = map(valueList, function (val) {
  16103. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  16104. });
  16105. var targetSeats = digits * 100;
  16106. var seats = map(votesPerQuota, function (votes) {
  16107. // Assign automatic seats.
  16108. return Math.floor(votes);
  16109. });
  16110. var currentSum = reduce(seats, function (acc, val) {
  16111. return acc + val;
  16112. }, 0);
  16113. var remainder = map(votesPerQuota, function (votes, idx) {
  16114. return votes - seats[idx];
  16115. });
  16116. // Has remainding votes.
  16117. while (currentSum < targetSeats) {
  16118. // Find next largest remainder.
  16119. var max = Number.NEGATIVE_INFINITY;
  16120. var maxId = null;
  16121. for (var i = 0, len = remainder.length; i < len; ++i) {
  16122. if (remainder[i] > max) {
  16123. max = remainder[i];
  16124. maxId = i;
  16125. }
  16126. }
  16127. // Add a vote to max remainder.
  16128. ++seats[maxId];
  16129. remainder[maxId] = 0;
  16130. ++currentSum;
  16131. }
  16132. return seats[idx] / digits;
  16133. }
  16134. // Number.MAX_SAFE_INTEGER, ie do not support.
  16135. var MAX_SAFE_INTEGER = 9007199254740991;
  16136. /**
  16137. * To 0 - 2 * PI, considering negative radian.
  16138. * @param {number} radian
  16139. * @return {number}
  16140. */
  16141. function remRadian(radian) {
  16142. var pi2 = Math.PI * 2;
  16143. return (radian % pi2 + pi2) % pi2;
  16144. }
  16145. /**
  16146. * @param {type} radian
  16147. * @return {boolean}
  16148. */
  16149. function isRadianAroundZero(val) {
  16150. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  16151. }
  16152. /* eslint-disable */
  16153. 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
  16154. /* eslint-enable */
  16155. /**
  16156. * @param {string|Date|number} value These values can be accepted:
  16157. * + An instance of Date, represent a time in its own time zone.
  16158. * + Or string in a subset of ISO 8601, only including:
  16159. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  16160. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  16161. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  16162. * all of which will be treated as local time if time zone is not specified
  16163. * (see <https://momentjs.com/>).
  16164. * + Or other string format, including (all of which will be treated as loacal time):
  16165. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  16166. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  16167. * + a timestamp, which represent a time in UTC.
  16168. * @return {Date} date
  16169. */
  16170. function parseDate(value) {
  16171. if (value instanceof Date) {
  16172. return value;
  16173. }
  16174. else if (typeof value === 'string') {
  16175. // Different browsers parse date in different way, so we parse it manually.
  16176. // Some other issues:
  16177. // new Date('1970-01-01') is UTC,
  16178. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  16179. // See issue #3623
  16180. var match = TIME_REG.exec(value);
  16181. if (!match) {
  16182. // return Invalid Date.
  16183. return new Date(NaN);
  16184. }
  16185. // Use local time when no timezone offset specifed.
  16186. if (!match[8]) {
  16187. // match[n] can only be string or undefined.
  16188. // But take care of '12' + 1 => '121'.
  16189. return new Date(
  16190. +match[1],
  16191. +(match[2] || 1) - 1,
  16192. +match[3] || 1,
  16193. +match[4] || 0,
  16194. +(match[5] || 0),
  16195. +match[6] || 0,
  16196. +match[7] || 0
  16197. );
  16198. }
  16199. // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  16200. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  16201. // For example, system timezone is set as "Time Zone: America/Toronto",
  16202. // then these code will get different result:
  16203. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  16204. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  16205. // So we should not use `new Date`, but use `Date.UTC`.
  16206. else {
  16207. var hour = +match[4] || 0;
  16208. if (match[8].toUpperCase() !== 'Z') {
  16209. hour -= match[8].slice(0, 3);
  16210. }
  16211. return new Date(Date.UTC(
  16212. +match[1],
  16213. +(match[2] || 1) - 1,
  16214. +match[3] || 1,
  16215. hour,
  16216. +(match[5] || 0),
  16217. +match[6] || 0,
  16218. +match[7] || 0
  16219. ));
  16220. }
  16221. }
  16222. else if (value == null) {
  16223. return new Date(NaN);
  16224. }
  16225. return new Date(Math.round(value));
  16226. }
  16227. /**
  16228. * Quantity of a number. e.g. 0.1, 1, 10, 100
  16229. *
  16230. * @param {number} val
  16231. * @return {number}
  16232. */
  16233. function quantity(val) {
  16234. return Math.pow(10, quantityExponent(val));
  16235. }
  16236. function quantityExponent(val) {
  16237. return Math.floor(Math.log(val) / Math.LN10);
  16238. }
  16239. /**
  16240. * find a “nice” number approximately equal to x. Round the number if round = true,
  16241. * take ceiling if round = false. The primary observation is that the “nicest”
  16242. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  16243. *
  16244. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  16245. *
  16246. * @param {number} val Non-negative value.
  16247. * @param {boolean} round
  16248. * @return {number}
  16249. */
  16250. function nice(val, round) {
  16251. var exponent = quantityExponent(val);
  16252. var exp10 = Math.pow(10, exponent);
  16253. var f = val / exp10; // 1 <= f < 10
  16254. var nf;
  16255. if (round) {
  16256. if (f < 1.5) {
  16257. nf = 1;
  16258. }
  16259. else if (f < 2.5) {
  16260. nf = 2;
  16261. }
  16262. else if (f < 4) {
  16263. nf = 3;
  16264. }
  16265. else if (f < 7) {
  16266. nf = 5;
  16267. }
  16268. else {
  16269. nf = 10;
  16270. }
  16271. }
  16272. else {
  16273. if (f < 1) {
  16274. nf = 1;
  16275. }
  16276. else if (f < 2) {
  16277. nf = 2;
  16278. }
  16279. else if (f < 3) {
  16280. nf = 3;
  16281. }
  16282. else if (f < 5) {
  16283. nf = 5;
  16284. }
  16285. else {
  16286. nf = 10;
  16287. }
  16288. }
  16289. val = nf * exp10;
  16290. // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  16291. // 20 is the uppper bound of toFixed.
  16292. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  16293. }
  16294. /**
  16295. * This code was copied from "d3.js"
  16296. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  16297. * See the license statement at the head of this file.
  16298. * @param {Array.<number>} ascArr
  16299. */
  16300. function quantile(ascArr, p) {
  16301. var H = (ascArr.length - 1) * p + 1;
  16302. var h = Math.floor(H);
  16303. var v = +ascArr[h - 1];
  16304. var e = H - h;
  16305. return e ? v + e * (ascArr[h] - v) : v;
  16306. }
  16307. /**
  16308. * Order intervals asc, and split them when overlap.
  16309. * expect(numberUtil.reformIntervals([
  16310. * {interval: [18, 62], close: [1, 1]},
  16311. * {interval: [-Infinity, -70], close: [0, 0]},
  16312. * {interval: [-70, -26], close: [1, 1]},
  16313. * {interval: [-26, 18], close: [1, 1]},
  16314. * {interval: [62, 150], close: [1, 1]},
  16315. * {interval: [106, 150], close: [1, 1]},
  16316. * {interval: [150, Infinity], close: [0, 0]}
  16317. * ])).toEqual([
  16318. * {interval: [-Infinity, -70], close: [0, 0]},
  16319. * {interval: [-70, -26], close: [1, 1]},
  16320. * {interval: [-26, 18], close: [0, 1]},
  16321. * {interval: [18, 62], close: [0, 1]},
  16322. * {interval: [62, 150], close: [0, 1]},
  16323. * {interval: [150, Infinity], close: [0, 0]}
  16324. * ]);
  16325. * @param {Array.<Object>} list, where `close` mean open or close
  16326. * of the interval, and Infinity can be used.
  16327. * @return {Array.<Object>} The origin list, which has been reformed.
  16328. */
  16329. function reformIntervals(list) {
  16330. list.sort(function (a, b) {
  16331. return littleThan(a, b, 0) ? -1 : 1;
  16332. });
  16333. var curr = -Infinity;
  16334. var currClose = 1;
  16335. for (var i = 0; i < list.length;) {
  16336. var interval = list[i].interval;
  16337. var close = list[i].close;
  16338. for (var lg = 0; lg < 2; lg++) {
  16339. if (interval[lg] <= curr) {
  16340. interval[lg] = curr;
  16341. close[lg] = !lg ? 1 - currClose : 1;
  16342. }
  16343. curr = interval[lg];
  16344. currClose = close[lg];
  16345. }
  16346. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  16347. list.splice(i, 1);
  16348. }
  16349. else {
  16350. i++;
  16351. }
  16352. }
  16353. return list;
  16354. function littleThan(a, b, lg) {
  16355. return a.interval[lg] < b.interval[lg]
  16356. || (
  16357. a.interval[lg] === b.interval[lg]
  16358. && (
  16359. (a.close[lg] - b.close[lg] === (!lg ? 1 : -1))
  16360. || (!lg && littleThan(a, b, 1))
  16361. )
  16362. );
  16363. }
  16364. }
  16365. /**
  16366. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  16367. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  16368. * subtraction forces infinities to NaN
  16369. *
  16370. * @param {*} v
  16371. * @return {boolean}
  16372. */
  16373. function isNumeric(v) {
  16374. return v - parseFloat(v) >= 0;
  16375. }
  16376. var number = (Object.freeze || Object)({
  16377. linearMap: linearMap,
  16378. parsePercent: parsePercent$1,
  16379. round: round$2,
  16380. asc: asc,
  16381. getPrecision: getPrecision,
  16382. getPrecisionSafe: getPrecisionSafe,
  16383. getPixelPrecision: getPixelPrecision,
  16384. getPercentWithPrecision: getPercentWithPrecision,
  16385. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER,
  16386. remRadian: remRadian,
  16387. isRadianAroundZero: isRadianAroundZero,
  16388. parseDate: parseDate,
  16389. quantity: quantity,
  16390. nice: nice,
  16391. quantile: quantile,
  16392. reformIntervals: reformIntervals,
  16393. isNumeric: isNumeric
  16394. });
  16395. /*
  16396. * Licensed to the Apache Software Foundation (ASF) under one
  16397. * or more contributor license agreements. See the NOTICE file
  16398. * distributed with this work for additional information
  16399. * regarding copyright ownership. The ASF licenses this file
  16400. * to you under the Apache License, Version 2.0 (the
  16401. * "License"); you may not use this file except in compliance
  16402. * with the License. You may obtain a copy of the License at
  16403. *
  16404. * http://www.apache.org/licenses/LICENSE-2.0
  16405. *
  16406. * Unless required by applicable law or agreed to in writing,
  16407. * software distributed under the License is distributed on an
  16408. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16409. * KIND, either express or implied. See the License for the
  16410. * specific language governing permissions and limitations
  16411. * under the License.
  16412. */
  16413. // import Text from 'zrender/src/graphic/Text';
  16414. /**
  16415. * 每三位默认加,格式化
  16416. * @param {string|number} x
  16417. * @return {string}
  16418. */
  16419. function addCommas(x) {
  16420. if (isNaN(x)) {
  16421. return '-';
  16422. }
  16423. x = (x + '').split('.');
  16424. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,')
  16425. + (x.length > 1 ? ('.' + x[1]) : '');
  16426. }
  16427. /**
  16428. * @param {string} str
  16429. * @param {boolean} [upperCaseFirst=false]
  16430. * @return {string} str
  16431. */
  16432. function toCamelCase(str, upperCaseFirst) {
  16433. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  16434. return group1.toUpperCase();
  16435. });
  16436. if (upperCaseFirst && str) {
  16437. str = str.charAt(0).toUpperCase() + str.slice(1);
  16438. }
  16439. return str;
  16440. }
  16441. var normalizeCssArray$1 = normalizeCssArray;
  16442. var replaceReg = /([&<>"'])/g;
  16443. var replaceMap = {
  16444. '&': '&amp;',
  16445. '<': '&lt;',
  16446. '>': '&gt;',
  16447. '"': '&quot;',
  16448. '\'': '&#39;'
  16449. };
  16450. function encodeHTML(source) {
  16451. return source == null
  16452. ? ''
  16453. : (source + '').replace(replaceReg, function (str, c) {
  16454. return replaceMap[c];
  16455. });
  16456. }
  16457. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  16458. var wrapVar = function (varName, seriesIdx) {
  16459. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  16460. };
  16461. /**
  16462. * Template formatter
  16463. * @param {string} tpl
  16464. * @param {Array.<Object>|Object} paramsList
  16465. * @param {boolean} [encode=false]
  16466. * @return {string}
  16467. */
  16468. function formatTpl(tpl, paramsList, encode) {
  16469. if (!isArray(paramsList)) {
  16470. paramsList = [paramsList];
  16471. }
  16472. var seriesLen = paramsList.length;
  16473. if (!seriesLen) {
  16474. return '';
  16475. }
  16476. var $vars = paramsList[0].$vars || [];
  16477. for (var i = 0; i < $vars.length; i++) {
  16478. var alias = TPL_VAR_ALIAS[i];
  16479. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  16480. }
  16481. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  16482. for (var k = 0; k < $vars.length; k++) {
  16483. var val = paramsList[seriesIdx][$vars[k]];
  16484. tpl = tpl.replace(
  16485. wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
  16486. encode ? encodeHTML(val) : val
  16487. );
  16488. }
  16489. }
  16490. return tpl;
  16491. }
  16492. /**
  16493. * simple Template formatter
  16494. *
  16495. * @param {string} tpl
  16496. * @param {Object} param
  16497. * @param {boolean} [encode=false]
  16498. * @return {string}
  16499. */
  16500. function formatTplSimple(tpl, param, encode) {
  16501. each$1(param, function (value, key) {
  16502. tpl = tpl.replace(
  16503. '{' + key + '}',
  16504. encode ? encodeHTML(value) : value
  16505. );
  16506. });
  16507. return tpl;
  16508. }
  16509. /**
  16510. * @param {Object|string} [opt] If string, means color.
  16511. * @param {string} [opt.color]
  16512. * @param {string} [opt.extraCssText]
  16513. * @param {string} [opt.type='item'] 'item' or 'subItem'
  16514. * @param {string} [opt.renderMode='html'] render mode of tooltip, 'html' or 'richText'
  16515. * @param {string} [opt.markerId='X'] id name for marker. If only one marker is in a rich text, this can be omitted.
  16516. * @return {string}
  16517. */
  16518. function getTooltipMarker(opt, extraCssText) {
  16519. opt = isString(opt) ? {color: opt, extraCssText: extraCssText} : (opt || {});
  16520. var color = opt.color;
  16521. var type = opt.type;
  16522. var extraCssText = opt.extraCssText;
  16523. var renderMode = opt.renderMode || 'html';
  16524. var markerId = opt.markerId || 'X';
  16525. if (!color) {
  16526. return '';
  16527. }
  16528. if (renderMode === 'html') {
  16529. return type === 'subItem'
  16530. ? '<span style="display:inline-block;vertical-align:middle;margin-right:8px;margin-left:3px;'
  16531. + 'border-radius:4px;width:4px;height:4px;background-color:'
  16532. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>'
  16533. : '<span style="display:inline-block;margin-right:5px;'
  16534. + 'border-radius:10px;width:10px;height:10px;background-color:'
  16535. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>';
  16536. }
  16537. else {
  16538. // Space for rich element marker
  16539. return {
  16540. renderMode: renderMode,
  16541. content: '{marker' + markerId + '|} ',
  16542. style: {
  16543. color: color
  16544. }
  16545. };
  16546. }
  16547. }
  16548. function pad(str, len) {
  16549. str += '';
  16550. return '0000'.substr(0, len - str.length) + str;
  16551. }
  16552. /**
  16553. * ISO Date format
  16554. * @param {string} tpl
  16555. * @param {number} value
  16556. * @param {boolean} [isUTC=false] Default in local time.
  16557. * see `module:echarts/scale/Time`
  16558. * and `module:echarts/util/number#parseDate`.
  16559. * @inner
  16560. */
  16561. function formatTime(tpl, value, isUTC) {
  16562. if (tpl === 'week'
  16563. || tpl === 'month'
  16564. || tpl === 'quarter'
  16565. || tpl === 'half-year'
  16566. || tpl === 'year'
  16567. ) {
  16568. tpl = 'MM-dd\nyyyy';
  16569. }
  16570. var date = parseDate(value);
  16571. var utc = isUTC ? 'UTC' : '';
  16572. var y = date['get' + utc + 'FullYear']();
  16573. var M = date['get' + utc + 'Month']() + 1;
  16574. var d = date['get' + utc + 'Date']();
  16575. var h = date['get' + utc + 'Hours']();
  16576. var m = date['get' + utc + 'Minutes']();
  16577. var s = date['get' + utc + 'Seconds']();
  16578. var S = date['get' + utc + 'Milliseconds']();
  16579. tpl = tpl.replace('MM', pad(M, 2))
  16580. .replace('M', M)
  16581. .replace('yyyy', y)
  16582. .replace('yy', y % 100)
  16583. .replace('dd', pad(d, 2))
  16584. .replace('d', d)
  16585. .replace('hh', pad(h, 2))
  16586. .replace('h', h)
  16587. .replace('mm', pad(m, 2))
  16588. .replace('m', m)
  16589. .replace('ss', pad(s, 2))
  16590. .replace('s', s)
  16591. .replace('SSS', pad(S, 3));
  16592. return tpl;
  16593. }
  16594. /**
  16595. * Capital first
  16596. * @param {string} str
  16597. * @return {string}
  16598. */
  16599. function capitalFirst(str) {
  16600. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  16601. }
  16602. var truncateText$1 = truncateText;
  16603. /**
  16604. * @public
  16605. * @param {Object} opt
  16606. * @param {string} opt.text
  16607. * @param {string} opt.font
  16608. * @param {string} [opt.textAlign='left']
  16609. * @param {string} [opt.textVerticalAlign='top']
  16610. * @param {Array.<number>} [opt.textPadding]
  16611. * @param {number} [opt.textLineHeight]
  16612. * @param {Object} [opt.rich]
  16613. * @param {Object} [opt.truncate]
  16614. * @return {Object} {x, y, width, height, lineHeight}
  16615. */
  16616. function getTextBoundingRect(opt) {
  16617. return getBoundingRect(
  16618. opt.text,
  16619. opt.font,
  16620. opt.textAlign,
  16621. opt.textVerticalAlign,
  16622. opt.textPadding,
  16623. opt.textLineHeight,
  16624. opt.rich,
  16625. opt.truncate
  16626. );
  16627. }
  16628. /**
  16629. * @deprecated
  16630. * the `textLineHeight` was added later.
  16631. * For backward compatiblility, put it as the last parameter.
  16632. * But deprecated this interface. Please use `getTextBoundingRect` instead.
  16633. */
  16634. function getTextRect(
  16635. text, font, textAlign, textVerticalAlign, textPadding, rich, truncate, textLineHeight
  16636. ) {
  16637. return getBoundingRect(
  16638. text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate
  16639. );
  16640. }
  16641. var format = (Object.freeze || Object)({
  16642. addCommas: addCommas,
  16643. toCamelCase: toCamelCase,
  16644. normalizeCssArray: normalizeCssArray$1,
  16645. encodeHTML: encodeHTML,
  16646. formatTpl: formatTpl,
  16647. formatTplSimple: formatTplSimple,
  16648. getTooltipMarker: getTooltipMarker,
  16649. formatTime: formatTime,
  16650. capitalFirst: capitalFirst,
  16651. truncateText: truncateText$1,
  16652. getTextBoundingRect: getTextBoundingRect,
  16653. getTextRect: getTextRect
  16654. });
  16655. /*
  16656. * Licensed to the Apache Software Foundation (ASF) under one
  16657. * or more contributor license agreements. See the NOTICE file
  16658. * distributed with this work for additional information
  16659. * regarding copyright ownership. The ASF licenses this file
  16660. * to you under the Apache License, Version 2.0 (the
  16661. * "License"); you may not use this file except in compliance
  16662. * with the License. You may obtain a copy of the License at
  16663. *
  16664. * http://www.apache.org/licenses/LICENSE-2.0
  16665. *
  16666. * Unless required by applicable law or agreed to in writing,
  16667. * software distributed under the License is distributed on an
  16668. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16669. * KIND, either express or implied. See the License for the
  16670. * specific language governing permissions and limitations
  16671. * under the License.
  16672. */
  16673. // Layout helpers for each component positioning
  16674. var each$3 = each$1;
  16675. /**
  16676. * @public
  16677. */
  16678. var LOCATION_PARAMS = [
  16679. 'left', 'right', 'top', 'bottom', 'width', 'height'
  16680. ];
  16681. /**
  16682. * @public
  16683. */
  16684. var HV_NAMES = [
  16685. ['width', 'left', 'right'],
  16686. ['height', 'top', 'bottom']
  16687. ];
  16688. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  16689. var x = 0;
  16690. var y = 0;
  16691. if (maxWidth == null) {
  16692. maxWidth = Infinity;
  16693. }
  16694. if (maxHeight == null) {
  16695. maxHeight = Infinity;
  16696. }
  16697. var currentLineMaxSize = 0;
  16698. group.eachChild(function (child, idx) {
  16699. var position = child.position;
  16700. var rect = child.getBoundingRect();
  16701. var nextChild = group.childAt(idx + 1);
  16702. var nextChildRect = nextChild && nextChild.getBoundingRect();
  16703. var nextX;
  16704. var nextY;
  16705. if (orient === 'horizontal') {
  16706. var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);
  16707. nextX = x + moveX;
  16708. // Wrap when width exceeds maxWidth or meet a `newline` group
  16709. // FIXME compare before adding gap?
  16710. if (nextX > maxWidth || child.newline) {
  16711. x = 0;
  16712. nextX = moveX;
  16713. y += currentLineMaxSize + gap;
  16714. currentLineMaxSize = rect.height;
  16715. }
  16716. else {
  16717. // FIXME: consider rect.y is not `0`?
  16718. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  16719. }
  16720. }
  16721. else {
  16722. var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);
  16723. nextY = y + moveY;
  16724. // Wrap when width exceeds maxHeight or meet a `newline` group
  16725. if (nextY > maxHeight || child.newline) {
  16726. x += currentLineMaxSize + gap;
  16727. y = 0;
  16728. nextY = moveY;
  16729. currentLineMaxSize = rect.width;
  16730. }
  16731. else {
  16732. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  16733. }
  16734. }
  16735. if (child.newline) {
  16736. return;
  16737. }
  16738. position[0] = x;
  16739. position[1] = y;
  16740. orient === 'horizontal'
  16741. ? (x = nextX + gap)
  16742. : (y = nextY + gap);
  16743. });
  16744. }
  16745. /**
  16746. * VBox or HBox layouting
  16747. * @param {string} orient
  16748. * @param {module:zrender/container/Group} group
  16749. * @param {number} gap
  16750. * @param {number} [width=Infinity]
  16751. * @param {number} [height=Infinity]
  16752. */
  16753. var box = boxLayout;
  16754. /**
  16755. * VBox layouting
  16756. * @param {module:zrender/container/Group} group
  16757. * @param {number} gap
  16758. * @param {number} [width=Infinity]
  16759. * @param {number} [height=Infinity]
  16760. */
  16761. var vbox = curry(boxLayout, 'vertical');
  16762. /**
  16763. * HBox layouting
  16764. * @param {module:zrender/container/Group} group
  16765. * @param {number} gap
  16766. * @param {number} [width=Infinity]
  16767. * @param {number} [height=Infinity]
  16768. */
  16769. var hbox = curry(boxLayout, 'horizontal');
  16770. /**
  16771. * If x or x2 is not specified or 'center' 'left' 'right',
  16772. * the width would be as long as possible.
  16773. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  16774. * the height would be as long as possible.
  16775. *
  16776. * @param {Object} positionInfo
  16777. * @param {number|string} [positionInfo.x]
  16778. * @param {number|string} [positionInfo.y]
  16779. * @param {number|string} [positionInfo.x2]
  16780. * @param {number|string} [positionInfo.y2]
  16781. * @param {Object} containerRect {width, height}
  16782. * @param {string|number} margin
  16783. * @return {Object} {width, height}
  16784. */
  16785. function getAvailableSize(positionInfo, containerRect, margin) {
  16786. var containerWidth = containerRect.width;
  16787. var containerHeight = containerRect.height;
  16788. var x = parsePercent$1(positionInfo.x, containerWidth);
  16789. var y = parsePercent$1(positionInfo.y, containerHeight);
  16790. var x2 = parsePercent$1(positionInfo.x2, containerWidth);
  16791. var y2 = parsePercent$1(positionInfo.y2, containerHeight);
  16792. (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);
  16793. (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);
  16794. (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);
  16795. (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);
  16796. margin = normalizeCssArray$1(margin || 0);
  16797. return {
  16798. width: Math.max(x2 - x - margin[1] - margin[3], 0),
  16799. height: Math.max(y2 - y - margin[0] - margin[2], 0)
  16800. };
  16801. }
  16802. /**
  16803. * Parse position info.
  16804. *
  16805. * @param {Object} positionInfo
  16806. * @param {number|string} [positionInfo.left]
  16807. * @param {number|string} [positionInfo.top]
  16808. * @param {number|string} [positionInfo.right]
  16809. * @param {number|string} [positionInfo.bottom]
  16810. * @param {number|string} [positionInfo.width]
  16811. * @param {number|string} [positionInfo.height]
  16812. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  16813. * @param {Object} containerRect
  16814. * @param {string|number} [margin]
  16815. *
  16816. * @return {module:zrender/core/BoundingRect}
  16817. */
  16818. function getLayoutRect(
  16819. positionInfo, containerRect, margin
  16820. ) {
  16821. margin = normalizeCssArray$1(margin || 0);
  16822. var containerWidth = containerRect.width;
  16823. var containerHeight = containerRect.height;
  16824. var left = parsePercent$1(positionInfo.left, containerWidth);
  16825. var top = parsePercent$1(positionInfo.top, containerHeight);
  16826. var right = parsePercent$1(positionInfo.right, containerWidth);
  16827. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  16828. var width = parsePercent$1(positionInfo.width, containerWidth);
  16829. var height = parsePercent$1(positionInfo.height, containerHeight);
  16830. var verticalMargin = margin[2] + margin[0];
  16831. var horizontalMargin = margin[1] + margin[3];
  16832. var aspect = positionInfo.aspect;
  16833. // If width is not specified, calculate width from left and right
  16834. if (isNaN(width)) {
  16835. width = containerWidth - right - horizontalMargin - left;
  16836. }
  16837. if (isNaN(height)) {
  16838. height = containerHeight - bottom - verticalMargin - top;
  16839. }
  16840. if (aspect != null) {
  16841. // If width and height are not given
  16842. // 1. Graph should not exceeds the container
  16843. // 2. Aspect must be keeped
  16844. // 3. Graph should take the space as more as possible
  16845. // FIXME
  16846. // Margin is not considered, because there is no case that both
  16847. // using margin and aspect so far.
  16848. if (isNaN(width) && isNaN(height)) {
  16849. if (aspect > containerWidth / containerHeight) {
  16850. width = containerWidth * 0.8;
  16851. }
  16852. else {
  16853. height = containerHeight * 0.8;
  16854. }
  16855. }
  16856. // Calculate width or height with given aspect
  16857. if (isNaN(width)) {
  16858. width = aspect * height;
  16859. }
  16860. if (isNaN(height)) {
  16861. height = width / aspect;
  16862. }
  16863. }
  16864. // If left is not specified, calculate left from right and width
  16865. if (isNaN(left)) {
  16866. left = containerWidth - right - width - horizontalMargin;
  16867. }
  16868. if (isNaN(top)) {
  16869. top = containerHeight - bottom - height - verticalMargin;
  16870. }
  16871. // Align left and top
  16872. switch (positionInfo.left || positionInfo.right) {
  16873. case 'center':
  16874. left = containerWidth / 2 - width / 2 - margin[3];
  16875. break;
  16876. case 'right':
  16877. left = containerWidth - width - horizontalMargin;
  16878. break;
  16879. }
  16880. switch (positionInfo.top || positionInfo.bottom) {
  16881. case 'middle':
  16882. case 'center':
  16883. top = containerHeight / 2 - height / 2 - margin[0];
  16884. break;
  16885. case 'bottom':
  16886. top = containerHeight - height - verticalMargin;
  16887. break;
  16888. }
  16889. // If something is wrong and left, top, width, height are calculated as NaN
  16890. left = left || 0;
  16891. top = top || 0;
  16892. if (isNaN(width)) {
  16893. // Width may be NaN if only one value is given except width
  16894. width = containerWidth - horizontalMargin - left - (right || 0);
  16895. }
  16896. if (isNaN(height)) {
  16897. // Height may be NaN if only one value is given except height
  16898. height = containerHeight - verticalMargin - top - (bottom || 0);
  16899. }
  16900. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  16901. rect.margin = margin;
  16902. return rect;
  16903. }
  16904. /**
  16905. * Position a zr element in viewport
  16906. * Group position is specified by either
  16907. * {left, top}, {right, bottom}
  16908. * If all properties exists, right and bottom will be igonred.
  16909. *
  16910. * Logic:
  16911. * 1. Scale (against origin point in parent coord)
  16912. * 2. Rotate (against origin point in parent coord)
  16913. * 3. Traslate (with el.position by this method)
  16914. * So this method only fixes the last step 'Traslate', which does not affect
  16915. * scaling and rotating.
  16916. *
  16917. * If be called repeatly with the same input el, the same result will be gotten.
  16918. *
  16919. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  16920. * @param {Object} positionInfo
  16921. * @param {number|string} [positionInfo.left]
  16922. * @param {number|string} [positionInfo.top]
  16923. * @param {number|string} [positionInfo.right]
  16924. * @param {number|string} [positionInfo.bottom]
  16925. * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'
  16926. * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'
  16927. * @param {Object} containerRect
  16928. * @param {string|number} margin
  16929. * @param {Object} [opt]
  16930. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  16931. * @param {Array.<number>} [opt.boundingMode='all']
  16932. * Specify how to calculate boundingRect when locating.
  16933. * 'all': Position the boundingRect that is transformed and uioned
  16934. * both itself and its descendants.
  16935. * This mode simplies confine the elements in the bounding
  16936. * of their container (e.g., using 'right: 0').
  16937. * 'raw': Position the boundingRect that is not transformed and only itself.
  16938. * This mode is useful when you want a element can overflow its
  16939. * container. (Consider a rotated circle needs to be located in a corner.)
  16940. * In this mode positionInfo.width/height can only be number.
  16941. */
  16942. function positionElement(el, positionInfo, containerRect, margin, opt) {
  16943. var h = !opt || !opt.hv || opt.hv[0];
  16944. var v = !opt || !opt.hv || opt.hv[1];
  16945. var boundingMode = opt && opt.boundingMode || 'all';
  16946. if (!h && !v) {
  16947. return;
  16948. }
  16949. var rect;
  16950. if (boundingMode === 'raw') {
  16951. rect = el.type === 'group'
  16952. ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0)
  16953. : el.getBoundingRect();
  16954. }
  16955. else {
  16956. rect = el.getBoundingRect();
  16957. if (el.needLocalTransform()) {
  16958. var transform = el.getLocalTransform();
  16959. // Notice: raw rect may be inner object of el,
  16960. // which should not be modified.
  16961. rect = rect.clone();
  16962. rect.applyTransform(transform);
  16963. }
  16964. }
  16965. // The real width and height can not be specified but calculated by the given el.
  16966. positionInfo = getLayoutRect(
  16967. defaults(
  16968. {width: rect.width, height: rect.height},
  16969. positionInfo
  16970. ),
  16971. containerRect,
  16972. margin
  16973. );
  16974. // Because 'tranlate' is the last step in transform
  16975. // (see zrender/core/Transformable#getLocalTransform),
  16976. // we can just only modify el.position to get final result.
  16977. var elPos = el.position;
  16978. var dx = h ? positionInfo.x - rect.x : 0;
  16979. var dy = v ? positionInfo.y - rect.y : 0;
  16980. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  16981. }
  16982. /**
  16983. * @param {Object} option Contains some of the properties in HV_NAMES.
  16984. * @param {number} hvIdx 0: horizontal; 1: vertical.
  16985. */
  16986. function sizeCalculable(option, hvIdx) {
  16987. return option[HV_NAMES[hvIdx][0]] != null
  16988. || (option[HV_NAMES[hvIdx][1]] != null && option[HV_NAMES[hvIdx][2]] != null);
  16989. }
  16990. /**
  16991. * Consider Case:
  16992. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  16993. * through setOption or media query, using normal zrUtil.merge will cause
  16994. * {right: 0} does not take effect.
  16995. *
  16996. * @example
  16997. * ComponentModel.extend({
  16998. * init: function () {
  16999. * ...
  17000. * var inputPositionParams = layout.getLayoutParams(option);
  17001. * this.mergeOption(inputPositionParams);
  17002. * },
  17003. * mergeOption: function (newOption) {
  17004. * newOption && zrUtil.merge(thisOption, newOption, true);
  17005. * layout.mergeLayoutParam(thisOption, newOption);
  17006. * }
  17007. * });
  17008. *
  17009. * @param {Object} targetOption
  17010. * @param {Object} newOption
  17011. * @param {Object|string} [opt]
  17012. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components
  17013. * that width (or height) should not be calculated by left and right (or top and bottom).
  17014. */
  17015. function mergeLayoutParam(targetOption, newOption, opt) {
  17016. !isObject$1(opt) && (opt = {});
  17017. var ignoreSize = opt.ignoreSize;
  17018. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  17019. var hResult = merge$$1(HV_NAMES[0], 0);
  17020. var vResult = merge$$1(HV_NAMES[1], 1);
  17021. copy(HV_NAMES[0], targetOption, hResult);
  17022. copy(HV_NAMES[1], targetOption, vResult);
  17023. function merge$$1(names, hvIdx) {
  17024. var newParams = {};
  17025. var newValueCount = 0;
  17026. var merged = {};
  17027. var mergedValueCount = 0;
  17028. var enoughParamNumber = 2;
  17029. each$3(names, function (name) {
  17030. merged[name] = targetOption[name];
  17031. });
  17032. each$3(names, function (name) {
  17033. // Consider case: newOption.width is null, which is
  17034. // set by user for removing width setting.
  17035. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  17036. hasValue(newParams, name) && newValueCount++;
  17037. hasValue(merged, name) && mergedValueCount++;
  17038. });
  17039. if (ignoreSize[hvIdx]) {
  17040. // Only one of left/right is premitted to exist.
  17041. if (hasValue(newOption, names[1])) {
  17042. merged[names[2]] = null;
  17043. }
  17044. else if (hasValue(newOption, names[2])) {
  17045. merged[names[1]] = null;
  17046. }
  17047. return merged;
  17048. }
  17049. // Case: newOption: {width: ..., right: ...},
  17050. // or targetOption: {right: ...} and newOption: {width: ...},
  17051. // There is no conflict when merged only has params count
  17052. // little than enoughParamNumber.
  17053. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  17054. return merged;
  17055. }
  17056. // Case: newOption: {width: ..., right: ...},
  17057. // Than we can make sure user only want those two, and ignore
  17058. // all origin params in targetOption.
  17059. else if (newValueCount >= enoughParamNumber) {
  17060. return newParams;
  17061. }
  17062. else {
  17063. // Chose another param from targetOption by priority.
  17064. for (var i = 0; i < names.length; i++) {
  17065. var name = names[i];
  17066. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  17067. newParams[name] = targetOption[name];
  17068. break;
  17069. }
  17070. }
  17071. return newParams;
  17072. }
  17073. }
  17074. function hasProp(obj, name) {
  17075. return obj.hasOwnProperty(name);
  17076. }
  17077. function hasValue(obj, name) {
  17078. return obj[name] != null && obj[name] !== 'auto';
  17079. }
  17080. function copy(names, target, source) {
  17081. each$3(names, function (name) {
  17082. target[name] = source[name];
  17083. });
  17084. }
  17085. }
  17086. /**
  17087. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  17088. * @param {Object} source
  17089. * @return {Object} Result contains those props.
  17090. */
  17091. function getLayoutParams(source) {
  17092. return copyLayoutParams({}, source);
  17093. }
  17094. /**
  17095. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  17096. * @param {Object} source
  17097. * @return {Object} Result contains those props.
  17098. */
  17099. function copyLayoutParams(target, source) {
  17100. source && target && each$3(LOCATION_PARAMS, function (name) {
  17101. source.hasOwnProperty(name) && (target[name] = source[name]);
  17102. });
  17103. return target;
  17104. }
  17105. /*
  17106. * Licensed to the Apache Software Foundation (ASF) under one
  17107. * or more contributor license agreements. See the NOTICE file
  17108. * distributed with this work for additional information
  17109. * regarding copyright ownership. The ASF licenses this file
  17110. * to you under the Apache License, Version 2.0 (the
  17111. * "License"); you may not use this file except in compliance
  17112. * with the License. You may obtain a copy of the License at
  17113. *
  17114. * http://www.apache.org/licenses/LICENSE-2.0
  17115. *
  17116. * Unless required by applicable law or agreed to in writing,
  17117. * software distributed under the License is distributed on an
  17118. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17119. * KIND, either express or implied. See the License for the
  17120. * specific language governing permissions and limitations
  17121. * under the License.
  17122. */
  17123. var boxLayoutMixin = {
  17124. getBoxLayoutParams: function () {
  17125. return {
  17126. left: this.get('left'),
  17127. top: this.get('top'),
  17128. right: this.get('right'),
  17129. bottom: this.get('bottom'),
  17130. width: this.get('width'),
  17131. height: this.get('height')
  17132. };
  17133. }
  17134. };
  17135. /*
  17136. * Licensed to the Apache Software Foundation (ASF) under one
  17137. * or more contributor license agreements. See the NOTICE file
  17138. * distributed with this work for additional information
  17139. * regarding copyright ownership. The ASF licenses this file
  17140. * to you under the Apache License, Version 2.0 (the
  17141. * "License"); you may not use this file except in compliance
  17142. * with the License. You may obtain a copy of the License at
  17143. *
  17144. * http://www.apache.org/licenses/LICENSE-2.0
  17145. *
  17146. * Unless required by applicable law or agreed to in writing,
  17147. * software distributed under the License is distributed on an
  17148. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17149. * KIND, either express or implied. See the License for the
  17150. * specific language governing permissions and limitations
  17151. * under the License.
  17152. */
  17153. /**
  17154. * Component model
  17155. *
  17156. * @module echarts/model/Component
  17157. */
  17158. var inner$1 = makeInner();
  17159. /**
  17160. * @alias module:echarts/model/Component
  17161. * @constructor
  17162. * @param {Object} option
  17163. * @param {module:echarts/model/Model} parentModel
  17164. * @param {module:echarts/model/Model} ecModel
  17165. */
  17166. var ComponentModel = Model.extend({
  17167. type: 'component',
  17168. /**
  17169. * @readOnly
  17170. * @type {string}
  17171. */
  17172. id: '',
  17173. /**
  17174. * Because simplified concept is probably better, series.name (or component.name)
  17175. * has been having too many resposibilities:
  17176. * (1) Generating id (which requires name in option should not be modified).
  17177. * (2) As an index to mapping series when merging option or calling API (a name
  17178. * can refer to more then one components, which is convinient is some case).
  17179. * (3) Display.
  17180. * @readOnly
  17181. */
  17182. name: '',
  17183. /**
  17184. * @readOnly
  17185. * @type {string}
  17186. */
  17187. mainType: '',
  17188. /**
  17189. * @readOnly
  17190. * @type {string}
  17191. */
  17192. subType: '',
  17193. /**
  17194. * @readOnly
  17195. * @type {number}
  17196. */
  17197. componentIndex: 0,
  17198. /**
  17199. * @type {Object}
  17200. * @protected
  17201. */
  17202. defaultOption: null,
  17203. /**
  17204. * @type {module:echarts/model/Global}
  17205. * @readOnly
  17206. */
  17207. ecModel: null,
  17208. /**
  17209. * key: componentType
  17210. * value: Component model list, can not be null.
  17211. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  17212. * @readOnly
  17213. */
  17214. dependentModels: [],
  17215. /**
  17216. * @type {string}
  17217. * @readOnly
  17218. */
  17219. uid: null,
  17220. /**
  17221. * Support merge layout params.
  17222. * Only support 'box' now (left/right/top/bottom/width/height).
  17223. * @type {string|Object} Object can be {ignoreSize: true}
  17224. * @readOnly
  17225. */
  17226. layoutMode: null,
  17227. $constructor: function (option, parentModel, ecModel, extraOpt) {
  17228. Model.call(this, option, parentModel, ecModel, extraOpt);
  17229. this.uid = getUID('ec_cpt_model');
  17230. },
  17231. init: function (option, parentModel, ecModel, extraOpt) {
  17232. this.mergeDefaultAndTheme(option, ecModel);
  17233. },
  17234. mergeDefaultAndTheme: function (option, ecModel) {
  17235. var layoutMode = this.layoutMode;
  17236. var inputPositionParams = layoutMode
  17237. ? getLayoutParams(option) : {};
  17238. var themeModel = ecModel.getTheme();
  17239. merge(option, themeModel.get(this.mainType));
  17240. merge(option, this.getDefaultOption());
  17241. if (layoutMode) {
  17242. mergeLayoutParam(option, inputPositionParams, layoutMode);
  17243. }
  17244. },
  17245. mergeOption: function (option, extraOpt) {
  17246. merge(this.option, option, true);
  17247. var layoutMode = this.layoutMode;
  17248. if (layoutMode) {
  17249. mergeLayoutParam(this.option, option, layoutMode);
  17250. }
  17251. },
  17252. // Hooker after init or mergeOption
  17253. optionUpdated: function (newCptOption, isInit) {},
  17254. getDefaultOption: function () {
  17255. var fields = inner$1(this);
  17256. if (!fields.defaultOption) {
  17257. var optList = [];
  17258. var Class = this.constructor;
  17259. while (Class) {
  17260. var opt = Class.prototype.defaultOption;
  17261. opt && optList.push(opt);
  17262. Class = Class.superClass;
  17263. }
  17264. var defaultOption = {};
  17265. for (var i = optList.length - 1; i >= 0; i--) {
  17266. defaultOption = merge(defaultOption, optList[i], true);
  17267. }
  17268. fields.defaultOption = defaultOption;
  17269. }
  17270. return fields.defaultOption;
  17271. },
  17272. getReferringComponents: function (mainType) {
  17273. return this.ecModel.queryComponents({
  17274. mainType: mainType,
  17275. index: this.get(mainType + 'Index', true),
  17276. id: this.get(mainType + 'Id', true)
  17277. });
  17278. }
  17279. });
  17280. // Reset ComponentModel.extend, add preConstruct.
  17281. // clazzUtil.enableClassExtend(
  17282. // ComponentModel,
  17283. // function (option, parentModel, ecModel, extraOpt) {
  17284. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  17285. // zrUtil.extend(this, extraOpt);
  17286. // this.uid = componentUtil.getUID('componentModel');
  17287. // // this.setReadOnly([
  17288. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  17289. // // 'dependentModels', 'componentIndex'
  17290. // // ]);
  17291. // }
  17292. // );
  17293. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  17294. enableClassManagement(
  17295. ComponentModel, {registerWhenExtend: true}
  17296. );
  17297. enableSubTypeDefaulter(ComponentModel);
  17298. // Add capability of ComponentModel.topologicalTravel.
  17299. enableTopologicalTravel(ComponentModel, getDependencies);
  17300. function getDependencies(componentType) {
  17301. var deps = [];
  17302. each$1(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  17303. deps = deps.concat(Clazz.prototype.dependencies || []);
  17304. });
  17305. // Ensure main type.
  17306. deps = map(deps, function (type) {
  17307. return parseClassType$1(type).main;
  17308. });
  17309. // Hack dataset for convenience.
  17310. if (componentType !== 'dataset' && indexOf(deps, 'dataset') <= 0) {
  17311. deps.unshift('dataset');
  17312. }
  17313. return deps;
  17314. }
  17315. mixin(ComponentModel, boxLayoutMixin);
  17316. /*
  17317. * Licensed to the Apache Software Foundation (ASF) under one
  17318. * or more contributor license agreements. See the NOTICE file
  17319. * distributed with this work for additional information
  17320. * regarding copyright ownership. The ASF licenses this file
  17321. * to you under the Apache License, Version 2.0 (the
  17322. * "License"); you may not use this file except in compliance
  17323. * with the License. You may obtain a copy of the License at
  17324. *
  17325. * http://www.apache.org/licenses/LICENSE-2.0
  17326. *
  17327. * Unless required by applicable law or agreed to in writing,
  17328. * software distributed under the License is distributed on an
  17329. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17330. * KIND, either express or implied. See the License for the
  17331. * specific language governing permissions and limitations
  17332. * under the License.
  17333. */
  17334. var platform = '';
  17335. // Navigator not exists in node
  17336. if (typeof navigator !== 'undefined') {
  17337. platform = navigator.platform || '';
  17338. }
  17339. var globalDefault = {
  17340. // backgroundColor: 'rgba(0,0,0,0)',
  17341. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  17342. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  17343. // Light colors:
  17344. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  17345. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  17346. // Dark colors:
  17347. color: [
  17348. '#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83',
  17349. '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'
  17350. ],
  17351. gradientColor: ['#f6efa6', '#d88273', '#bf444c'],
  17352. // If xAxis and yAxis declared, grid is created by default.
  17353. // grid: {},
  17354. textStyle: {
  17355. // color: '#000',
  17356. // decoration: 'none',
  17357. // PENDING
  17358. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  17359. // fontFamily: 'Arial, Verdana, sans-serif',
  17360. fontSize: 12,
  17361. fontStyle: 'normal',
  17362. fontWeight: 'normal'
  17363. },
  17364. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  17365. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  17366. // Default is source-over
  17367. blendMode: null,
  17368. animation: 'auto',
  17369. animationDuration: 1000,
  17370. animationDurationUpdate: 300,
  17371. animationEasing: 'exponentialOut',
  17372. animationEasingUpdate: 'cubicOut',
  17373. animationThreshold: 2000,
  17374. // Configuration for progressive/incremental rendering
  17375. progressiveThreshold: 3000,
  17376. progressive: 400,
  17377. // Threshold of if use single hover layer to optimize.
  17378. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  17379. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  17380. // which is unexpected.
  17381. // see example <echarts/test/heatmap-large.html>.
  17382. hoverLayerThreshold: 3000,
  17383. // See: module:echarts/scale/Time
  17384. useUTC: false
  17385. };
  17386. /*
  17387. * Licensed to the Apache Software Foundation (ASF) under one
  17388. * or more contributor license agreements. See the NOTICE file
  17389. * distributed with this work for additional information
  17390. * regarding copyright ownership. The ASF licenses this file
  17391. * to you under the Apache License, Version 2.0 (the
  17392. * "License"); you may not use this file except in compliance
  17393. * with the License. You may obtain a copy of the License at
  17394. *
  17395. * http://www.apache.org/licenses/LICENSE-2.0
  17396. *
  17397. * Unless required by applicable law or agreed to in writing,
  17398. * software distributed under the License is distributed on an
  17399. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17400. * KIND, either express or implied. See the License for the
  17401. * specific language governing permissions and limitations
  17402. * under the License.
  17403. */
  17404. var inner$2 = makeInner();
  17405. function getNearestColorPalette(colors, requestColorNum) {
  17406. var paletteNum = colors.length;
  17407. // TODO colors must be in order
  17408. for (var i = 0; i < paletteNum; i++) {
  17409. if (colors[i].length > requestColorNum) {
  17410. return colors[i];
  17411. }
  17412. }
  17413. return colors[paletteNum - 1];
  17414. }
  17415. var colorPaletteMixin = {
  17416. clearColorPalette: function () {
  17417. inner$2(this).colorIdx = 0;
  17418. inner$2(this).colorNameMap = {};
  17419. },
  17420. /**
  17421. * @param {string} name MUST NOT be null/undefined. Otherwise call this function
  17422. * twise with the same parameters will get different result.
  17423. * @param {Object} [scope=this]
  17424. * @param {Object} [requestColorNum]
  17425. * @return {string} color string.
  17426. */
  17427. getColorFromPalette: function (name, scope, requestColorNum) {
  17428. scope = scope || this;
  17429. var scopeFields = inner$2(scope);
  17430. var colorIdx = scopeFields.colorIdx || 0;
  17431. var colorNameMap = scopeFields.colorNameMap = scopeFields.colorNameMap || {};
  17432. // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  17433. if (colorNameMap.hasOwnProperty(name)) {
  17434. return colorNameMap[name];
  17435. }
  17436. var defaultColorPalette = normalizeToArray(this.get('color', true));
  17437. var layeredColorPalette = this.get('colorLayer', true);
  17438. var colorPalette = ((requestColorNum == null || !layeredColorPalette)
  17439. ? defaultColorPalette : getNearestColorPalette(layeredColorPalette, requestColorNum));
  17440. // In case can't find in layered color palette.
  17441. colorPalette = colorPalette || defaultColorPalette;
  17442. if (!colorPalette || !colorPalette.length) {
  17443. return;
  17444. }
  17445. var color = colorPalette[colorIdx];
  17446. if (name) {
  17447. colorNameMap[name] = color;
  17448. }
  17449. scopeFields.colorIdx = (colorIdx + 1) % colorPalette.length;
  17450. return color;
  17451. }
  17452. };
  17453. /*
  17454. * Licensed to the Apache Software Foundation (ASF) under one
  17455. * or more contributor license agreements. See the NOTICE file
  17456. * distributed with this work for additional information
  17457. * regarding copyright ownership. The ASF licenses this file
  17458. * to you under the Apache License, Version 2.0 (the
  17459. * "License"); you may not use this file except in compliance
  17460. * with the License. You may obtain a copy of the License at
  17461. *
  17462. * http://www.apache.org/licenses/LICENSE-2.0
  17463. *
  17464. * Unless required by applicable law or agreed to in writing,
  17465. * software distributed under the License is distributed on an
  17466. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17467. * KIND, either express or implied. See the License for the
  17468. * specific language governing permissions and limitations
  17469. * under the License.
  17470. */
  17471. /**
  17472. * Helper for model references.
  17473. * There are many manners to refer axis/coordSys.
  17474. */
  17475. // TODO
  17476. // merge relevant logic to this file?
  17477. // check: "modelHelper" of tooltip and "BrushTargetManager".
  17478. /**
  17479. * @return {Object} For example:
  17480. * {
  17481. * coordSysName: 'cartesian2d',
  17482. * coordSysDims: ['x', 'y', ...],
  17483. * axisMap: HashMap({
  17484. * x: xAxisModel,
  17485. * y: yAxisModel
  17486. * }),
  17487. * categoryAxisMap: HashMap({
  17488. * x: xAxisModel,
  17489. * y: undefined
  17490. * }),
  17491. * // It also indicate that whether there is category axis.
  17492. * firstCategoryDimIndex: 1,
  17493. * // To replace user specified encode.
  17494. * }
  17495. */
  17496. function getCoordSysDefineBySeries(seriesModel) {
  17497. var coordSysName = seriesModel.get('coordinateSystem');
  17498. var result = {
  17499. coordSysName: coordSysName,
  17500. coordSysDims: [],
  17501. axisMap: createHashMap(),
  17502. categoryAxisMap: createHashMap()
  17503. };
  17504. var fetch = fetchers[coordSysName];
  17505. if (fetch) {
  17506. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  17507. return result;
  17508. }
  17509. }
  17510. var fetchers = {
  17511. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  17512. var xAxisModel = seriesModel.getReferringComponents('xAxis')[0];
  17513. var yAxisModel = seriesModel.getReferringComponents('yAxis')[0];
  17514. if (__DEV__) {
  17515. if (!xAxisModel) {
  17516. throw new Error('xAxis "' + retrieve(
  17517. seriesModel.get('xAxisIndex'),
  17518. seriesModel.get('xAxisId'),
  17519. 0
  17520. ) + '" not found');
  17521. }
  17522. if (!yAxisModel) {
  17523. throw new Error('yAxis "' + retrieve(
  17524. seriesModel.get('xAxisIndex'),
  17525. seriesModel.get('yAxisId'),
  17526. 0
  17527. ) + '" not found');
  17528. }
  17529. }
  17530. result.coordSysDims = ['x', 'y'];
  17531. axisMap.set('x', xAxisModel);
  17532. axisMap.set('y', yAxisModel);
  17533. if (isCategory(xAxisModel)) {
  17534. categoryAxisMap.set('x', xAxisModel);
  17535. result.firstCategoryDimIndex = 0;
  17536. }
  17537. if (isCategory(yAxisModel)) {
  17538. categoryAxisMap.set('y', yAxisModel);
  17539. result.firstCategoryDimIndex = 1;
  17540. }
  17541. },
  17542. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  17543. var singleAxisModel = seriesModel.getReferringComponents('singleAxis')[0];
  17544. if (__DEV__) {
  17545. if (!singleAxisModel) {
  17546. throw new Error('singleAxis should be specified.');
  17547. }
  17548. }
  17549. result.coordSysDims = ['single'];
  17550. axisMap.set('single', singleAxisModel);
  17551. if (isCategory(singleAxisModel)) {
  17552. categoryAxisMap.set('single', singleAxisModel);
  17553. result.firstCategoryDimIndex = 0;
  17554. }
  17555. },
  17556. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  17557. var polarModel = seriesModel.getReferringComponents('polar')[0];
  17558. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  17559. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  17560. if (__DEV__) {
  17561. if (!angleAxisModel) {
  17562. throw new Error('angleAxis option not found');
  17563. }
  17564. if (!radiusAxisModel) {
  17565. throw new Error('radiusAxis option not found');
  17566. }
  17567. }
  17568. result.coordSysDims = ['radius', 'angle'];
  17569. axisMap.set('radius', radiusAxisModel);
  17570. axisMap.set('angle', angleAxisModel);
  17571. if (isCategory(radiusAxisModel)) {
  17572. categoryAxisMap.set('radius', radiusAxisModel);
  17573. result.firstCategoryDimIndex = 0;
  17574. }
  17575. if (isCategory(angleAxisModel)) {
  17576. categoryAxisMap.set('angle', angleAxisModel);
  17577. result.firstCategoryDimIndex = 1;
  17578. }
  17579. },
  17580. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  17581. result.coordSysDims = ['lng', 'lat'];
  17582. },
  17583. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  17584. var ecModel = seriesModel.ecModel;
  17585. var parallelModel = ecModel.getComponent(
  17586. 'parallel', seriesModel.get('parallelIndex')
  17587. );
  17588. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  17589. each$1(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  17590. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  17591. var axisDim = coordSysDims[index];
  17592. axisMap.set(axisDim, axisModel);
  17593. if (isCategory(axisModel) && result.firstCategoryDimIndex == null) {
  17594. categoryAxisMap.set(axisDim, axisModel);
  17595. result.firstCategoryDimIndex = index;
  17596. }
  17597. });
  17598. }
  17599. };
  17600. function isCategory(axisModel) {
  17601. return axisModel.get('type') === 'category';
  17602. }
  17603. /*
  17604. * Licensed to the Apache Software Foundation (ASF) under one
  17605. * or more contributor license agreements. See the NOTICE file
  17606. * distributed with this work for additional information
  17607. * regarding copyright ownership. The ASF licenses this file
  17608. * to you under the Apache License, Version 2.0 (the
  17609. * "License"); you may not use this file except in compliance
  17610. * with the License. You may obtain a copy of the License at
  17611. *
  17612. * http://www.apache.org/licenses/LICENSE-2.0
  17613. *
  17614. * Unless required by applicable law or agreed to in writing,
  17615. * software distributed under the License is distributed on an
  17616. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17617. * KIND, either express or implied. See the License for the
  17618. * specific language governing permissions and limitations
  17619. * under the License.
  17620. */
  17621. // Avoid typo.
  17622. var SOURCE_FORMAT_ORIGINAL = 'original';
  17623. var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
  17624. var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
  17625. var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
  17626. var SOURCE_FORMAT_UNKNOWN = 'unknown';
  17627. // ??? CHANGE A NAME
  17628. var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
  17629. var SERIES_LAYOUT_BY_COLUMN = 'column';
  17630. var SERIES_LAYOUT_BY_ROW = 'row';
  17631. /*
  17632. * Licensed to the Apache Software Foundation (ASF) under one
  17633. * or more contributor license agreements. See the NOTICE file
  17634. * distributed with this work for additional information
  17635. * regarding copyright ownership. The ASF licenses this file
  17636. * to you under the Apache License, Version 2.0 (the
  17637. * "License"); you may not use this file except in compliance
  17638. * with the License. You may obtain a copy of the License at
  17639. *
  17640. * http://www.apache.org/licenses/LICENSE-2.0
  17641. *
  17642. * Unless required by applicable law or agreed to in writing,
  17643. * software distributed under the License is distributed on an
  17644. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17645. * KIND, either express or implied. See the License for the
  17646. * specific language governing permissions and limitations
  17647. * under the License.
  17648. */
  17649. /**
  17650. * [sourceFormat]
  17651. *
  17652. * + "original":
  17653. * This format is only used in series.data, where
  17654. * itemStyle can be specified in data item.
  17655. *
  17656. * + "arrayRows":
  17657. * [
  17658. * ['product', 'score', 'amount'],
  17659. * ['Matcha Latte', 89.3, 95.8],
  17660. * ['Milk Tea', 92.1, 89.4],
  17661. * ['Cheese Cocoa', 94.4, 91.2],
  17662. * ['Walnut Brownie', 85.4, 76.9]
  17663. * ]
  17664. *
  17665. * + "objectRows":
  17666. * [
  17667. * {product: 'Matcha Latte', score: 89.3, amount: 95.8},
  17668. * {product: 'Milk Tea', score: 92.1, amount: 89.4},
  17669. * {product: 'Cheese Cocoa', score: 94.4, amount: 91.2},
  17670. * {product: 'Walnut Brownie', score: 85.4, amount: 76.9}
  17671. * ]
  17672. *
  17673. * + "keyedColumns":
  17674. * {
  17675. * 'product': ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],
  17676. * 'count': [823, 235, 1042, 988],
  17677. * 'score': [95.8, 81.4, 91.2, 76.9]
  17678. * }
  17679. *
  17680. * + "typedArray"
  17681. *
  17682. * + "unknown"
  17683. */
  17684. /**
  17685. * @constructor
  17686. * @param {Object} fields
  17687. * @param {string} fields.sourceFormat
  17688. * @param {Array|Object} fields.fromDataset
  17689. * @param {Array|Object} [fields.data]
  17690. * @param {string} [seriesLayoutBy='column']
  17691. * @param {Array.<Object|string>} [dimensionsDefine]
  17692. * @param {Objet|HashMap} [encodeDefine]
  17693. * @param {number} [startIndex=0]
  17694. * @param {number} [dimensionsDetectCount]
  17695. */
  17696. function Source(fields) {
  17697. /**
  17698. * @type {boolean}
  17699. */
  17700. this.fromDataset = fields.fromDataset;
  17701. /**
  17702. * Not null/undefined.
  17703. * @type {Array|Object}
  17704. */
  17705. this.data = fields.data || (
  17706. fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []
  17707. );
  17708. /**
  17709. * See also "detectSourceFormat".
  17710. * Not null/undefined.
  17711. * @type {string}
  17712. */
  17713. this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;
  17714. /**
  17715. * 'row' or 'column'
  17716. * Not null/undefined.
  17717. * @type {string} seriesLayoutBy
  17718. */
  17719. this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
  17720. /**
  17721. * dimensions definition in option.
  17722. * can be null/undefined.
  17723. * @type {Array.<Object|string>}
  17724. */
  17725. this.dimensionsDefine = fields.dimensionsDefine;
  17726. /**
  17727. * encode definition in option.
  17728. * can be null/undefined.
  17729. * @type {Objet|HashMap}
  17730. */
  17731. this.encodeDefine = fields.encodeDefine && createHashMap(fields.encodeDefine);
  17732. /**
  17733. * Not null/undefined, uint.
  17734. * @type {number}
  17735. */
  17736. this.startIndex = fields.startIndex || 0;
  17737. /**
  17738. * Can be null/undefined (when unknown), uint.
  17739. * @type {number}
  17740. */
  17741. this.dimensionsDetectCount = fields.dimensionsDetectCount;
  17742. }
  17743. /**
  17744. * Wrap original series data for some compatibility cases.
  17745. */
  17746. Source.seriesDataToSource = function (data) {
  17747. return new Source({
  17748. data: data,
  17749. sourceFormat: isTypedArray(data)
  17750. ? SOURCE_FORMAT_TYPED_ARRAY
  17751. : SOURCE_FORMAT_ORIGINAL,
  17752. fromDataset: false
  17753. });
  17754. };
  17755. enableClassCheck(Source);
  17756. /*
  17757. * Licensed to the Apache Software Foundation (ASF) under one
  17758. * or more contributor license agreements. See the NOTICE file
  17759. * distributed with this work for additional information
  17760. * regarding copyright ownership. The ASF licenses this file
  17761. * to you under the Apache License, Version 2.0 (the
  17762. * "License"); you may not use this file except in compliance
  17763. * with the License. You may obtain a copy of the License at
  17764. *
  17765. * http://www.apache.org/licenses/LICENSE-2.0
  17766. *
  17767. * Unless required by applicable law or agreed to in writing,
  17768. * software distributed under the License is distributed on an
  17769. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17770. * KIND, either express or implied. See the License for the
  17771. * specific language governing permissions and limitations
  17772. * under the License.
  17773. */
  17774. var inner$3 = makeInner();
  17775. /**
  17776. * @see {module:echarts/data/Source}
  17777. * @param {module:echarts/component/dataset/DatasetModel} datasetModel
  17778. * @return {string} sourceFormat
  17779. */
  17780. function detectSourceFormat(datasetModel) {
  17781. var data = datasetModel.option.source;
  17782. var sourceFormat = SOURCE_FORMAT_UNKNOWN;
  17783. if (isTypedArray(data)) {
  17784. sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
  17785. }
  17786. else if (isArray(data)) {
  17787. // FIXME Whether tolerate null in top level array?
  17788. if (data.length === 0) {
  17789. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  17790. }
  17791. for (var i = 0, len = data.length; i < len; i++) {
  17792. var item = data[i];
  17793. if (item == null) {
  17794. continue;
  17795. }
  17796. else if (isArray(item)) {
  17797. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  17798. break;
  17799. }
  17800. else if (isObject$1(item)) {
  17801. sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
  17802. break;
  17803. }
  17804. }
  17805. }
  17806. else if (isObject$1(data)) {
  17807. for (var key in data) {
  17808. if (data.hasOwnProperty(key) && isArrayLike(data[key])) {
  17809. sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
  17810. break;
  17811. }
  17812. }
  17813. }
  17814. else if (data != null) {
  17815. throw new Error('Invalid data');
  17816. }
  17817. inner$3(datasetModel).sourceFormat = sourceFormat;
  17818. }
  17819. /**
  17820. * [Scenarios]:
  17821. * (1) Provide source data directly:
  17822. * series: {
  17823. * encode: {...},
  17824. * dimensions: [...]
  17825. * seriesLayoutBy: 'row',
  17826. * data: [[...]]
  17827. * }
  17828. * (2) Refer to datasetModel.
  17829. * series: [{
  17830. * encode: {...}
  17831. * // Ignore datasetIndex means `datasetIndex: 0`
  17832. * // and the dimensions defination in dataset is used
  17833. * }, {
  17834. * encode: {...},
  17835. * seriesLayoutBy: 'column',
  17836. * datasetIndex: 1
  17837. * }]
  17838. *
  17839. * Get data from series itself or datset.
  17840. * @return {module:echarts/data/Source} source
  17841. */
  17842. function getSource(seriesModel) {
  17843. return inner$3(seriesModel).source;
  17844. }
  17845. /**
  17846. * MUST be called before mergeOption of all series.
  17847. * @param {module:echarts/model/Global} ecModel
  17848. */
  17849. function resetSourceDefaulter(ecModel) {
  17850. // `datasetMap` is used to make default encode.
  17851. inner$3(ecModel).datasetMap = createHashMap();
  17852. }
  17853. /**
  17854. * [Caution]:
  17855. * MUST be called after series option merged and
  17856. * before "series.getInitailData()" called.
  17857. *
  17858. * [The rule of making default encode]:
  17859. * Category axis (if exists) alway map to the first dimension.
  17860. * Each other axis occupies a subsequent dimension.
  17861. *
  17862. * [Why make default encode]:
  17863. * Simplify the typing of encode in option, avoiding the case like that:
  17864. * series: [{encode: {x: 0, y: 1}}, {encode: {x: 0, y: 2}}, {encode: {x: 0, y: 3}}],
  17865. * where the "y" have to be manually typed as "1, 2, 3, ...".
  17866. *
  17867. * @param {module:echarts/model/Series} seriesModel
  17868. */
  17869. function prepareSource(seriesModel) {
  17870. var seriesOption = seriesModel.option;
  17871. var data = seriesOption.data;
  17872. var sourceFormat = isTypedArray(data)
  17873. ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
  17874. var fromDataset = false;
  17875. var seriesLayoutBy = seriesOption.seriesLayoutBy;
  17876. var sourceHeader = seriesOption.sourceHeader;
  17877. var dimensionsDefine = seriesOption.dimensions;
  17878. var datasetModel = getDatasetModel(seriesModel);
  17879. if (datasetModel) {
  17880. var datasetOption = datasetModel.option;
  17881. data = datasetOption.source;
  17882. sourceFormat = inner$3(datasetModel).sourceFormat;
  17883. fromDataset = true;
  17884. // These settings from series has higher priority.
  17885. seriesLayoutBy = seriesLayoutBy || datasetOption.seriesLayoutBy;
  17886. sourceHeader == null && (sourceHeader = datasetOption.sourceHeader);
  17887. dimensionsDefine = dimensionsDefine || datasetOption.dimensions;
  17888. }
  17889. var completeResult = completeBySourceData(
  17890. data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine
  17891. );
  17892. // Note: dataset option does not have `encode`.
  17893. var encodeDefine = seriesOption.encode;
  17894. if (!encodeDefine && datasetModel) {
  17895. encodeDefine = makeDefaultEncode(
  17896. seriesModel, datasetModel, data, sourceFormat, seriesLayoutBy, completeResult
  17897. );
  17898. }
  17899. inner$3(seriesModel).source = new Source({
  17900. data: data,
  17901. fromDataset: fromDataset,
  17902. seriesLayoutBy: seriesLayoutBy,
  17903. sourceFormat: sourceFormat,
  17904. dimensionsDefine: completeResult.dimensionsDefine,
  17905. startIndex: completeResult.startIndex,
  17906. dimensionsDetectCount: completeResult.dimensionsDetectCount,
  17907. encodeDefine: encodeDefine
  17908. });
  17909. }
  17910. // return {startIndex, dimensionsDefine, dimensionsCount}
  17911. function completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine) {
  17912. if (!data) {
  17913. return {dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine)};
  17914. }
  17915. var dimensionsDetectCount;
  17916. var startIndex;
  17917. var findPotentialName;
  17918. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  17919. // Rule: Most of the first line are string: it is header.
  17920. // Caution: consider a line with 5 string and 1 number,
  17921. // it still can not be sure it is a head, because the
  17922. // 5 string may be 5 values of category columns.
  17923. if (sourceHeader === 'auto' || sourceHeader == null) {
  17924. arrayRowsTravelFirst(function (val) {
  17925. // '-' is regarded as null/undefined.
  17926. if (val != null && val !== '-') {
  17927. if (isString(val)) {
  17928. startIndex == null && (startIndex = 1);
  17929. }
  17930. else {
  17931. startIndex = 0;
  17932. }
  17933. }
  17934. // 10 is an experience number, avoid long loop.
  17935. }, seriesLayoutBy, data, 10);
  17936. }
  17937. else {
  17938. startIndex = sourceHeader ? 1 : 0;
  17939. }
  17940. if (!dimensionsDefine && startIndex === 1) {
  17941. dimensionsDefine = [];
  17942. arrayRowsTravelFirst(function (val, index) {
  17943. dimensionsDefine[index] = val != null ? val : '';
  17944. }, seriesLayoutBy, data);
  17945. }
  17946. dimensionsDetectCount = dimensionsDefine
  17947. ? dimensionsDefine.length
  17948. : seriesLayoutBy === SERIES_LAYOUT_BY_ROW
  17949. ? data.length
  17950. : data[0]
  17951. ? data[0].length
  17952. : null;
  17953. }
  17954. else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  17955. if (!dimensionsDefine) {
  17956. dimensionsDefine = objectRowsCollectDimensions(data);
  17957. findPotentialName = true;
  17958. }
  17959. }
  17960. else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  17961. if (!dimensionsDefine) {
  17962. dimensionsDefine = [];
  17963. findPotentialName = true;
  17964. each$1(data, function (colArr, key) {
  17965. dimensionsDefine.push(key);
  17966. });
  17967. }
  17968. }
  17969. else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  17970. var value0 = getDataItemValue(data[0]);
  17971. dimensionsDetectCount = isArray(value0) && value0.length || 1;
  17972. }
  17973. else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  17974. if (__DEV__) {
  17975. assert$1(!!dimensionsDefine, 'dimensions must be given if data is TypedArray.');
  17976. }
  17977. }
  17978. var potentialNameDimIndex;
  17979. if (findPotentialName) {
  17980. each$1(dimensionsDefine, function (dim, idx) {
  17981. if ((isObject$1(dim) ? dim.name : dim) === 'name') {
  17982. potentialNameDimIndex = idx;
  17983. }
  17984. });
  17985. }
  17986. return {
  17987. startIndex: startIndex,
  17988. dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine),
  17989. dimensionsDetectCount: dimensionsDetectCount,
  17990. potentialNameDimIndex: potentialNameDimIndex
  17991. // TODO: potentialIdDimIdx
  17992. };
  17993. }
  17994. // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
  17995. // which is reasonable. But dimension name is duplicated.
  17996. // Returns undefined or an array contains only object without null/undefiend or string.
  17997. function normalizeDimensionsDefine(dimensionsDefine) {
  17998. if (!dimensionsDefine) {
  17999. // The meaning of null/undefined is different from empty array.
  18000. return;
  18001. }
  18002. var nameMap = createHashMap();
  18003. return map(dimensionsDefine, function (item, index) {
  18004. item = extend({}, isObject$1(item) ? item : {name: item});
  18005. // User can set null in dimensions.
  18006. // We dont auto specify name, othewise a given name may
  18007. // cause it be refered unexpectedly.
  18008. if (item.name == null) {
  18009. return item;
  18010. }
  18011. // Also consider number form like 2012.
  18012. item.name += '';
  18013. // User may also specify displayName.
  18014. // displayName will always exists except user not
  18015. // specified or dim name is not specified or detected.
  18016. // (A auto generated dim name will not be used as
  18017. // displayName).
  18018. if (item.displayName == null) {
  18019. item.displayName = item.name;
  18020. }
  18021. var exist = nameMap.get(item.name);
  18022. if (!exist) {
  18023. nameMap.set(item.name, {count: 1});
  18024. }
  18025. else {
  18026. item.name += '-' + exist.count++;
  18027. }
  18028. return item;
  18029. });
  18030. }
  18031. function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
  18032. maxLoop == null && (maxLoop = Infinity);
  18033. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  18034. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18035. cb(data[i] ? data[i][0] : null, i);
  18036. }
  18037. }
  18038. else {
  18039. var value0 = data[0] || [];
  18040. for (var i = 0; i < value0.length && i < maxLoop; i++) {
  18041. cb(value0[i], i);
  18042. }
  18043. }
  18044. }
  18045. function objectRowsCollectDimensions(data) {
  18046. var firstIndex = 0;
  18047. var obj;
  18048. while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
  18049. if (obj) {
  18050. var dimensions = [];
  18051. each$1(obj, function (value, key) {
  18052. dimensions.push(key);
  18053. });
  18054. return dimensions;
  18055. }
  18056. }
  18057. // ??? TODO merge to completedimensions, where also has
  18058. // default encode making logic. And the default rule
  18059. // should depends on series? consider 'map'.
  18060. function makeDefaultEncode(
  18061. seriesModel, datasetModel, data, sourceFormat, seriesLayoutBy, completeResult
  18062. ) {
  18063. var coordSysDefine = getCoordSysDefineBySeries(seriesModel);
  18064. var encode = {};
  18065. // var encodeTooltip = [];
  18066. // var encodeLabel = [];
  18067. var encodeItemName = [];
  18068. var encodeSeriesName = [];
  18069. var seriesType = seriesModel.subType;
  18070. // ??? TODO refactor: provide by series itself.
  18071. // Consider the case: 'map' series is based on geo coordSys,
  18072. // 'graph', 'heatmap' can be based on cartesian. But can not
  18073. // give default rule simply here.
  18074. var nSeriesMap = createHashMap(['pie', 'map', 'funnel']);
  18075. var cSeriesMap = createHashMap([
  18076. 'line', 'bar', 'pictorialBar', 'scatter', 'effectScatter', 'candlestick', 'boxplot'
  18077. ]);
  18078. // Usually in this case series will use the first data
  18079. // dimension as the "value" dimension, or other default
  18080. // processes respectively.
  18081. if (coordSysDefine && cSeriesMap.get(seriesType) != null) {
  18082. var ecModel = seriesModel.ecModel;
  18083. var datasetMap = inner$3(ecModel).datasetMap;
  18084. var key = datasetModel.uid + '_' + seriesLayoutBy;
  18085. var datasetRecord = datasetMap.get(key)
  18086. || datasetMap.set(key, {categoryWayDim: 1, valueWayDim: 0});
  18087. // TODO
  18088. // Auto detect first time axis and do arrangement.
  18089. each$1(coordSysDefine.coordSysDims, function (coordDim) {
  18090. // In value way.
  18091. if (coordSysDefine.firstCategoryDimIndex == null) {
  18092. var dataDim = datasetRecord.valueWayDim++;
  18093. encode[coordDim] = dataDim;
  18094. // ??? TODO give a better default series name rule?
  18095. // especially when encode x y specified.
  18096. // consider: when mutiple series share one dimension
  18097. // category axis, series name should better use
  18098. // the other dimsion name. On the other hand, use
  18099. // both dimensions name.
  18100. encodeSeriesName.push(dataDim);
  18101. // encodeTooltip.push(dataDim);
  18102. // encodeLabel.push(dataDim);
  18103. }
  18104. // In category way, category axis.
  18105. else if (coordSysDefine.categoryAxisMap.get(coordDim)) {
  18106. encode[coordDim] = 0;
  18107. encodeItemName.push(0);
  18108. }
  18109. // In category way, non-category axis.
  18110. else {
  18111. var dataDim = datasetRecord.categoryWayDim++;
  18112. encode[coordDim] = dataDim;
  18113. // encodeTooltip.push(dataDim);
  18114. // encodeLabel.push(dataDim);
  18115. encodeSeriesName.push(dataDim);
  18116. }
  18117. });
  18118. }
  18119. // Do not make a complex rule! Hard to code maintain and not necessary.
  18120. // ??? TODO refactor: provide by series itself.
  18121. // [{name: ..., value: ...}, ...] like:
  18122. else if (nSeriesMap.get(seriesType) != null) {
  18123. // Find the first not ordinal. (5 is an experience value)
  18124. var firstNotOrdinal;
  18125. for (var i = 0; i < 5 && firstNotOrdinal == null; i++) {
  18126. if (!doGuessOrdinal(
  18127. data, sourceFormat, seriesLayoutBy,
  18128. completeResult.dimensionsDefine, completeResult.startIndex, i
  18129. )) {
  18130. firstNotOrdinal = i;
  18131. }
  18132. }
  18133. if (firstNotOrdinal != null) {
  18134. encode.value = firstNotOrdinal;
  18135. var nameDimIndex = completeResult.potentialNameDimIndex
  18136. || Math.max(firstNotOrdinal - 1, 0);
  18137. // By default, label use itemName in charts.
  18138. // So we dont set encodeLabel here.
  18139. encodeSeriesName.push(nameDimIndex);
  18140. encodeItemName.push(nameDimIndex);
  18141. // encodeTooltip.push(firstNotOrdinal);
  18142. }
  18143. }
  18144. // encodeTooltip.length && (encode.tooltip = encodeTooltip);
  18145. // encodeLabel.length && (encode.label = encodeLabel);
  18146. encodeItemName.length && (encode.itemName = encodeItemName);
  18147. encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
  18148. return encode;
  18149. }
  18150. /**
  18151. * If return null/undefined, indicate that should not use datasetModel.
  18152. */
  18153. function getDatasetModel(seriesModel) {
  18154. var option = seriesModel.option;
  18155. // Caution: consider the scenario:
  18156. // A dataset is declared and a series is not expected to use the dataset,
  18157. // and at the beginning `setOption({series: { noData })` (just prepare other
  18158. // option but no data), then `setOption({series: {data: [...]}); In this case,
  18159. // the user should set an empty array to avoid that dataset is used by default.
  18160. var thisData = option.data;
  18161. if (!thisData) {
  18162. return seriesModel.ecModel.getComponent('dataset', option.datasetIndex || 0);
  18163. }
  18164. }
  18165. /**
  18166. * The rule should not be complex, otherwise user might not
  18167. * be able to known where the data is wrong.
  18168. * The code is ugly, but how to make it neat?
  18169. *
  18170. * @param {module:echars/data/Source} source
  18171. * @param {number} dimIndex
  18172. * @return {boolean} Whether ordinal.
  18173. */
  18174. function guessOrdinal(source, dimIndex) {
  18175. return doGuessOrdinal(
  18176. source.data,
  18177. source.sourceFormat,
  18178. source.seriesLayoutBy,
  18179. source.dimensionsDefine,
  18180. source.startIndex,
  18181. dimIndex
  18182. );
  18183. }
  18184. // dimIndex may be overflow source data.
  18185. function doGuessOrdinal(
  18186. data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex
  18187. ) {
  18188. var result;
  18189. // Experience value.
  18190. var maxLoop = 5;
  18191. if (isTypedArray(data)) {
  18192. return false;
  18193. }
  18194. // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
  18195. // always exists in source.
  18196. var dimName;
  18197. if (dimensionsDefine) {
  18198. dimName = dimensionsDefine[dimIndex];
  18199. dimName = isObject$1(dimName) ? dimName.name : dimName;
  18200. }
  18201. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  18202. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  18203. var sample = data[dimIndex];
  18204. for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
  18205. if ((result = detectValue(sample[startIndex + i])) != null) {
  18206. return result;
  18207. }
  18208. }
  18209. }
  18210. else {
  18211. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18212. var row = data[startIndex + i];
  18213. if (row && (result = detectValue(row[dimIndex])) != null) {
  18214. return result;
  18215. }
  18216. }
  18217. }
  18218. }
  18219. else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  18220. if (!dimName) {
  18221. return;
  18222. }
  18223. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18224. var item = data[i];
  18225. if (item && (result = detectValue(item[dimName])) != null) {
  18226. return result;
  18227. }
  18228. }
  18229. }
  18230. else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18231. if (!dimName) {
  18232. return;
  18233. }
  18234. var sample = data[dimName];
  18235. if (!sample || isTypedArray(sample)) {
  18236. return false;
  18237. }
  18238. for (var i = 0; i < sample.length && i < maxLoop; i++) {
  18239. if ((result = detectValue(sample[i])) != null) {
  18240. return result;
  18241. }
  18242. }
  18243. }
  18244. else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  18245. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18246. var item = data[i];
  18247. var val = getDataItemValue(item);
  18248. if (!isArray(val)) {
  18249. return false;
  18250. }
  18251. if ((result = detectValue(val[dimIndex])) != null) {
  18252. return result;
  18253. }
  18254. }
  18255. }
  18256. function detectValue(val) {
  18257. // Consider usage convenience, '1', '2' will be treated as "number".
  18258. // `isFinit('')` get `true`.
  18259. if (val != null && isFinite(val) && val !== '') {
  18260. return false;
  18261. }
  18262. else if (isString(val) && val !== '-') {
  18263. return true;
  18264. }
  18265. }
  18266. return false;
  18267. }
  18268. /*
  18269. * Licensed to the Apache Software Foundation (ASF) under one
  18270. * or more contributor license agreements. See the NOTICE file
  18271. * distributed with this work for additional information
  18272. * regarding copyright ownership. The ASF licenses this file
  18273. * to you under the Apache License, Version 2.0 (the
  18274. * "License"); you may not use this file except in compliance
  18275. * with the License. You may obtain a copy of the License at
  18276. *
  18277. * http://www.apache.org/licenses/LICENSE-2.0
  18278. *
  18279. * Unless required by applicable law or agreed to in writing,
  18280. * software distributed under the License is distributed on an
  18281. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18282. * KIND, either express or implied. See the License for the
  18283. * specific language governing permissions and limitations
  18284. * under the License.
  18285. */
  18286. /**
  18287. * ECharts global model
  18288. *
  18289. * @module {echarts/model/Global}
  18290. */
  18291. /**
  18292. * Caution: If the mechanism should be changed some day, these cases
  18293. * should be considered:
  18294. *
  18295. * (1) In `merge option` mode, if using the same option to call `setOption`
  18296. * many times, the result should be the same (try our best to ensure that).
  18297. * (2) In `merge option` mode, if a component has no id/name specified, it
  18298. * will be merged by index, and the result sequence of the components is
  18299. * consistent to the original sequence.
  18300. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  18301. * `mergeOption` in module:echarts/model/OptionManager.
  18302. */
  18303. var OPTION_INNER_KEY = '\0_ec_inner';
  18304. /**
  18305. * @alias module:echarts/model/Global
  18306. *
  18307. * @param {Object} option
  18308. * @param {module:echarts/model/Model} parentModel
  18309. * @param {Object} theme
  18310. */
  18311. var GlobalModel = Model.extend({
  18312. init: function (option, parentModel, theme, optionManager) {
  18313. theme = theme || {};
  18314. this.option = null; // Mark as not initialized.
  18315. /**
  18316. * @type {module:echarts/model/Model}
  18317. * @private
  18318. */
  18319. this._theme = new Model(theme);
  18320. /**
  18321. * @type {module:echarts/model/OptionManager}
  18322. */
  18323. this._optionManager = optionManager;
  18324. },
  18325. setOption: function (option, optionPreprocessorFuncs) {
  18326. assert$1(
  18327. !(OPTION_INNER_KEY in option),
  18328. 'please use chart.getOption()'
  18329. );
  18330. this._optionManager.setOption(option, optionPreprocessorFuncs);
  18331. this.resetOption(null);
  18332. },
  18333. /**
  18334. * @param {string} type null/undefined: reset all.
  18335. * 'recreate': force recreate all.
  18336. * 'timeline': only reset timeline option
  18337. * 'media': only reset media query option
  18338. * @return {boolean} Whether option changed.
  18339. */
  18340. resetOption: function (type) {
  18341. var optionChanged = false;
  18342. var optionManager = this._optionManager;
  18343. if (!type || type === 'recreate') {
  18344. var baseOption = optionManager.mountOption(type === 'recreate');
  18345. if (!this.option || type === 'recreate') {
  18346. initBase.call(this, baseOption);
  18347. }
  18348. else {
  18349. this.restoreData();
  18350. this.mergeOption(baseOption);
  18351. }
  18352. optionChanged = true;
  18353. }
  18354. if (type === 'timeline' || type === 'media') {
  18355. this.restoreData();
  18356. }
  18357. if (!type || type === 'recreate' || type === 'timeline') {
  18358. var timelineOption = optionManager.getTimelineOption(this);
  18359. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  18360. }
  18361. if (!type || type === 'recreate' || type === 'media') {
  18362. var mediaOptions = optionManager.getMediaOption(this, this._api);
  18363. if (mediaOptions.length) {
  18364. each$1(mediaOptions, function (mediaOption) {
  18365. this.mergeOption(mediaOption, optionChanged = true);
  18366. }, this);
  18367. }
  18368. }
  18369. return optionChanged;
  18370. },
  18371. /**
  18372. * @protected
  18373. */
  18374. mergeOption: function (newOption) {
  18375. var option = this.option;
  18376. var componentsMap = this._componentsMap;
  18377. var newCptTypes = [];
  18378. resetSourceDefaulter(this);
  18379. // If no component class, merge directly.
  18380. // For example: color, animaiton options, etc.
  18381. each$1(newOption, function (componentOption, mainType) {
  18382. if (componentOption == null) {
  18383. return;
  18384. }
  18385. if (!ComponentModel.hasClass(mainType)) {
  18386. // globalSettingTask.dirty();
  18387. option[mainType] = option[mainType] == null
  18388. ? clone(componentOption)
  18389. : merge(option[mainType], componentOption, true);
  18390. }
  18391. else if (mainType) {
  18392. newCptTypes.push(mainType);
  18393. }
  18394. });
  18395. ComponentModel.topologicalTravel(
  18396. newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this
  18397. );
  18398. function visitComponent(mainType, dependencies) {
  18399. var newCptOptionList = normalizeToArray(newOption[mainType]);
  18400. var mapResult = mappingToExists(
  18401. componentsMap.get(mainType), newCptOptionList
  18402. );
  18403. makeIdAndName(mapResult);
  18404. // Set mainType and complete subType.
  18405. each$1(mapResult, function (item, index) {
  18406. var opt = item.option;
  18407. if (isObject$1(opt)) {
  18408. item.keyInfo.mainType = mainType;
  18409. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  18410. }
  18411. });
  18412. var dependentModels = getComponentsByTypes(
  18413. componentsMap, dependencies
  18414. );
  18415. option[mainType] = [];
  18416. componentsMap.set(mainType, []);
  18417. each$1(mapResult, function (resultItem, index) {
  18418. var componentModel = resultItem.exist;
  18419. var newCptOption = resultItem.option;
  18420. assert$1(
  18421. isObject$1(newCptOption) || componentModel,
  18422. 'Empty component definition'
  18423. );
  18424. // Consider where is no new option and should be merged using {},
  18425. // see removeEdgeAndAdd in topologicalTravel and
  18426. // ComponentModel.getAllClassMainTypes.
  18427. if (!newCptOption) {
  18428. componentModel.mergeOption({}, this);
  18429. componentModel.optionUpdated({}, false);
  18430. }
  18431. else {
  18432. var ComponentModelClass = ComponentModel.getClass(
  18433. mainType, resultItem.keyInfo.subType, true
  18434. );
  18435. if (componentModel && componentModel instanceof ComponentModelClass) {
  18436. componentModel.name = resultItem.keyInfo.name;
  18437. // componentModel.settingTask && componentModel.settingTask.dirty();
  18438. componentModel.mergeOption(newCptOption, this);
  18439. componentModel.optionUpdated(newCptOption, false);
  18440. }
  18441. else {
  18442. // PENDING Global as parent ?
  18443. var extraOpt = extend(
  18444. {
  18445. dependentModels: dependentModels,
  18446. componentIndex: index
  18447. },
  18448. resultItem.keyInfo
  18449. );
  18450. componentModel = new ComponentModelClass(
  18451. newCptOption, this, this, extraOpt
  18452. );
  18453. extend(componentModel, extraOpt);
  18454. componentModel.init(newCptOption, this, this, extraOpt);
  18455. // Call optionUpdated after init.
  18456. // newCptOption has been used as componentModel.option
  18457. // and may be merged with theme and default, so pass null
  18458. // to avoid confusion.
  18459. componentModel.optionUpdated(null, true);
  18460. }
  18461. }
  18462. componentsMap.get(mainType)[index] = componentModel;
  18463. option[mainType][index] = componentModel.option;
  18464. }, this);
  18465. // Backup series for filtering.
  18466. if (mainType === 'series') {
  18467. createSeriesIndices(this, componentsMap.get('series'));
  18468. }
  18469. }
  18470. this._seriesIndicesMap = createHashMap(
  18471. this._seriesIndices = this._seriesIndices || []
  18472. );
  18473. },
  18474. /**
  18475. * Get option for output (cloned option and inner info removed)
  18476. * @public
  18477. * @return {Object}
  18478. */
  18479. getOption: function () {
  18480. var option = clone(this.option);
  18481. each$1(option, function (opts, mainType) {
  18482. if (ComponentModel.hasClass(mainType)) {
  18483. var opts = normalizeToArray(opts);
  18484. for (var i = opts.length - 1; i >= 0; i--) {
  18485. // Remove options with inner id.
  18486. if (isIdInner(opts[i])) {
  18487. opts.splice(i, 1);
  18488. }
  18489. }
  18490. option[mainType] = opts;
  18491. }
  18492. });
  18493. delete option[OPTION_INNER_KEY];
  18494. return option;
  18495. },
  18496. /**
  18497. * @return {module:echarts/model/Model}
  18498. */
  18499. getTheme: function () {
  18500. return this._theme;
  18501. },
  18502. /**
  18503. * @param {string} mainType
  18504. * @param {number} [idx=0]
  18505. * @return {module:echarts/model/Component}
  18506. */
  18507. getComponent: function (mainType, idx) {
  18508. var list = this._componentsMap.get(mainType);
  18509. if (list) {
  18510. return list[idx || 0];
  18511. }
  18512. },
  18513. /**
  18514. * If none of index and id and name used, return all components with mainType.
  18515. * @param {Object} condition
  18516. * @param {string} condition.mainType
  18517. * @param {string} [condition.subType] If ignore, only query by mainType
  18518. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  18519. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  18520. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  18521. * @return {Array.<module:echarts/model/Component>}
  18522. */
  18523. queryComponents: function (condition) {
  18524. var mainType = condition.mainType;
  18525. if (!mainType) {
  18526. return [];
  18527. }
  18528. var index = condition.index;
  18529. var id = condition.id;
  18530. var name = condition.name;
  18531. var cpts = this._componentsMap.get(mainType);
  18532. if (!cpts || !cpts.length) {
  18533. return [];
  18534. }
  18535. var result;
  18536. if (index != null) {
  18537. if (!isArray(index)) {
  18538. index = [index];
  18539. }
  18540. result = filter(map(index, function (idx) {
  18541. return cpts[idx];
  18542. }), function (val) {
  18543. return !!val;
  18544. });
  18545. }
  18546. else if (id != null) {
  18547. var isIdArray = isArray(id);
  18548. result = filter(cpts, function (cpt) {
  18549. return (isIdArray && indexOf(id, cpt.id) >= 0)
  18550. || (!isIdArray && cpt.id === id);
  18551. });
  18552. }
  18553. else if (name != null) {
  18554. var isNameArray = isArray(name);
  18555. result = filter(cpts, function (cpt) {
  18556. return (isNameArray && indexOf(name, cpt.name) >= 0)
  18557. || (!isNameArray && cpt.name === name);
  18558. });
  18559. }
  18560. else {
  18561. // Return all components with mainType
  18562. result = cpts.slice();
  18563. }
  18564. return filterBySubType(result, condition);
  18565. },
  18566. /**
  18567. * The interface is different from queryComponents,
  18568. * which is convenient for inner usage.
  18569. *
  18570. * @usage
  18571. * var result = findComponents(
  18572. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  18573. * );
  18574. * var result = findComponents(
  18575. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  18576. * );
  18577. * var result = findComponents(
  18578. * {mainType: 'series'},
  18579. * function (model, index) {...}
  18580. * );
  18581. * // result like [component0, componnet1, ...]
  18582. *
  18583. * @param {Object} condition
  18584. * @param {string} condition.mainType Mandatory.
  18585. * @param {string} [condition.subType] Optional.
  18586. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  18587. * where xxx is mainType.
  18588. * If query attribute is null/undefined or has no index/id/name,
  18589. * do not filtering by query conditions, which is convenient for
  18590. * no-payload situations or when target of action is global.
  18591. * @param {Function} [condition.filter] parameter: component, return boolean.
  18592. * @return {Array.<module:echarts/model/Component>}
  18593. */
  18594. findComponents: function (condition) {
  18595. var query = condition.query;
  18596. var mainType = condition.mainType;
  18597. var queryCond = getQueryCond(query);
  18598. var result = queryCond
  18599. ? this.queryComponents(queryCond)
  18600. : this._componentsMap.get(mainType);
  18601. return doFilter(filterBySubType(result, condition));
  18602. function getQueryCond(q) {
  18603. var indexAttr = mainType + 'Index';
  18604. var idAttr = mainType + 'Id';
  18605. var nameAttr = mainType + 'Name';
  18606. return q && (
  18607. q[indexAttr] != null
  18608. || q[idAttr] != null
  18609. || q[nameAttr] != null
  18610. )
  18611. ? {
  18612. mainType: mainType,
  18613. // subType will be filtered finally.
  18614. index: q[indexAttr],
  18615. id: q[idAttr],
  18616. name: q[nameAttr]
  18617. }
  18618. : null;
  18619. }
  18620. function doFilter(res) {
  18621. return condition.filter
  18622. ? filter(res, condition.filter)
  18623. : res;
  18624. }
  18625. },
  18626. /**
  18627. * @usage
  18628. * eachComponent('legend', function (legendModel, index) {
  18629. * ...
  18630. * });
  18631. * eachComponent(function (componentType, model, index) {
  18632. * // componentType does not include subType
  18633. * // (componentType is 'xxx' but not 'xxx.aa')
  18634. * });
  18635. * eachComponent(
  18636. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  18637. * function (model, index) {...}
  18638. * );
  18639. * eachComponent(
  18640. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  18641. * function (model, index) {...}
  18642. * );
  18643. *
  18644. * @param {string|Object=} mainType When mainType is object, the definition
  18645. * is the same as the method 'findComponents'.
  18646. * @param {Function} cb
  18647. * @param {*} context
  18648. */
  18649. eachComponent: function (mainType, cb, context) {
  18650. var componentsMap = this._componentsMap;
  18651. if (typeof mainType === 'function') {
  18652. context = cb;
  18653. cb = mainType;
  18654. componentsMap.each(function (components, componentType) {
  18655. each$1(components, function (component, index) {
  18656. cb.call(context, componentType, component, index);
  18657. });
  18658. });
  18659. }
  18660. else if (isString(mainType)) {
  18661. each$1(componentsMap.get(mainType), cb, context);
  18662. }
  18663. else if (isObject$1(mainType)) {
  18664. var queryResult = this.findComponents(mainType);
  18665. each$1(queryResult, cb, context);
  18666. }
  18667. },
  18668. /**
  18669. * @param {string} name
  18670. * @return {Array.<module:echarts/model/Series>}
  18671. */
  18672. getSeriesByName: function (name) {
  18673. var series = this._componentsMap.get('series');
  18674. return filter(series, function (oneSeries) {
  18675. return oneSeries.name === name;
  18676. });
  18677. },
  18678. /**
  18679. * @param {number} seriesIndex
  18680. * @return {module:echarts/model/Series}
  18681. */
  18682. getSeriesByIndex: function (seriesIndex) {
  18683. return this._componentsMap.get('series')[seriesIndex];
  18684. },
  18685. /**
  18686. * Get series list before filtered by type.
  18687. * FIXME: rename to getRawSeriesByType?
  18688. *
  18689. * @param {string} subType
  18690. * @return {Array.<module:echarts/model/Series>}
  18691. */
  18692. getSeriesByType: function (subType) {
  18693. var series = this._componentsMap.get('series');
  18694. return filter(series, function (oneSeries) {
  18695. return oneSeries.subType === subType;
  18696. });
  18697. },
  18698. /**
  18699. * @return {Array.<module:echarts/model/Series>}
  18700. */
  18701. getSeries: function () {
  18702. return this._componentsMap.get('series').slice();
  18703. },
  18704. /**
  18705. * @return {number}
  18706. */
  18707. getSeriesCount: function () {
  18708. return this._componentsMap.get('series').length;
  18709. },
  18710. /**
  18711. * After filtering, series may be different
  18712. * frome raw series.
  18713. *
  18714. * @param {Function} cb
  18715. * @param {*} context
  18716. */
  18717. eachSeries: function (cb, context) {
  18718. assertSeriesInitialized(this);
  18719. each$1(this._seriesIndices, function (rawSeriesIndex) {
  18720. var series = this._componentsMap.get('series')[rawSeriesIndex];
  18721. cb.call(context, series, rawSeriesIndex);
  18722. }, this);
  18723. },
  18724. /**
  18725. * Iterate raw series before filtered.
  18726. *
  18727. * @param {Function} cb
  18728. * @param {*} context
  18729. */
  18730. eachRawSeries: function (cb, context) {
  18731. each$1(this._componentsMap.get('series'), cb, context);
  18732. },
  18733. /**
  18734. * After filtering, series may be different.
  18735. * frome raw series.
  18736. *
  18737. * @parma {string} subType
  18738. * @param {Function} cb
  18739. * @param {*} context
  18740. */
  18741. eachSeriesByType: function (subType, cb, context) {
  18742. assertSeriesInitialized(this);
  18743. each$1(this._seriesIndices, function (rawSeriesIndex) {
  18744. var series = this._componentsMap.get('series')[rawSeriesIndex];
  18745. if (series.subType === subType) {
  18746. cb.call(context, series, rawSeriesIndex);
  18747. }
  18748. }, this);
  18749. },
  18750. /**
  18751. * Iterate raw series before filtered of given type.
  18752. *
  18753. * @parma {string} subType
  18754. * @param {Function} cb
  18755. * @param {*} context
  18756. */
  18757. eachRawSeriesByType: function (subType, cb, context) {
  18758. return each$1(this.getSeriesByType(subType), cb, context);
  18759. },
  18760. /**
  18761. * @param {module:echarts/model/Series} seriesModel
  18762. */
  18763. isSeriesFiltered: function (seriesModel) {
  18764. assertSeriesInitialized(this);
  18765. return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;
  18766. },
  18767. /**
  18768. * @return {Array.<number>}
  18769. */
  18770. getCurrentSeriesIndices: function () {
  18771. return (this._seriesIndices || []).slice();
  18772. },
  18773. /**
  18774. * @param {Function} cb
  18775. * @param {*} context
  18776. */
  18777. filterSeries: function (cb, context) {
  18778. assertSeriesInitialized(this);
  18779. var filteredSeries = filter(
  18780. this._componentsMap.get('series'), cb, context
  18781. );
  18782. createSeriesIndices(this, filteredSeries);
  18783. },
  18784. restoreData: function (payload) {
  18785. var componentsMap = this._componentsMap;
  18786. createSeriesIndices(this, componentsMap.get('series'));
  18787. var componentTypes = [];
  18788. componentsMap.each(function (components, componentType) {
  18789. componentTypes.push(componentType);
  18790. });
  18791. ComponentModel.topologicalTravel(
  18792. componentTypes,
  18793. ComponentModel.getAllClassMainTypes(),
  18794. function (componentType, dependencies) {
  18795. each$1(componentsMap.get(componentType), function (component) {
  18796. (componentType !== 'series' || !isNotTargetSeries(component, payload))
  18797. && component.restoreData();
  18798. });
  18799. }
  18800. );
  18801. }
  18802. });
  18803. function isNotTargetSeries(seriesModel, payload) {
  18804. if (payload) {
  18805. var index = payload.seiresIndex;
  18806. var id = payload.seriesId;
  18807. var name = payload.seriesName;
  18808. return (index != null && seriesModel.componentIndex !== index)
  18809. || (id != null && seriesModel.id !== id)
  18810. || (name != null && seriesModel.name !== name);
  18811. }
  18812. }
  18813. /**
  18814. * @inner
  18815. */
  18816. function mergeTheme(option, theme) {
  18817. // PENDING
  18818. // NOT use `colorLayer` in theme if option has `color`
  18819. var notMergeColorLayer = option.color && !option.colorLayer;
  18820. each$1(theme, function (themeItem, name) {
  18821. if (name === 'colorLayer' && notMergeColorLayer) {
  18822. return;
  18823. }
  18824. // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  18825. if (!ComponentModel.hasClass(name)) {
  18826. if (typeof themeItem === 'object') {
  18827. option[name] = !option[name]
  18828. ? clone(themeItem)
  18829. : merge(option[name], themeItem, false);
  18830. }
  18831. else {
  18832. if (option[name] == null) {
  18833. option[name] = themeItem;
  18834. }
  18835. }
  18836. }
  18837. });
  18838. }
  18839. function initBase(baseOption) {
  18840. baseOption = baseOption;
  18841. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  18842. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  18843. this.option = {};
  18844. this.option[OPTION_INNER_KEY] = 1;
  18845. /**
  18846. * Init with series: [], in case of calling findSeries method
  18847. * before series initialized.
  18848. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  18849. * @private
  18850. */
  18851. this._componentsMap = createHashMap({series: []});
  18852. /**
  18853. * Mapping between filtered series list and raw series list.
  18854. * key: filtered series indices, value: raw series indices.
  18855. * @type {Array.<nubmer>}
  18856. * @private
  18857. */
  18858. this._seriesIndices;
  18859. this._seriesIndicesMap;
  18860. mergeTheme(baseOption, this._theme.option);
  18861. // TODO Needs clone when merging to the unexisted property
  18862. merge(baseOption, globalDefault, false);
  18863. this.mergeOption(baseOption);
  18864. }
  18865. /**
  18866. * @inner
  18867. * @param {Array.<string>|string} types model types
  18868. * @return {Object} key: {string} type, value: {Array.<Object>} models
  18869. */
  18870. function getComponentsByTypes(componentsMap, types) {
  18871. if (!isArray(types)) {
  18872. types = types ? [types] : [];
  18873. }
  18874. var ret = {};
  18875. each$1(types, function (type) {
  18876. ret[type] = (componentsMap.get(type) || []).slice();
  18877. });
  18878. return ret;
  18879. }
  18880. /**
  18881. * @inner
  18882. */
  18883. function determineSubType(mainType, newCptOption, existComponent) {
  18884. var subType = newCptOption.type
  18885. ? newCptOption.type
  18886. : existComponent
  18887. ? existComponent.subType
  18888. // Use determineSubType only when there is no existComponent.
  18889. : ComponentModel.determineSubType(mainType, newCptOption);
  18890. // tooltip, markline, markpoint may always has no subType
  18891. return subType;
  18892. }
  18893. /**
  18894. * @inner
  18895. */
  18896. function createSeriesIndices(ecModel, seriesModels) {
  18897. ecModel._seriesIndicesMap = createHashMap(
  18898. ecModel._seriesIndices = map(seriesModels, function (series) {
  18899. return series.componentIndex;
  18900. }) || []
  18901. );
  18902. }
  18903. /**
  18904. * @inner
  18905. */
  18906. function filterBySubType(components, condition) {
  18907. // Using hasOwnProperty for restrict. Consider
  18908. // subType is undefined in user payload.
  18909. return condition.hasOwnProperty('subType')
  18910. ? filter(components, function (cpt) {
  18911. return cpt.subType === condition.subType;
  18912. })
  18913. : components;
  18914. }
  18915. /**
  18916. * @inner
  18917. */
  18918. function assertSeriesInitialized(ecModel) {
  18919. // Components that use _seriesIndices should depends on series component,
  18920. // which make sure that their initialization is after series.
  18921. if (__DEV__) {
  18922. if (!ecModel._seriesIndices) {
  18923. throw new Error('Option should contains series.');
  18924. }
  18925. }
  18926. }
  18927. mixin(GlobalModel, colorPaletteMixin);
  18928. /*
  18929. * Licensed to the Apache Software Foundation (ASF) under one
  18930. * or more contributor license agreements. See the NOTICE file
  18931. * distributed with this work for additional information
  18932. * regarding copyright ownership. The ASF licenses this file
  18933. * to you under the Apache License, Version 2.0 (the
  18934. * "License"); you may not use this file except in compliance
  18935. * with the License. You may obtain a copy of the License at
  18936. *
  18937. * http://www.apache.org/licenses/LICENSE-2.0
  18938. *
  18939. * Unless required by applicable law or agreed to in writing,
  18940. * software distributed under the License is distributed on an
  18941. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18942. * KIND, either express or implied. See the License for the
  18943. * specific language governing permissions and limitations
  18944. * under the License.
  18945. */
  18946. var echartsAPIList = [
  18947. 'getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isDisposed',
  18948. 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption',
  18949. 'getViewOfComponentModel', 'getViewOfSeriesModel'
  18950. ];
  18951. // And `getCoordinateSystems` and `getComponentByElement` will be injected in echarts.js
  18952. function ExtensionAPI(chartInstance) {
  18953. each$1(echartsAPIList, function (name) {
  18954. this[name] = bind(chartInstance[name], chartInstance);
  18955. }, this);
  18956. }
  18957. /*
  18958. * Licensed to the Apache Software Foundation (ASF) under one
  18959. * or more contributor license agreements. See the NOTICE file
  18960. * distributed with this work for additional information
  18961. * regarding copyright ownership. The ASF licenses this file
  18962. * to you under the Apache License, Version 2.0 (the
  18963. * "License"); you may not use this file except in compliance
  18964. * with the License. You may obtain a copy of the License at
  18965. *
  18966. * http://www.apache.org/licenses/LICENSE-2.0
  18967. *
  18968. * Unless required by applicable law or agreed to in writing,
  18969. * software distributed under the License is distributed on an
  18970. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18971. * KIND, either express or implied. See the License for the
  18972. * specific language governing permissions and limitations
  18973. * under the License.
  18974. */
  18975. var coordinateSystemCreators = {};
  18976. function CoordinateSystemManager() {
  18977. this._coordinateSystems = [];
  18978. }
  18979. CoordinateSystemManager.prototype = {
  18980. constructor: CoordinateSystemManager,
  18981. create: function (ecModel, api) {
  18982. var coordinateSystems = [];
  18983. each$1(coordinateSystemCreators, function (creater, type) {
  18984. var list = creater.create(ecModel, api);
  18985. coordinateSystems = coordinateSystems.concat(list || []);
  18986. });
  18987. this._coordinateSystems = coordinateSystems;
  18988. },
  18989. update: function (ecModel, api) {
  18990. each$1(this._coordinateSystems, function (coordSys) {
  18991. coordSys.update && coordSys.update(ecModel, api);
  18992. });
  18993. },
  18994. getCoordinateSystems: function () {
  18995. return this._coordinateSystems.slice();
  18996. }
  18997. };
  18998. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  18999. coordinateSystemCreators[type] = coordinateSystemCreator;
  19000. };
  19001. CoordinateSystemManager.get = function (type) {
  19002. return coordinateSystemCreators[type];
  19003. };
  19004. /*
  19005. * Licensed to the Apache Software Foundation (ASF) under one
  19006. * or more contributor license agreements. See the NOTICE file
  19007. * distributed with this work for additional information
  19008. * regarding copyright ownership. The ASF licenses this file
  19009. * to you under the Apache License, Version 2.0 (the
  19010. * "License"); you may not use this file except in compliance
  19011. * with the License. You may obtain a copy of the License at
  19012. *
  19013. * http://www.apache.org/licenses/LICENSE-2.0
  19014. *
  19015. * Unless required by applicable law or agreed to in writing,
  19016. * software distributed under the License is distributed on an
  19017. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19018. * KIND, either express or implied. See the License for the
  19019. * specific language governing permissions and limitations
  19020. * under the License.
  19021. */
  19022. /**
  19023. * ECharts option manager
  19024. *
  19025. * @module {echarts/model/OptionManager}
  19026. */
  19027. var each$4 = each$1;
  19028. var clone$3 = clone;
  19029. var map$1 = map;
  19030. var merge$1 = merge;
  19031. var QUERY_REG = /^(min|max)?(.+)$/;
  19032. /**
  19033. * TERM EXPLANATIONS:
  19034. *
  19035. * [option]:
  19036. *
  19037. * An object that contains definitions of components. For example:
  19038. * var option = {
  19039. * title: {...},
  19040. * legend: {...},
  19041. * visualMap: {...},
  19042. * series: [
  19043. * {data: [...]},
  19044. * {data: [...]},
  19045. * ...
  19046. * ]
  19047. * };
  19048. *
  19049. * [rawOption]:
  19050. *
  19051. * An object input to echarts.setOption. 'rawOption' may be an
  19052. * 'option', or may be an object contains multi-options. For example:
  19053. * var option = {
  19054. * baseOption: {
  19055. * title: {...},
  19056. * legend: {...},
  19057. * series: [
  19058. * {data: [...]},
  19059. * {data: [...]},
  19060. * ...
  19061. * ]
  19062. * },
  19063. * timeline: {...},
  19064. * options: [
  19065. * {title: {...}, series: {data: [...]}},
  19066. * {title: {...}, series: {data: [...]}},
  19067. * ...
  19068. * ],
  19069. * media: [
  19070. * {
  19071. * query: {maxWidth: 320},
  19072. * option: {series: {x: 20}, visualMap: {show: false}}
  19073. * },
  19074. * {
  19075. * query: {minWidth: 320, maxWidth: 720},
  19076. * option: {series: {x: 500}, visualMap: {show: true}}
  19077. * },
  19078. * {
  19079. * option: {series: {x: 1200}, visualMap: {show: true}}
  19080. * }
  19081. * ]
  19082. * };
  19083. *
  19084. * @alias module:echarts/model/OptionManager
  19085. * @param {module:echarts/ExtensionAPI} api
  19086. */
  19087. function OptionManager(api) {
  19088. /**
  19089. * @private
  19090. * @type {module:echarts/ExtensionAPI}
  19091. */
  19092. this._api = api;
  19093. /**
  19094. * @private
  19095. * @type {Array.<number>}
  19096. */
  19097. this._timelineOptions = [];
  19098. /**
  19099. * @private
  19100. * @type {Array.<Object>}
  19101. */
  19102. this._mediaList = [];
  19103. /**
  19104. * @private
  19105. * @type {Object}
  19106. */
  19107. this._mediaDefault;
  19108. /**
  19109. * -1, means default.
  19110. * empty means no media.
  19111. * @private
  19112. * @type {Array.<number>}
  19113. */
  19114. this._currentMediaIndices = [];
  19115. /**
  19116. * @private
  19117. * @type {Object}
  19118. */
  19119. this._optionBackup;
  19120. /**
  19121. * @private
  19122. * @type {Object}
  19123. */
  19124. this._newBaseOption;
  19125. }
  19126. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  19127. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  19128. // rawOption cloned and backuped when timeline changed, which does no
  19129. // good to performance. What's more, that both timeline and setOption
  19130. // method supply 'notMerge' brings complex and some problems.
  19131. // Consider this case:
  19132. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  19133. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  19134. OptionManager.prototype = {
  19135. constructor: OptionManager,
  19136. /**
  19137. * @public
  19138. * @param {Object} rawOption Raw option.
  19139. * @param {module:echarts/model/Global} ecModel
  19140. * @param {Array.<Function>} optionPreprocessorFuncs
  19141. * @return {Object} Init option
  19142. */
  19143. setOption: function (rawOption, optionPreprocessorFuncs) {
  19144. if (rawOption) {
  19145. // That set dat primitive is dangerous if user reuse the data when setOption again.
  19146. each$1(normalizeToArray(rawOption.series), function (series) {
  19147. series && series.data && isTypedArray(series.data) && setAsPrimitive(series.data);
  19148. });
  19149. }
  19150. // Caution: some series modify option data, if do not clone,
  19151. // it should ensure that the repeat modify correctly
  19152. // (create a new object when modify itself).
  19153. rawOption = clone$3(rawOption, true);
  19154. // FIXME
  19155. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  19156. var oldOptionBackup = this._optionBackup;
  19157. var newParsedOption = parseRawOption.call(
  19158. this, rawOption, optionPreprocessorFuncs, !oldOptionBackup
  19159. );
  19160. this._newBaseOption = newParsedOption.baseOption;
  19161. // For setOption at second time (using merge mode);
  19162. if (oldOptionBackup) {
  19163. // Only baseOption can be merged.
  19164. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);
  19165. // For simplicity, timeline options and media options do not support merge,
  19166. // that is, if you `setOption` twice and both has timeline options, the latter
  19167. // timeline opitons will not be merged to the formers, but just substitude them.
  19168. if (newParsedOption.timelineOptions.length) {
  19169. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  19170. }
  19171. if (newParsedOption.mediaList.length) {
  19172. oldOptionBackup.mediaList = newParsedOption.mediaList;
  19173. }
  19174. if (newParsedOption.mediaDefault) {
  19175. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  19176. }
  19177. }
  19178. else {
  19179. this._optionBackup = newParsedOption;
  19180. }
  19181. },
  19182. /**
  19183. * @param {boolean} isRecreate
  19184. * @return {Object}
  19185. */
  19186. mountOption: function (isRecreate) {
  19187. var optionBackup = this._optionBackup;
  19188. // TODO
  19189. // 如果没有reset功能则不clone。
  19190. this._timelineOptions = map$1(optionBackup.timelineOptions, clone$3);
  19191. this._mediaList = map$1(optionBackup.mediaList, clone$3);
  19192. this._mediaDefault = clone$3(optionBackup.mediaDefault);
  19193. this._currentMediaIndices = [];
  19194. return clone$3(isRecreate
  19195. // this._optionBackup.baseOption, which is created at the first `setOption`
  19196. // called, and is merged into every new option by inner method `mergeOption`
  19197. // each time `setOption` called, can be only used in `isRecreate`, because
  19198. // its reliability is under suspicion. In other cases option merge is
  19199. // performed by `model.mergeOption`.
  19200. ? optionBackup.baseOption : this._newBaseOption
  19201. );
  19202. },
  19203. /**
  19204. * @param {module:echarts/model/Global} ecModel
  19205. * @return {Object}
  19206. */
  19207. getTimelineOption: function (ecModel) {
  19208. var option;
  19209. var timelineOptions = this._timelineOptions;
  19210. if (timelineOptions.length) {
  19211. // getTimelineOption can only be called after ecModel inited,
  19212. // so we can get currentIndex from timelineModel.
  19213. var timelineModel = ecModel.getComponent('timeline');
  19214. if (timelineModel) {
  19215. option = clone$3(
  19216. timelineOptions[timelineModel.getCurrentIndex()],
  19217. true
  19218. );
  19219. }
  19220. }
  19221. return option;
  19222. },
  19223. /**
  19224. * @param {module:echarts/model/Global} ecModel
  19225. * @return {Array.<Object>}
  19226. */
  19227. getMediaOption: function (ecModel) {
  19228. var ecWidth = this._api.getWidth();
  19229. var ecHeight = this._api.getHeight();
  19230. var mediaList = this._mediaList;
  19231. var mediaDefault = this._mediaDefault;
  19232. var indices = [];
  19233. var result = [];
  19234. // No media defined.
  19235. if (!mediaList.length && !mediaDefault) {
  19236. return result;
  19237. }
  19238. // Multi media may be applied, the latter defined media has higher priority.
  19239. for (var i = 0, len = mediaList.length; i < len; i++) {
  19240. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  19241. indices.push(i);
  19242. }
  19243. }
  19244. // FIXME
  19245. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  19246. if (!indices.length && mediaDefault) {
  19247. indices = [-1];
  19248. }
  19249. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  19250. result = map$1(indices, function (index) {
  19251. return clone$3(
  19252. index === -1 ? mediaDefault.option : mediaList[index].option
  19253. );
  19254. });
  19255. }
  19256. // Otherwise return nothing.
  19257. this._currentMediaIndices = indices;
  19258. return result;
  19259. }
  19260. };
  19261. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  19262. var timelineOptions = [];
  19263. var mediaList = [];
  19264. var mediaDefault;
  19265. var baseOption;
  19266. // Compatible with ec2.
  19267. var timelineOpt = rawOption.timeline;
  19268. if (rawOption.baseOption) {
  19269. baseOption = rawOption.baseOption;
  19270. }
  19271. // For timeline
  19272. if (timelineOpt || rawOption.options) {
  19273. baseOption = baseOption || {};
  19274. timelineOptions = (rawOption.options || []).slice();
  19275. }
  19276. // For media query
  19277. if (rawOption.media) {
  19278. baseOption = baseOption || {};
  19279. var media = rawOption.media;
  19280. each$4(media, function (singleMedia) {
  19281. if (singleMedia && singleMedia.option) {
  19282. if (singleMedia.query) {
  19283. mediaList.push(singleMedia);
  19284. }
  19285. else if (!mediaDefault) {
  19286. // Use the first media default.
  19287. mediaDefault = singleMedia;
  19288. }
  19289. }
  19290. });
  19291. }
  19292. // For normal option
  19293. if (!baseOption) {
  19294. baseOption = rawOption;
  19295. }
  19296. // Set timelineOpt to baseOption in ec3,
  19297. // which is convenient for merge option.
  19298. if (!baseOption.timeline) {
  19299. baseOption.timeline = timelineOpt;
  19300. }
  19301. // Preprocess.
  19302. each$4([baseOption].concat(timelineOptions)
  19303. .concat(map(mediaList, function (media) {
  19304. return media.option;
  19305. })),
  19306. function (option) {
  19307. each$4(optionPreprocessorFuncs, function (preProcess) {
  19308. preProcess(option, isNew);
  19309. });
  19310. }
  19311. );
  19312. return {
  19313. baseOption: baseOption,
  19314. timelineOptions: timelineOptions,
  19315. mediaDefault: mediaDefault,
  19316. mediaList: mediaList
  19317. };
  19318. }
  19319. /**
  19320. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  19321. * Support: width, height, aspectRatio
  19322. * Can use max or min as prefix.
  19323. */
  19324. function applyMediaQuery(query, ecWidth, ecHeight) {
  19325. var realMap = {
  19326. width: ecWidth,
  19327. height: ecHeight,
  19328. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  19329. };
  19330. var applicatable = true;
  19331. each$1(query, function (value, attr) {
  19332. var matched = attr.match(QUERY_REG);
  19333. if (!matched || !matched[1] || !matched[2]) {
  19334. return;
  19335. }
  19336. var operator = matched[1];
  19337. var realAttr = matched[2].toLowerCase();
  19338. if (!compare(realMap[realAttr], value, operator)) {
  19339. applicatable = false;
  19340. }
  19341. });
  19342. return applicatable;
  19343. }
  19344. function compare(real, expect, operator) {
  19345. if (operator === 'min') {
  19346. return real >= expect;
  19347. }
  19348. else if (operator === 'max') {
  19349. return real <= expect;
  19350. }
  19351. else { // Equals
  19352. return real === expect;
  19353. }
  19354. }
  19355. function indicesEquals(indices1, indices2) {
  19356. // indices is always order by asc and has only finite number.
  19357. return indices1.join(',') === indices2.join(',');
  19358. }
  19359. /**
  19360. * Consider case:
  19361. * `chart.setOption(opt1);`
  19362. * Then user do some interaction like dataZoom, dataView changing.
  19363. * `chart.setOption(opt2);`
  19364. * Then user press 'reset button' in toolbox.
  19365. *
  19366. * After doing that all of the interaction effects should be reset, the
  19367. * chart should be the same as the result of invoke
  19368. * `chart.setOption(opt1); chart.setOption(opt2);`.
  19369. *
  19370. * Although it is not able ensure that
  19371. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  19372. * `chart.setOption(merge(opt1, opt2));` exactly,
  19373. * this might be the only simple way to implement that feature.
  19374. *
  19375. * MEMO: We've considered some other approaches:
  19376. * 1. Each model handle its self restoration but not uniform treatment.
  19377. * (Too complex in logic and error-prone)
  19378. * 2. Use a shadow ecModel. (Performace expensive)
  19379. */
  19380. function mergeOption(oldOption, newOption) {
  19381. newOption = newOption || {};
  19382. each$4(newOption, function (newCptOpt, mainType) {
  19383. if (newCptOpt == null) {
  19384. return;
  19385. }
  19386. var oldCptOpt = oldOption[mainType];
  19387. if (!ComponentModel.hasClass(mainType)) {
  19388. oldOption[mainType] = merge$1(oldCptOpt, newCptOpt, true);
  19389. }
  19390. else {
  19391. newCptOpt = normalizeToArray(newCptOpt);
  19392. oldCptOpt = normalizeToArray(oldCptOpt);
  19393. var mapResult = mappingToExists(oldCptOpt, newCptOpt);
  19394. oldOption[mainType] = map$1(mapResult, function (item) {
  19395. return (item.option && item.exist)
  19396. ? merge$1(item.exist, item.option, true)
  19397. : (item.exist || item.option);
  19398. });
  19399. }
  19400. });
  19401. }
  19402. /*
  19403. * Licensed to the Apache Software Foundation (ASF) under one
  19404. * or more contributor license agreements. See the NOTICE file
  19405. * distributed with this work for additional information
  19406. * regarding copyright ownership. The ASF licenses this file
  19407. * to you under the Apache License, Version 2.0 (the
  19408. * "License"); you may not use this file except in compliance
  19409. * with the License. You may obtain a copy of the License at
  19410. *
  19411. * http://www.apache.org/licenses/LICENSE-2.0
  19412. *
  19413. * Unless required by applicable law or agreed to in writing,
  19414. * software distributed under the License is distributed on an
  19415. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19416. * KIND, either express or implied. See the License for the
  19417. * specific language governing permissions and limitations
  19418. * under the License.
  19419. */
  19420. var each$5 = each$1;
  19421. var isObject$3 = isObject$1;
  19422. var POSSIBLE_STYLES = [
  19423. 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',
  19424. 'chordStyle', 'label', 'labelLine'
  19425. ];
  19426. function compatEC2ItemStyle(opt) {
  19427. var itemStyleOpt = opt && opt.itemStyle;
  19428. if (!itemStyleOpt) {
  19429. return;
  19430. }
  19431. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  19432. var styleName = POSSIBLE_STYLES[i];
  19433. var normalItemStyleOpt = itemStyleOpt.normal;
  19434. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  19435. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  19436. opt[styleName] = opt[styleName] || {};
  19437. if (!opt[styleName].normal) {
  19438. opt[styleName].normal = normalItemStyleOpt[styleName];
  19439. }
  19440. else {
  19441. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  19442. }
  19443. normalItemStyleOpt[styleName] = null;
  19444. }
  19445. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  19446. opt[styleName] = opt[styleName] || {};
  19447. if (!opt[styleName].emphasis) {
  19448. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  19449. }
  19450. else {
  19451. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  19452. }
  19453. emphasisItemStyleOpt[styleName] = null;
  19454. }
  19455. }
  19456. }
  19457. function convertNormalEmphasis(opt, optType, useExtend) {
  19458. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  19459. var normalOpt = opt[optType].normal;
  19460. var emphasisOpt = opt[optType].emphasis;
  19461. if (normalOpt) {
  19462. // Timeline controlStyle has other properties besides normal and emphasis
  19463. if (useExtend) {
  19464. opt[optType].normal = opt[optType].emphasis = null;
  19465. defaults(opt[optType], normalOpt);
  19466. }
  19467. else {
  19468. opt[optType] = normalOpt;
  19469. }
  19470. }
  19471. if (emphasisOpt) {
  19472. opt.emphasis = opt.emphasis || {};
  19473. opt.emphasis[optType] = emphasisOpt;
  19474. }
  19475. }
  19476. }
  19477. function removeEC3NormalStatus(opt) {
  19478. convertNormalEmphasis(opt, 'itemStyle');
  19479. convertNormalEmphasis(opt, 'lineStyle');
  19480. convertNormalEmphasis(opt, 'areaStyle');
  19481. convertNormalEmphasis(opt, 'label');
  19482. convertNormalEmphasis(opt, 'labelLine');
  19483. // treemap
  19484. convertNormalEmphasis(opt, 'upperLabel');
  19485. // graph
  19486. convertNormalEmphasis(opt, 'edgeLabel');
  19487. }
  19488. function compatTextStyle(opt, propName) {
  19489. // Check whether is not object (string\null\undefined ...)
  19490. var labelOptSingle = isObject$3(opt) && opt[propName];
  19491. var textStyle = isObject$3(labelOptSingle) && labelOptSingle.textStyle;
  19492. if (textStyle) {
  19493. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  19494. var propName = TEXT_STYLE_OPTIONS[i];
  19495. if (textStyle.hasOwnProperty(propName)) {
  19496. labelOptSingle[propName] = textStyle[propName];
  19497. }
  19498. }
  19499. }
  19500. }
  19501. function compatEC3CommonStyles(opt) {
  19502. if (opt) {
  19503. removeEC3NormalStatus(opt);
  19504. compatTextStyle(opt, 'label');
  19505. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  19506. }
  19507. }
  19508. function processSeries(seriesOpt) {
  19509. if (!isObject$3(seriesOpt)) {
  19510. return;
  19511. }
  19512. compatEC2ItemStyle(seriesOpt);
  19513. removeEC3NormalStatus(seriesOpt);
  19514. compatTextStyle(seriesOpt, 'label');
  19515. // treemap
  19516. compatTextStyle(seriesOpt, 'upperLabel');
  19517. // graph
  19518. compatTextStyle(seriesOpt, 'edgeLabel');
  19519. if (seriesOpt.emphasis) {
  19520. compatTextStyle(seriesOpt.emphasis, 'label');
  19521. // treemap
  19522. compatTextStyle(seriesOpt.emphasis, 'upperLabel');
  19523. // graph
  19524. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  19525. }
  19526. var markPoint = seriesOpt.markPoint;
  19527. if (markPoint) {
  19528. compatEC2ItemStyle(markPoint);
  19529. compatEC3CommonStyles(markPoint);
  19530. }
  19531. var markLine = seriesOpt.markLine;
  19532. if (markLine) {
  19533. compatEC2ItemStyle(markLine);
  19534. compatEC3CommonStyles(markLine);
  19535. }
  19536. var markArea = seriesOpt.markArea;
  19537. if (markArea) {
  19538. compatEC3CommonStyles(markArea);
  19539. }
  19540. var data = seriesOpt.data;
  19541. // Break with ec3: if `setOption` again, there may be no `type` in option,
  19542. // then the backward compat based on option type will not be performed.
  19543. if (seriesOpt.type === 'graph') {
  19544. data = data || seriesOpt.nodes;
  19545. var edgeData = seriesOpt.links || seriesOpt.edges;
  19546. if (edgeData && !isTypedArray(edgeData)) {
  19547. for (var i = 0; i < edgeData.length; i++) {
  19548. compatEC3CommonStyles(edgeData[i]);
  19549. }
  19550. }
  19551. each$1(seriesOpt.categories, function (opt) {
  19552. removeEC3NormalStatus(opt);
  19553. });
  19554. }
  19555. if (data && !isTypedArray(data)) {
  19556. for (var i = 0; i < data.length; i++) {
  19557. compatEC3CommonStyles(data[i]);
  19558. }
  19559. }
  19560. // mark point data
  19561. var markPoint = seriesOpt.markPoint;
  19562. if (markPoint && markPoint.data) {
  19563. var mpData = markPoint.data;
  19564. for (var i = 0; i < mpData.length; i++) {
  19565. compatEC3CommonStyles(mpData[i]);
  19566. }
  19567. }
  19568. // mark line data
  19569. var markLine = seriesOpt.markLine;
  19570. if (markLine && markLine.data) {
  19571. var mlData = markLine.data;
  19572. for (var i = 0; i < mlData.length; i++) {
  19573. if (isArray(mlData[i])) {
  19574. compatEC3CommonStyles(mlData[i][0]);
  19575. compatEC3CommonStyles(mlData[i][1]);
  19576. }
  19577. else {
  19578. compatEC3CommonStyles(mlData[i]);
  19579. }
  19580. }
  19581. }
  19582. // Series
  19583. if (seriesOpt.type === 'gauge') {
  19584. compatTextStyle(seriesOpt, 'axisLabel');
  19585. compatTextStyle(seriesOpt, 'title');
  19586. compatTextStyle(seriesOpt, 'detail');
  19587. }
  19588. else if (seriesOpt.type === 'treemap') {
  19589. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  19590. each$1(seriesOpt.levels, function (opt) {
  19591. removeEC3NormalStatus(opt);
  19592. });
  19593. }
  19594. else if (seriesOpt.type === 'tree') {
  19595. removeEC3NormalStatus(seriesOpt.leaves);
  19596. }
  19597. // sunburst starts from ec4, so it does not need to compat levels.
  19598. }
  19599. function toArr(o) {
  19600. return isArray(o) ? o : o ? [o] : [];
  19601. }
  19602. function toObj(o) {
  19603. return (isArray(o) ? o[0] : o) || {};
  19604. }
  19605. var compatStyle = function (option, isTheme) {
  19606. each$5(toArr(option.series), function (seriesOpt) {
  19607. isObject$3(seriesOpt) && processSeries(seriesOpt);
  19608. });
  19609. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  19610. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  19611. each$5(
  19612. axes,
  19613. function (axisName) {
  19614. each$5(toArr(option[axisName]), function (axisOpt) {
  19615. if (axisOpt) {
  19616. compatTextStyle(axisOpt, 'axisLabel');
  19617. compatTextStyle(axisOpt.axisPointer, 'label');
  19618. }
  19619. });
  19620. }
  19621. );
  19622. each$5(toArr(option.parallel), function (parallelOpt) {
  19623. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  19624. compatTextStyle(parallelAxisDefault, 'axisLabel');
  19625. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  19626. });
  19627. each$5(toArr(option.calendar), function (calendarOpt) {
  19628. convertNormalEmphasis(calendarOpt, 'itemStyle');
  19629. compatTextStyle(calendarOpt, 'dayLabel');
  19630. compatTextStyle(calendarOpt, 'monthLabel');
  19631. compatTextStyle(calendarOpt, 'yearLabel');
  19632. });
  19633. // radar.name.textStyle
  19634. each$5(toArr(option.radar), function (radarOpt) {
  19635. compatTextStyle(radarOpt, 'name');
  19636. });
  19637. each$5(toArr(option.geo), function (geoOpt) {
  19638. if (isObject$3(geoOpt)) {
  19639. compatEC3CommonStyles(geoOpt);
  19640. each$5(toArr(geoOpt.regions), function (regionObj) {
  19641. compatEC3CommonStyles(regionObj);
  19642. });
  19643. }
  19644. });
  19645. each$5(toArr(option.timeline), function (timelineOpt) {
  19646. compatEC3CommonStyles(timelineOpt);
  19647. convertNormalEmphasis(timelineOpt, 'label');
  19648. convertNormalEmphasis(timelineOpt, 'itemStyle');
  19649. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  19650. var data = timelineOpt.data;
  19651. isArray(data) && each$1(data, function (item) {
  19652. if (isObject$1(item)) {
  19653. convertNormalEmphasis(item, 'label');
  19654. convertNormalEmphasis(item, 'itemStyle');
  19655. }
  19656. });
  19657. });
  19658. each$5(toArr(option.toolbox), function (toolboxOpt) {
  19659. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  19660. each$5(toolboxOpt.feature, function (featureOpt) {
  19661. convertNormalEmphasis(featureOpt, 'iconStyle');
  19662. });
  19663. });
  19664. compatTextStyle(toObj(option.axisPointer), 'label');
  19665. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  19666. };
  19667. /*
  19668. * Licensed to the Apache Software Foundation (ASF) under one
  19669. * or more contributor license agreements. See the NOTICE file
  19670. * distributed with this work for additional information
  19671. * regarding copyright ownership. The ASF licenses this file
  19672. * to you under the Apache License, Version 2.0 (the
  19673. * "License"); you may not use this file except in compliance
  19674. * with the License. You may obtain a copy of the License at
  19675. *
  19676. * http://www.apache.org/licenses/LICENSE-2.0
  19677. *
  19678. * Unless required by applicable law or agreed to in writing,
  19679. * software distributed under the License is distributed on an
  19680. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19681. * KIND, either express or implied. See the License for the
  19682. * specific language governing permissions and limitations
  19683. * under the License.
  19684. */
  19685. // Compatitable with 2.0
  19686. function get(opt, path) {
  19687. path = path.split(',');
  19688. var obj = opt;
  19689. for (var i = 0; i < path.length; i++) {
  19690. obj = obj && obj[path[i]];
  19691. if (obj == null) {
  19692. break;
  19693. }
  19694. }
  19695. return obj;
  19696. }
  19697. function set$1(opt, path, val, overwrite) {
  19698. path = path.split(',');
  19699. var obj = opt;
  19700. var key;
  19701. for (var i = 0; i < path.length - 1; i++) {
  19702. key = path[i];
  19703. if (obj[key] == null) {
  19704. obj[key] = {};
  19705. }
  19706. obj = obj[key];
  19707. }
  19708. if (overwrite || obj[path[i]] == null) {
  19709. obj[path[i]] = val;
  19710. }
  19711. }
  19712. function compatLayoutProperties(option) {
  19713. each$1(LAYOUT_PROPERTIES, function (prop) {
  19714. if (prop[0] in option && !(prop[1] in option)) {
  19715. option[prop[1]] = option[prop[0]];
  19716. }
  19717. });
  19718. }
  19719. var LAYOUT_PROPERTIES = [
  19720. ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']
  19721. ];
  19722. var COMPATITABLE_COMPONENTS = [
  19723. 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'
  19724. ];
  19725. var backwardCompat = function (option, isTheme) {
  19726. compatStyle(option, isTheme);
  19727. // Make sure series array for model initialization.
  19728. option.series = normalizeToArray(option.series);
  19729. each$1(option.series, function (seriesOpt) {
  19730. if (!isObject$1(seriesOpt)) {
  19731. return;
  19732. }
  19733. var seriesType = seriesOpt.type;
  19734. if (seriesType === 'pie' || seriesType === 'gauge') {
  19735. if (seriesOpt.clockWise != null) {
  19736. seriesOpt.clockwise = seriesOpt.clockWise;
  19737. }
  19738. }
  19739. if (seriesType === 'gauge') {
  19740. var pointerColor = get(seriesOpt, 'pointer.color');
  19741. pointerColor != null
  19742. && set$1(seriesOpt, 'itemStyle.normal.color', pointerColor);
  19743. }
  19744. compatLayoutProperties(seriesOpt);
  19745. });
  19746. // dataRange has changed to visualMap
  19747. if (option.dataRange) {
  19748. option.visualMap = option.dataRange;
  19749. }
  19750. each$1(COMPATITABLE_COMPONENTS, function (componentName) {
  19751. var options = option[componentName];
  19752. if (options) {
  19753. if (!isArray(options)) {
  19754. options = [options];
  19755. }
  19756. each$1(options, function (option) {
  19757. compatLayoutProperties(option);
  19758. });
  19759. }
  19760. });
  19761. };
  19762. /*
  19763. * Licensed to the Apache Software Foundation (ASF) under one
  19764. * or more contributor license agreements. See the NOTICE file
  19765. * distributed with this work for additional information
  19766. * regarding copyright ownership. The ASF licenses this file
  19767. * to you under the Apache License, Version 2.0 (the
  19768. * "License"); you may not use this file except in compliance
  19769. * with the License. You may obtain a copy of the License at
  19770. *
  19771. * http://www.apache.org/licenses/LICENSE-2.0
  19772. *
  19773. * Unless required by applicable law or agreed to in writing,
  19774. * software distributed under the License is distributed on an
  19775. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19776. * KIND, either express or implied. See the License for the
  19777. * specific language governing permissions and limitations
  19778. * under the License.
  19779. */
  19780. // (1) [Caution]: the logic is correct based on the premises:
  19781. // data processing stage is blocked in stream.
  19782. // See <module:echarts/stream/Scheduler#performDataProcessorTasks>
  19783. // (2) Only register once when import repeatly.
  19784. // Should be executed before after series filtered and before stack calculation.
  19785. var dataStack = function (ecModel) {
  19786. var stackInfoMap = createHashMap();
  19787. ecModel.eachSeries(function (seriesModel) {
  19788. var stack = seriesModel.get('stack');
  19789. // Compatibal: when `stack` is set as '', do not stack.
  19790. if (stack) {
  19791. var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
  19792. var data = seriesModel.getData();
  19793. var stackInfo = {
  19794. // Used for calculate axis extent automatically.
  19795. stackResultDimension: data.getCalculationInfo('stackResultDimension'),
  19796. stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
  19797. stackedDimension: data.getCalculationInfo('stackedDimension'),
  19798. stackedByDimension: data.getCalculationInfo('stackedByDimension'),
  19799. isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
  19800. data: data,
  19801. seriesModel: seriesModel
  19802. };
  19803. // If stacked on axis that do not support data stack.
  19804. if (!stackInfo.stackedDimension
  19805. || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)
  19806. ) {
  19807. return;
  19808. }
  19809. stackInfoList.length && data.setCalculationInfo(
  19810. 'stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel
  19811. );
  19812. stackInfoList.push(stackInfo);
  19813. }
  19814. });
  19815. stackInfoMap.each(calculateStack);
  19816. };
  19817. function calculateStack(stackInfoList) {
  19818. each$1(stackInfoList, function (targetStackInfo, idxInStack) {
  19819. var resultVal = [];
  19820. var resultNaN = [NaN, NaN];
  19821. var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
  19822. var targetData = targetStackInfo.data;
  19823. var isStackedByIndex = targetStackInfo.isStackedByIndex;
  19824. // Should not write on raw data, because stack series model list changes
  19825. // depending on legend selection.
  19826. var newData = targetData.map(dims, function (v0, v1, dataIndex) {
  19827. var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex);
  19828. // Consider `connectNulls` of line area, if value is NaN, stackedOver
  19829. // should also be NaN, to draw a appropriate belt area.
  19830. if (isNaN(sum)) {
  19831. return resultNaN;
  19832. }
  19833. var byValue;
  19834. var stackedDataRawIndex;
  19835. if (isStackedByIndex) {
  19836. stackedDataRawIndex = targetData.getRawIndex(dataIndex);
  19837. }
  19838. else {
  19839. byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
  19840. }
  19841. // If stackOver is NaN, chart view will render point on value start.
  19842. var stackedOver = NaN;
  19843. for (var j = idxInStack - 1; j >= 0; j--) {
  19844. var stackInfo = stackInfoList[j];
  19845. // Has been optimized by inverted indices on `stackedByDimension`.
  19846. if (!isStackedByIndex) {
  19847. stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
  19848. }
  19849. if (stackedDataRawIndex >= 0) {
  19850. var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex);
  19851. // Considering positive stack, negative stack and empty data
  19852. if ((sum >= 0 && val > 0) // Positive stack
  19853. || (sum <= 0 && val < 0) // Negative stack
  19854. ) {
  19855. sum += val;
  19856. stackedOver = val;
  19857. break;
  19858. }
  19859. }
  19860. }
  19861. resultVal[0] = sum;
  19862. resultVal[1] = stackedOver;
  19863. return resultVal;
  19864. });
  19865. targetData.hostModel.setData(newData);
  19866. // Update for consequent calculation
  19867. targetStackInfo.data = newData;
  19868. });
  19869. }
  19870. /*
  19871. * Licensed to the Apache Software Foundation (ASF) under one
  19872. * or more contributor license agreements. See the NOTICE file
  19873. * distributed with this work for additional information
  19874. * regarding copyright ownership. The ASF licenses this file
  19875. * to you under the Apache License, Version 2.0 (the
  19876. * "License"); you may not use this file except in compliance
  19877. * with the License. You may obtain a copy of the License at
  19878. *
  19879. * http://www.apache.org/licenses/LICENSE-2.0
  19880. *
  19881. * Unless required by applicable law or agreed to in writing,
  19882. * software distributed under the License is distributed on an
  19883. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19884. * KIND, either express or implied. See the License for the
  19885. * specific language governing permissions and limitations
  19886. * under the License.
  19887. */
  19888. // TODO
  19889. // ??? refactor? check the outer usage of data provider.
  19890. // merge with defaultDimValueGetter?
  19891. /**
  19892. * If normal array used, mutable chunk size is supported.
  19893. * If typed array used, chunk size must be fixed.
  19894. */
  19895. function DefaultDataProvider(source, dimSize) {
  19896. if (!Source.isInstance(source)) {
  19897. source = Source.seriesDataToSource(source);
  19898. }
  19899. this._source = source;
  19900. var data = this._data = source.data;
  19901. var sourceFormat = source.sourceFormat;
  19902. // Typed array. TODO IE10+?
  19903. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  19904. if (__DEV__) {
  19905. if (dimSize == null) {
  19906. throw new Error('Typed array data must specify dimension size');
  19907. }
  19908. }
  19909. this._offset = 0;
  19910. this._dimSize = dimSize;
  19911. this._data = data;
  19912. }
  19913. var methods = providerMethods[
  19914. sourceFormat === SOURCE_FORMAT_ARRAY_ROWS
  19915. ? sourceFormat + '_' + source.seriesLayoutBy
  19916. : sourceFormat
  19917. ];
  19918. if (__DEV__) {
  19919. assert$1(methods, 'Invalide sourceFormat: ' + sourceFormat);
  19920. }
  19921. extend(this, methods);
  19922. }
  19923. var providerProto = DefaultDataProvider.prototype;
  19924. // If data is pure without style configuration
  19925. providerProto.pure = false;
  19926. // If data is persistent and will not be released after use.
  19927. providerProto.persistent = true;
  19928. // ???! FIXME legacy data provider do not has method getSource
  19929. providerProto.getSource = function () {
  19930. return this._source;
  19931. };
  19932. var providerMethods = {
  19933. 'arrayRows_column': {
  19934. pure: true,
  19935. count: function () {
  19936. return Math.max(0, this._data.length - this._source.startIndex);
  19937. },
  19938. getItem: function (idx) {
  19939. return this._data[idx + this._source.startIndex];
  19940. },
  19941. appendData: appendDataSimply
  19942. },
  19943. 'arrayRows_row': {
  19944. pure: true,
  19945. count: function () {
  19946. var row = this._data[0];
  19947. return row ? Math.max(0, row.length - this._source.startIndex) : 0;
  19948. },
  19949. getItem: function (idx) {
  19950. idx += this._source.startIndex;
  19951. var item = [];
  19952. var data = this._data;
  19953. for (var i = 0; i < data.length; i++) {
  19954. var row = data[i];
  19955. item.push(row ? row[idx] : null);
  19956. }
  19957. return item;
  19958. },
  19959. appendData: function () {
  19960. throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
  19961. }
  19962. },
  19963. 'objectRows': {
  19964. pure: true,
  19965. count: countSimply,
  19966. getItem: getItemSimply,
  19967. appendData: appendDataSimply
  19968. },
  19969. 'keyedColumns': {
  19970. pure: true,
  19971. count: function () {
  19972. var dimName = this._source.dimensionsDefine[0].name;
  19973. var col = this._data[dimName];
  19974. return col ? col.length : 0;
  19975. },
  19976. getItem: function (idx) {
  19977. var item = [];
  19978. var dims = this._source.dimensionsDefine;
  19979. for (var i = 0; i < dims.length; i++) {
  19980. var col = this._data[dims[i].name];
  19981. item.push(col ? col[idx] : null);
  19982. }
  19983. return item;
  19984. },
  19985. appendData: function (newData) {
  19986. var data = this._data;
  19987. each$1(newData, function (newCol, key) {
  19988. var oldCol = data[key] || (data[key] = []);
  19989. for (var i = 0; i < (newCol || []).length; i++) {
  19990. oldCol.push(newCol[i]);
  19991. }
  19992. });
  19993. }
  19994. },
  19995. 'original': {
  19996. count: countSimply,
  19997. getItem: getItemSimply,
  19998. appendData: appendDataSimply
  19999. },
  20000. 'typedArray': {
  20001. persistent: false,
  20002. pure: true,
  20003. count: function () {
  20004. return this._data ? (this._data.length / this._dimSize) : 0;
  20005. },
  20006. getItem: function (idx, out) {
  20007. idx = idx - this._offset;
  20008. out = out || [];
  20009. var offset = this._dimSize * idx;
  20010. for (var i = 0; i < this._dimSize; i++) {
  20011. out[i] = this._data[offset + i];
  20012. }
  20013. return out;
  20014. },
  20015. appendData: function (newData) {
  20016. if (__DEV__) {
  20017. assert$1(
  20018. isTypedArray(newData),
  20019. 'Added data must be TypedArray if data in initialization is TypedArray'
  20020. );
  20021. }
  20022. this._data = newData;
  20023. },
  20024. // Clean self if data is already used.
  20025. clean: function () {
  20026. // PENDING
  20027. this._offset += this.count();
  20028. this._data = null;
  20029. }
  20030. }
  20031. };
  20032. function countSimply() {
  20033. return this._data.length;
  20034. }
  20035. function getItemSimply(idx) {
  20036. return this._data[idx];
  20037. }
  20038. function appendDataSimply(newData) {
  20039. for (var i = 0; i < newData.length; i++) {
  20040. this._data.push(newData[i]);
  20041. }
  20042. }
  20043. var rawValueGetters = {
  20044. arrayRows: getRawValueSimply,
  20045. objectRows: function (dataItem, dataIndex, dimIndex, dimName) {
  20046. return dimIndex != null ? dataItem[dimName] : dataItem;
  20047. },
  20048. keyedColumns: getRawValueSimply,
  20049. original: function (dataItem, dataIndex, dimIndex, dimName) {
  20050. // FIXME
  20051. // In some case (markpoint in geo (geo-map.html)), dataItem
  20052. // is {coord: [...]}
  20053. var value = getDataItemValue(dataItem);
  20054. return (dimIndex == null || !(value instanceof Array))
  20055. ? value
  20056. : value[dimIndex];
  20057. },
  20058. typedArray: getRawValueSimply
  20059. };
  20060. function getRawValueSimply(dataItem, dataIndex, dimIndex, dimName) {
  20061. return dimIndex != null ? dataItem[dimIndex] : dataItem;
  20062. }
  20063. var defaultDimValueGetters = {
  20064. arrayRows: getDimValueSimply,
  20065. objectRows: function (dataItem, dimName, dataIndex, dimIndex) {
  20066. return converDataValue(dataItem[dimName], this._dimensionInfos[dimName]);
  20067. },
  20068. keyedColumns: getDimValueSimply,
  20069. original: function (dataItem, dimName, dataIndex, dimIndex) {
  20070. // Performance sensitive, do not use modelUtil.getDataItemValue.
  20071. // If dataItem is an plain object with no value field, the var `value`
  20072. // will be assigned with the object, but it will be tread correctly
  20073. // in the `convertDataValue`.
  20074. var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  20075. // If any dataItem is like { value: 10 }
  20076. if (!this._rawData.pure && isDataItemOption(dataItem)) {
  20077. this.hasItemOption = true;
  20078. }
  20079. return converDataValue(
  20080. (value instanceof Array)
  20081. ? value[dimIndex]
  20082. // If value is a single number or something else not array.
  20083. : value,
  20084. this._dimensionInfos[dimName]
  20085. );
  20086. },
  20087. typedArray: function (dataItem, dimName, dataIndex, dimIndex) {
  20088. return dataItem[dimIndex];
  20089. }
  20090. };
  20091. function getDimValueSimply(dataItem, dimName, dataIndex, dimIndex) {
  20092. return converDataValue(dataItem[dimIndex], this._dimensionInfos[dimName]);
  20093. }
  20094. /**
  20095. * This helper method convert value in data.
  20096. * @param {string|number|Date} value
  20097. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  20098. * If "dimInfo.ordinalParseAndSave", ordinal value can be parsed.
  20099. */
  20100. function converDataValue(value, dimInfo) {
  20101. // Performance sensitive.
  20102. var dimType = dimInfo && dimInfo.type;
  20103. if (dimType === 'ordinal') {
  20104. // If given value is a category string
  20105. var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
  20106. return ordinalMeta
  20107. ? ordinalMeta.parseAndCollect(value)
  20108. : value;
  20109. }
  20110. if (dimType === 'time'
  20111. // spead up when using timestamp
  20112. && typeof value !== 'number'
  20113. && value != null
  20114. && value !== '-'
  20115. ) {
  20116. value = +parseDate(value);
  20117. }
  20118. // dimType defaults 'number'.
  20119. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  20120. // parse to NaN.
  20121. return (value == null || value === '')
  20122. ? NaN
  20123. // If string (like '-'), using '+' parse to NaN
  20124. // If object, also parse to NaN
  20125. : +value;
  20126. }
  20127. // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
  20128. // Consider persistent.
  20129. // Caution: why use raw value to display on label or tooltip?
  20130. // A reason is to avoid format. For example time value we do not know
  20131. // how to format is expected. More over, if stack is used, calculated
  20132. // value may be 0.91000000001, which have brings trouble to display.
  20133. // TODO: consider how to treat null/undefined/NaN when display?
  20134. /**
  20135. * @param {module:echarts/data/List} data
  20136. * @param {number} dataIndex
  20137. * @param {string|number} [dim] dimName or dimIndex
  20138. * @return {Array.<number>|string|number} can be null/undefined.
  20139. */
  20140. function retrieveRawValue(data, dataIndex, dim) {
  20141. if (!data) {
  20142. return;
  20143. }
  20144. // Consider data may be not persistent.
  20145. var dataItem = data.getRawDataItem(dataIndex);
  20146. if (dataItem == null) {
  20147. return;
  20148. }
  20149. var sourceFormat = data.getProvider().getSource().sourceFormat;
  20150. var dimName;
  20151. var dimIndex;
  20152. var dimInfo = data.getDimensionInfo(dim);
  20153. if (dimInfo) {
  20154. dimName = dimInfo.name;
  20155. dimIndex = dimInfo.index;
  20156. }
  20157. return rawValueGetters[sourceFormat](dataItem, dataIndex, dimIndex, dimName);
  20158. }
  20159. /**
  20160. * Compatible with some cases (in pie, map) like:
  20161. * data: [{name: 'xx', value: 5, selected: true}, ...]
  20162. * where only sourceFormat is 'original' and 'objectRows' supported.
  20163. *
  20164. * ??? TODO
  20165. * Supported detail options in data item when using 'arrayRows'.
  20166. *
  20167. * @param {module:echarts/data/List} data
  20168. * @param {number} dataIndex
  20169. * @param {string} attr like 'selected'
  20170. */
  20171. function retrieveRawAttr(data, dataIndex, attr) {
  20172. if (!data) {
  20173. return;
  20174. }
  20175. var sourceFormat = data.getProvider().getSource().sourceFormat;
  20176. if (sourceFormat !== SOURCE_FORMAT_ORIGINAL
  20177. && sourceFormat !== SOURCE_FORMAT_OBJECT_ROWS
  20178. ) {
  20179. return;
  20180. }
  20181. var dataItem = data.getRawDataItem(dataIndex);
  20182. if (sourceFormat === SOURCE_FORMAT_ORIGINAL && !isObject$1(dataItem)) {
  20183. dataItem = null;
  20184. }
  20185. if (dataItem) {
  20186. return dataItem[attr];
  20187. }
  20188. }
  20189. /*
  20190. * Licensed to the Apache Software Foundation (ASF) under one
  20191. * or more contributor license agreements. See the NOTICE file
  20192. * distributed with this work for additional information
  20193. * regarding copyright ownership. The ASF licenses this file
  20194. * to you under the Apache License, Version 2.0 (the
  20195. * "License"); you may not use this file except in compliance
  20196. * with the License. You may obtain a copy of the License at
  20197. *
  20198. * http://www.apache.org/licenses/LICENSE-2.0
  20199. *
  20200. * Unless required by applicable law or agreed to in writing,
  20201. * software distributed under the License is distributed on an
  20202. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20203. * KIND, either express or implied. See the License for the
  20204. * specific language governing permissions and limitations
  20205. * under the License.
  20206. */
  20207. var DIMENSION_LABEL_REG = /\{@(.+?)\}/g;
  20208. // PENDING A little ugly
  20209. var dataFormatMixin = {
  20210. /**
  20211. * Get params for formatter
  20212. * @param {number} dataIndex
  20213. * @param {string} [dataType]
  20214. * @return {Object}
  20215. */
  20216. getDataParams: function (dataIndex, dataType) {
  20217. var data = this.getData(dataType);
  20218. var rawValue = this.getRawValue(dataIndex, dataType);
  20219. var rawDataIndex = data.getRawIndex(dataIndex);
  20220. var name = data.getName(dataIndex);
  20221. var itemOpt = data.getRawDataItem(dataIndex);
  20222. var color = data.getItemVisual(dataIndex, 'color');
  20223. var tooltipModel = this.ecModel.getComponent('tooltip');
  20224. var renderModeOption = tooltipModel && tooltipModel.get('renderMode');
  20225. var renderMode = getTooltipRenderMode(renderModeOption);
  20226. var mainType = this.mainType;
  20227. var isSeries = mainType === 'series';
  20228. return {
  20229. componentType: mainType,
  20230. componentSubType: this.subType,
  20231. componentIndex: this.componentIndex,
  20232. seriesType: isSeries ? this.subType : null,
  20233. seriesIndex: this.seriesIndex,
  20234. seriesId: isSeries ? this.id : null,
  20235. seriesName: isSeries ? this.name : null,
  20236. name: name,
  20237. dataIndex: rawDataIndex,
  20238. data: itemOpt,
  20239. dataType: dataType,
  20240. value: rawValue,
  20241. color: color,
  20242. marker: getTooltipMarker({
  20243. color: color,
  20244. renderMode: renderMode
  20245. }),
  20246. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  20247. $vars: ['seriesName', 'name', 'value']
  20248. };
  20249. },
  20250. /**
  20251. * Format label
  20252. * @param {number} dataIndex
  20253. * @param {string} [status='normal'] 'normal' or 'emphasis'
  20254. * @param {string} [dataType]
  20255. * @param {number} [dimIndex]
  20256. * @param {string} [labelProp='label']
  20257. * @return {string} If not formatter, return null/undefined
  20258. */
  20259. getFormattedLabel: function (dataIndex, status, dataType, dimIndex, labelProp) {
  20260. status = status || 'normal';
  20261. var data = this.getData(dataType);
  20262. var itemModel = data.getItemModel(dataIndex);
  20263. var params = this.getDataParams(dataIndex, dataType);
  20264. if (dimIndex != null && (params.value instanceof Array)) {
  20265. params.value = params.value[dimIndex];
  20266. }
  20267. var formatter = itemModel.get(
  20268. status === 'normal'
  20269. ? [labelProp || 'label', 'formatter']
  20270. : [status, labelProp || 'label', 'formatter']
  20271. );
  20272. if (typeof formatter === 'function') {
  20273. params.status = status;
  20274. return formatter(params);
  20275. }
  20276. else if (typeof formatter === 'string') {
  20277. var str = formatTpl(formatter, params);
  20278. // Support 'aaa{@[3]}bbb{@product}ccc'.
  20279. // Do not support '}' in dim name util have to.
  20280. return str.replace(DIMENSION_LABEL_REG, function (origin, dim) {
  20281. var len = dim.length;
  20282. if (dim.charAt(0) === '[' && dim.charAt(len - 1) === ']') {
  20283. dim = +dim.slice(1, len - 1); // Also: '[]' => 0
  20284. }
  20285. return retrieveRawValue(data, dataIndex, dim);
  20286. });
  20287. }
  20288. },
  20289. /**
  20290. * Get raw value in option
  20291. * @param {number} idx
  20292. * @param {string} [dataType]
  20293. * @return {Array|number|string}
  20294. */
  20295. getRawValue: function (idx, dataType) {
  20296. return retrieveRawValue(this.getData(dataType), idx);
  20297. },
  20298. /**
  20299. * Should be implemented.
  20300. * @param {number} dataIndex
  20301. * @param {boolean} [multipleSeries=false]
  20302. * @param {number} [dataType]
  20303. * @return {string} tooltip string
  20304. */
  20305. formatTooltip: function () {
  20306. // Empty function
  20307. }
  20308. };
  20309. /*
  20310. * Licensed to the Apache Software Foundation (ASF) under one
  20311. * or more contributor license agreements. See the NOTICE file
  20312. * distributed with this work for additional information
  20313. * regarding copyright ownership. The ASF licenses this file
  20314. * to you under the Apache License, Version 2.0 (the
  20315. * "License"); you may not use this file except in compliance
  20316. * with the License. You may obtain a copy of the License at
  20317. *
  20318. * http://www.apache.org/licenses/LICENSE-2.0
  20319. *
  20320. * Unless required by applicable law or agreed to in writing,
  20321. * software distributed under the License is distributed on an
  20322. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20323. * KIND, either express or implied. See the License for the
  20324. * specific language governing permissions and limitations
  20325. * under the License.
  20326. */
  20327. /**
  20328. * @param {Object} define
  20329. * @return See the return of `createTask`.
  20330. */
  20331. function createTask(define) {
  20332. return new Task(define);
  20333. }
  20334. /**
  20335. * @constructor
  20336. * @param {Object} define
  20337. * @param {Function} define.reset Custom reset
  20338. * @param {Function} [define.plan] Returns 'reset' indicate reset immediately.
  20339. * @param {Function} [define.count] count is used to determin data task.
  20340. * @param {Function} [define.onDirty] count is used to determin data task.
  20341. */
  20342. function Task(define) {
  20343. define = define || {};
  20344. this._reset = define.reset;
  20345. this._plan = define.plan;
  20346. this._count = define.count;
  20347. this._onDirty = define.onDirty;
  20348. this._dirty = true;
  20349. // Context must be specified implicitly, to
  20350. // avoid miss update context when model changed.
  20351. this.context;
  20352. }
  20353. var taskProto = Task.prototype;
  20354. /**
  20355. * @param {Object} performArgs
  20356. * @param {number} [performArgs.step] Specified step.
  20357. * @param {number} [performArgs.skip] Skip customer perform call.
  20358. * @param {number} [performArgs.modBy] Sampling window size.
  20359. * @param {number} [performArgs.modDataCount] Sampling count.
  20360. */
  20361. taskProto.perform = function (performArgs) {
  20362. var upTask = this._upstream;
  20363. var skip = performArgs && performArgs.skip;
  20364. // TODO some refactor.
  20365. // Pull data. Must pull data each time, because context.data
  20366. // may be updated by Series.setData.
  20367. if (this._dirty && upTask) {
  20368. var context = this.context;
  20369. context.data = context.outputData = upTask.context.outputData;
  20370. }
  20371. if (this.__pipeline) {
  20372. this.__pipeline.currentTask = this;
  20373. }
  20374. var planResult;
  20375. if (this._plan && !skip) {
  20376. planResult = this._plan(this.context);
  20377. }
  20378. // Support sharding by mod, which changes the render sequence and makes the rendered graphic
  20379. // elements uniformed distributed when progress, especially when moving or zooming.
  20380. var lastModBy = normalizeModBy(this._modBy);
  20381. var lastModDataCount = this._modDataCount || 0;
  20382. var modBy = normalizeModBy(performArgs && performArgs.modBy);
  20383. var modDataCount = performArgs && performArgs.modDataCount || 0;
  20384. if (lastModBy !== modBy || lastModDataCount !== modDataCount) {
  20385. planResult = 'reset';
  20386. }
  20387. function normalizeModBy(val) {
  20388. !(val >= 1) && (val = 1); // jshint ignore:line
  20389. return val;
  20390. }
  20391. var forceFirstProgress;
  20392. if (this._dirty || planResult === 'reset') {
  20393. this._dirty = false;
  20394. forceFirstProgress = reset(this, skip);
  20395. }
  20396. this._modBy = modBy;
  20397. this._modDataCount = modDataCount;
  20398. var step = performArgs && performArgs.step;
  20399. if (upTask) {
  20400. if (__DEV__) {
  20401. assert$1(upTask._outputDueEnd != null);
  20402. }
  20403. this._dueEnd = upTask._outputDueEnd;
  20404. }
  20405. // DataTask or overallTask
  20406. else {
  20407. if (__DEV__) {
  20408. assert$1(!this._progress || this._count);
  20409. }
  20410. this._dueEnd = this._count ? this._count(this.context) : Infinity;
  20411. }
  20412. // Note: Stubs, that its host overall task let it has progress, has progress.
  20413. // If no progress, pass index from upstream to downstream each time plan called.
  20414. if (this._progress) {
  20415. var start = this._dueIndex;
  20416. var end = Math.min(
  20417. step != null ? this._dueIndex + step : Infinity,
  20418. this._dueEnd
  20419. );
  20420. if (!skip && (forceFirstProgress || start < end)) {
  20421. var progress = this._progress;
  20422. if (isArray(progress)) {
  20423. for (var i = 0; i < progress.length; i++) {
  20424. doProgress(this, progress[i], start, end, modBy, modDataCount);
  20425. }
  20426. }
  20427. else {
  20428. doProgress(this, progress, start, end, modBy, modDataCount);
  20429. }
  20430. }
  20431. this._dueIndex = end;
  20432. // If no `outputDueEnd`, assume that output data and
  20433. // input data is the same, so use `dueIndex` as `outputDueEnd`.
  20434. var outputDueEnd = this._settedOutputEnd != null
  20435. ? this._settedOutputEnd : end;
  20436. if (__DEV__) {
  20437. // ??? Can not rollback.
  20438. assert$1(outputDueEnd >= this._outputDueEnd);
  20439. }
  20440. this._outputDueEnd = outputDueEnd;
  20441. }
  20442. else {
  20443. // (1) Some overall task has no progress.
  20444. // (2) Stubs, that its host overall task do not let it has progress, has no progress.
  20445. // This should always be performed so it can be passed to downstream.
  20446. this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null
  20447. ? this._settedOutputEnd : this._dueEnd;
  20448. }
  20449. return this.unfinished();
  20450. };
  20451. var iterator = (function () {
  20452. var end;
  20453. var current;
  20454. var modBy;
  20455. var modDataCount;
  20456. var winCount;
  20457. var it = {
  20458. reset: function (s, e, sStep, sCount) {
  20459. current = s;
  20460. end = e;
  20461. modBy = sStep;
  20462. modDataCount = sCount;
  20463. winCount = Math.ceil(modDataCount / modBy);
  20464. it.next = (modBy > 1 && modDataCount > 0) ? modNext : sequentialNext;
  20465. }
  20466. };
  20467. return it;
  20468. function sequentialNext() {
  20469. return current < end ? current++ : null;
  20470. }
  20471. function modNext() {
  20472. var dataIndex = (current % winCount) * modBy + Math.ceil(current / winCount);
  20473. var result = current >= end
  20474. ? null
  20475. : dataIndex < modDataCount
  20476. ? dataIndex
  20477. // If modDataCount is smaller than data.count() (consider `appendData` case),
  20478. // Use normal linear rendering mode.
  20479. : current;
  20480. current++;
  20481. return result;
  20482. }
  20483. })();
  20484. taskProto.dirty = function () {
  20485. this._dirty = true;
  20486. this._onDirty && this._onDirty(this.context);
  20487. };
  20488. function doProgress(taskIns, progress, start, end, modBy, modDataCount) {
  20489. iterator.reset(start, end, modBy, modDataCount);
  20490. taskIns._callingProgress = progress;
  20491. taskIns._callingProgress({
  20492. start: start, end: end, count: end - start, next: iterator.next
  20493. }, taskIns.context);
  20494. }
  20495. function reset(taskIns, skip) {
  20496. taskIns._dueIndex = taskIns._outputDueEnd = taskIns._dueEnd = 0;
  20497. taskIns._settedOutputEnd = null;
  20498. var progress;
  20499. var forceFirstProgress;
  20500. if (!skip && taskIns._reset) {
  20501. progress = taskIns._reset(taskIns.context);
  20502. if (progress && progress.progress) {
  20503. forceFirstProgress = progress.forceFirstProgress;
  20504. progress = progress.progress;
  20505. }
  20506. // To simplify no progress checking, array must has item.
  20507. if (isArray(progress) && !progress.length) {
  20508. progress = null;
  20509. }
  20510. }
  20511. taskIns._progress = progress;
  20512. taskIns._modBy = taskIns._modDataCount = null;
  20513. var downstream = taskIns._downstream;
  20514. downstream && downstream.dirty();
  20515. return forceFirstProgress;
  20516. }
  20517. /**
  20518. * @return {boolean}
  20519. */
  20520. taskProto.unfinished = function () {
  20521. return this._progress && this._dueIndex < this._dueEnd;
  20522. };
  20523. /**
  20524. * @param {Object} downTask The downstream task.
  20525. * @return {Object} The downstream task.
  20526. */
  20527. taskProto.pipe = function (downTask) {
  20528. if (__DEV__) {
  20529. assert$1(downTask && !downTask._disposed && downTask !== this);
  20530. }
  20531. // If already downstream, do not dirty downTask.
  20532. if (this._downstream !== downTask || this._dirty) {
  20533. this._downstream = downTask;
  20534. downTask._upstream = this;
  20535. downTask.dirty();
  20536. }
  20537. };
  20538. taskProto.dispose = function () {
  20539. if (this._disposed) {
  20540. return;
  20541. }
  20542. this._upstream && (this._upstream._downstream = null);
  20543. this._downstream && (this._downstream._upstream = null);
  20544. this._dirty = false;
  20545. this._disposed = true;
  20546. };
  20547. taskProto.getUpstream = function () {
  20548. return this._upstream;
  20549. };
  20550. taskProto.getDownstream = function () {
  20551. return this._downstream;
  20552. };
  20553. taskProto.setOutputEnd = function (end) {
  20554. // This only happend in dataTask, dataZoom, map, currently.
  20555. // where dataZoom do not set end each time, but only set
  20556. // when reset. So we should record the setted end, in case
  20557. // that the stub of dataZoom perform again and earse the
  20558. // setted end by upstream.
  20559. this._outputDueEnd = this._settedOutputEnd = end;
  20560. };
  20561. ///////////////////////////////////////////////////////////
  20562. // For stream debug (Should be commented out after used!)
  20563. // Usage: printTask(this, 'begin');
  20564. // Usage: printTask(this, null, {someExtraProp});
  20565. // function printTask(task, prefix, extra) {
  20566. // window.ecTaskUID == null && (window.ecTaskUID = 0);
  20567. // task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);
  20568. // task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);
  20569. // var props = [];
  20570. // if (task.__pipeline) {
  20571. // var val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;
  20572. // props.push({text: 'idx', value: val});
  20573. // } else {
  20574. // var stubCount = 0;
  20575. // task.agentStubMap.each(() => stubCount++);
  20576. // props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});
  20577. // }
  20578. // props.push({text: 'uid', value: task.uidDebug});
  20579. // if (task.__pipeline) {
  20580. // props.push({text: 'pid', value: task.__pipeline.id});
  20581. // task.agent && props.push(
  20582. // {text: 'stubFor', value: task.agent.uidDebug}
  20583. // );
  20584. // }
  20585. // props.push(
  20586. // {text: 'dirty', value: task._dirty},
  20587. // {text: 'dueIndex', value: task._dueIndex},
  20588. // {text: 'dueEnd', value: task._dueEnd},
  20589. // {text: 'outputDueEnd', value: task._outputDueEnd}
  20590. // );
  20591. // if (extra) {
  20592. // Object.keys(extra).forEach(key => {
  20593. // props.push({text: key, value: extra[key]});
  20594. // });
  20595. // }
  20596. // var args = ['color: blue'];
  20597. // var msg = `%c[${prefix || 'T'}] %c` + props.map(item => (
  20598. // args.push('color: black', 'color: red'),
  20599. // `${item.text}: %c${item.value}`
  20600. // )).join('%c, ');
  20601. // console.log.apply(console, [msg].concat(args));
  20602. // // console.log(this);
  20603. // }
  20604. /*
  20605. * Licensed to the Apache Software Foundation (ASF) under one
  20606. * or more contributor license agreements. See the NOTICE file
  20607. * distributed with this work for additional information
  20608. * regarding copyright ownership. The ASF licenses this file
  20609. * to you under the Apache License, Version 2.0 (the
  20610. * "License"); you may not use this file except in compliance
  20611. * with the License. You may obtain a copy of the License at
  20612. *
  20613. * http://www.apache.org/licenses/LICENSE-2.0
  20614. *
  20615. * Unless required by applicable law or agreed to in writing,
  20616. * software distributed under the License is distributed on an
  20617. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20618. * KIND, either express or implied. See the License for the
  20619. * specific language governing permissions and limitations
  20620. * under the License.
  20621. */
  20622. var inner$4 = makeInner();
  20623. var SeriesModel = ComponentModel.extend({
  20624. type: 'series.__base__',
  20625. /**
  20626. * @readOnly
  20627. */
  20628. seriesIndex: 0,
  20629. // coodinateSystem will be injected in the echarts/CoordinateSystem
  20630. coordinateSystem: null,
  20631. /**
  20632. * @type {Object}
  20633. * @protected
  20634. */
  20635. defaultOption: null,
  20636. /**
  20637. * Data provided for legend
  20638. * @type {Function}
  20639. */
  20640. // PENDING
  20641. legendDataProvider: null,
  20642. /**
  20643. * Access path of color for visual
  20644. */
  20645. visualColorAccessPath: 'itemStyle.color',
  20646. /**
  20647. * Support merge layout params.
  20648. * Only support 'box' now (left/right/top/bottom/width/height).
  20649. * @type {string|Object} Object can be {ignoreSize: true}
  20650. * @readOnly
  20651. */
  20652. layoutMode: null,
  20653. init: function (option, parentModel, ecModel, extraOpt) {
  20654. /**
  20655. * @type {number}
  20656. * @readOnly
  20657. */
  20658. this.seriesIndex = this.componentIndex;
  20659. this.dataTask = createTask({
  20660. count: dataTaskCount,
  20661. reset: dataTaskReset
  20662. });
  20663. this.dataTask.context = {model: this};
  20664. this.mergeDefaultAndTheme(option, ecModel);
  20665. prepareSource(this);
  20666. var data = this.getInitialData(option, ecModel);
  20667. wrapData(data, this);
  20668. this.dataTask.context.data = data;
  20669. if (__DEV__) {
  20670. assert$1(data, 'getInitialData returned invalid data.');
  20671. }
  20672. /**
  20673. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  20674. * @private
  20675. */
  20676. inner$4(this).dataBeforeProcessed = data;
  20677. // If we reverse the order (make data firstly, and then make
  20678. // dataBeforeProcessed by cloneShallow), cloneShallow will
  20679. // cause data.graph.data !== data when using
  20680. // module:echarts/data/Graph or module:echarts/data/Tree.
  20681. // See module:echarts/data/helper/linkList
  20682. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  20683. // init or merge stage, because the data can be restored. So we do not `restoreData`
  20684. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  20685. // Call `seriesModel.getRawData()` instead.
  20686. // this.restoreData();
  20687. autoSeriesName(this);
  20688. },
  20689. /**
  20690. * Util for merge default and theme to option
  20691. * @param {Object} option
  20692. * @param {module:echarts/model/Global} ecModel
  20693. */
  20694. mergeDefaultAndTheme: function (option, ecModel) {
  20695. var layoutMode = this.layoutMode;
  20696. var inputPositionParams = layoutMode
  20697. ? getLayoutParams(option) : {};
  20698. // Backward compat: using subType on theme.
  20699. // But if name duplicate between series subType
  20700. // (for example: parallel) add component mainType,
  20701. // add suffix 'Series'.
  20702. var themeSubType = this.subType;
  20703. if (ComponentModel.hasClass(themeSubType)) {
  20704. themeSubType += 'Series';
  20705. }
  20706. merge(
  20707. option,
  20708. ecModel.getTheme().get(this.subType)
  20709. );
  20710. merge(option, this.getDefaultOption());
  20711. // Default label emphasis `show`
  20712. defaultEmphasis(option, 'label', ['show']);
  20713. this.fillDataTextStyle(option.data);
  20714. if (layoutMode) {
  20715. mergeLayoutParam(option, inputPositionParams, layoutMode);
  20716. }
  20717. },
  20718. mergeOption: function (newSeriesOption, ecModel) {
  20719. // this.settingTask.dirty();
  20720. newSeriesOption = merge(this.option, newSeriesOption, true);
  20721. this.fillDataTextStyle(newSeriesOption.data);
  20722. var layoutMode = this.layoutMode;
  20723. if (layoutMode) {
  20724. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  20725. }
  20726. prepareSource(this);
  20727. var data = this.getInitialData(newSeriesOption, ecModel);
  20728. wrapData(data, this);
  20729. this.dataTask.dirty();
  20730. this.dataTask.context.data = data;
  20731. inner$4(this).dataBeforeProcessed = data;
  20732. autoSeriesName(this);
  20733. },
  20734. fillDataTextStyle: function (data) {
  20735. // Default data label emphasis `show`
  20736. // FIXME Tree structure data ?
  20737. // FIXME Performance ?
  20738. if (data && !isTypedArray(data)) {
  20739. var props = ['show'];
  20740. for (var i = 0; i < data.length; i++) {
  20741. if (data[i] && data[i].label) {
  20742. defaultEmphasis(data[i], 'label', props);
  20743. }
  20744. }
  20745. }
  20746. },
  20747. /**
  20748. * Init a data structure from data related option in series
  20749. * Must be overwritten
  20750. */
  20751. getInitialData: function () {},
  20752. /**
  20753. * Append data to list
  20754. * @param {Object} params
  20755. * @param {Array|TypedArray} params.data
  20756. */
  20757. appendData: function (params) {
  20758. // FIXME ???
  20759. // (1) If data from dataset, forbidden append.
  20760. // (2) support append data of dataset.
  20761. var data = this.getRawData();
  20762. data.appendData(params.data);
  20763. },
  20764. /**
  20765. * Consider some method like `filter`, `map` need make new data,
  20766. * We should make sure that `seriesModel.getData()` get correct
  20767. * data in the stream procedure. So we fetch data from upstream
  20768. * each time `task.perform` called.
  20769. * @param {string} [dataType]
  20770. * @return {module:echarts/data/List}
  20771. */
  20772. getData: function (dataType) {
  20773. var task = getCurrentTask(this);
  20774. if (task) {
  20775. var data = task.context.data;
  20776. return dataType == null ? data : data.getLinkedData(dataType);
  20777. }
  20778. else {
  20779. // When series is not alive (that may happen when click toolbox
  20780. // restore or setOption with not merge mode), series data may
  20781. // be still need to judge animation or something when graphic
  20782. // elements want to know whether fade out.
  20783. return inner$4(this).data;
  20784. }
  20785. },
  20786. /**
  20787. * @param {module:echarts/data/List} data
  20788. */
  20789. setData: function (data) {
  20790. var task = getCurrentTask(this);
  20791. if (task) {
  20792. var context = task.context;
  20793. // Consider case: filter, data sample.
  20794. if (context.data !== data && task.modifyOutputEnd) {
  20795. task.setOutputEnd(data.count());
  20796. }
  20797. context.outputData = data;
  20798. // Caution: setData should update context.data,
  20799. // Because getData may be called multiply in a
  20800. // single stage and expect to get the data just
  20801. // set. (For example, AxisProxy, x y both call
  20802. // getData and setDate sequentially).
  20803. // So the context.data should be fetched from
  20804. // upstream each time when a stage starts to be
  20805. // performed.
  20806. if (task !== this.dataTask) {
  20807. context.data = data;
  20808. }
  20809. }
  20810. inner$4(this).data = data;
  20811. },
  20812. /**
  20813. * @see {module:echarts/data/helper/sourceHelper#getSource}
  20814. * @return {module:echarts/data/Source} source
  20815. */
  20816. getSource: function () {
  20817. return getSource(this);
  20818. },
  20819. /**
  20820. * Get data before processed
  20821. * @return {module:echarts/data/List}
  20822. */
  20823. getRawData: function () {
  20824. return inner$4(this).dataBeforeProcessed;
  20825. },
  20826. /**
  20827. * Get base axis if has coordinate system and has axis.
  20828. * By default use coordSys.getBaseAxis();
  20829. * Can be overrided for some chart.
  20830. * @return {type} description
  20831. */
  20832. getBaseAxis: function () {
  20833. var coordSys = this.coordinateSystem;
  20834. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  20835. },
  20836. // FIXME
  20837. /**
  20838. * Default tooltip formatter
  20839. *
  20840. * @param {number} dataIndex
  20841. * @param {boolean} [multipleSeries=false]
  20842. * @param {number} [dataType]
  20843. * @param {string} [renderMode='html'] valid values: 'html' and 'richText'.
  20844. * 'html' is used for rendering tooltip in extra DOM form, and the result
  20845. * string is used as DOM HTML content.
  20846. * 'richText' is used for rendering tooltip in rich text form, for those where
  20847. * DOM operation is not supported.
  20848. * @return {Object} formatted tooltip with `html` and `markers`
  20849. */
  20850. formatTooltip: function (dataIndex, multipleSeries, dataType, renderMode) {
  20851. var series = this;
  20852. renderMode = renderMode || 'html';
  20853. var newLine = renderMode === 'html' ? '<br/>' : '\n';
  20854. var isRichText = renderMode === 'richText';
  20855. var markers = {};
  20856. var markerId = 0;
  20857. function formatArrayValue(value) {
  20858. // ??? TODO refactor these logic.
  20859. // check: category-no-encode-has-axis-data in dataset.html
  20860. var vertially = reduce(value, function (vertially, val, idx) {
  20861. var dimItem = data.getDimensionInfo(idx);
  20862. return vertially |= dimItem && dimItem.tooltip !== false && dimItem.displayName != null;
  20863. }, 0);
  20864. var result = [];
  20865. tooltipDims.length
  20866. ? each$1(tooltipDims, function (dim) {
  20867. setEachItem(retrieveRawValue(data, dataIndex, dim), dim);
  20868. })
  20869. // By default, all dims is used on tooltip.
  20870. : each$1(value, setEachItem);
  20871. function setEachItem(val, dim) {
  20872. var dimInfo = data.getDimensionInfo(dim);
  20873. // If `dimInfo.tooltip` is not set, show tooltip.
  20874. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  20875. return;
  20876. }
  20877. var dimType = dimInfo.type;
  20878. var markName = 'sub' + series.seriesIndex + 'at' + markerId;
  20879. var dimHead = getTooltipMarker({
  20880. color: color,
  20881. type: 'subItem',
  20882. renderMode: renderMode,
  20883. markerId: markName
  20884. });
  20885. var dimHeadStr = typeof dimHead === 'string' ? dimHead : dimHead.content;
  20886. var valStr = (vertially
  20887. ? dimHeadStr + encodeHTML(dimInfo.displayName || '-') + ': '
  20888. : ''
  20889. )
  20890. // FIXME should not format time for raw data?
  20891. + encodeHTML(dimType === 'ordinal'
  20892. ? val + ''
  20893. : dimType === 'time'
  20894. ? (multipleSeries ? '' : formatTime('yyyy/MM/dd hh:mm:ss', val))
  20895. : addCommas(val)
  20896. );
  20897. valStr && result.push(valStr);
  20898. if (isRichText) {
  20899. markers[markName] = color;
  20900. ++markerId;
  20901. }
  20902. }
  20903. var newLine = vertially ? (isRichText ? '\n' : '<br/>') : '';
  20904. var content = newLine + result.join(newLine || ', ');
  20905. return {
  20906. renderMode: renderMode,
  20907. content: content,
  20908. style: markers
  20909. };
  20910. }
  20911. function formatSingleValue(val) {
  20912. // return encodeHTML(addCommas(val));
  20913. return {
  20914. renderMode: renderMode,
  20915. content: encodeHTML(addCommas(val)),
  20916. style: markers
  20917. };
  20918. }
  20919. var data = this.getData();
  20920. var tooltipDims = data.mapDimension('defaultedTooltip', true);
  20921. var tooltipDimLen = tooltipDims.length;
  20922. var value = this.getRawValue(dataIndex);
  20923. var isValueArr = isArray(value);
  20924. var color = data.getItemVisual(dataIndex, 'color');
  20925. if (isObject$1(color) && color.colorStops) {
  20926. color = (color.colorStops[0] || {}).color;
  20927. }
  20928. color = color || 'transparent';
  20929. // Complicated rule for pretty tooltip.
  20930. var formattedValue = (tooltipDimLen > 1 || (isValueArr && !tooltipDimLen))
  20931. ? formatArrayValue(value)
  20932. : tooltipDimLen
  20933. ? formatSingleValue(retrieveRawValue(data, dataIndex, tooltipDims[0]))
  20934. : formatSingleValue(isValueArr ? value[0] : value);
  20935. var content = formattedValue.content;
  20936. var markName = series.seriesIndex + 'at' + markerId;
  20937. var colorEl = getTooltipMarker({
  20938. color: color,
  20939. type: 'item',
  20940. renderMode: renderMode,
  20941. markerId: markName
  20942. });
  20943. markers[markName] = color;
  20944. ++markerId;
  20945. var name = data.getName(dataIndex);
  20946. var seriesName = this.name;
  20947. if (!isNameSpecified(this)) {
  20948. seriesName = '';
  20949. }
  20950. seriesName = seriesName
  20951. ? encodeHTML(seriesName) + (!multipleSeries ? newLine : ': ')
  20952. : '';
  20953. var colorStr = typeof colorEl === 'string' ? colorEl : colorEl.content;
  20954. var html = !multipleSeries
  20955. ? seriesName + colorStr
  20956. + (name
  20957. ? encodeHTML(name) + ': ' + content
  20958. : content
  20959. )
  20960. : colorStr + seriesName + content;
  20961. return {
  20962. html: html,
  20963. markers: markers
  20964. };
  20965. },
  20966. /**
  20967. * @return {boolean}
  20968. */
  20969. isAnimationEnabled: function () {
  20970. if (env$1.node) {
  20971. return false;
  20972. }
  20973. var animationEnabled = this.getShallow('animation');
  20974. if (animationEnabled) {
  20975. if (this.getData().count() > this.getShallow('animationThreshold')) {
  20976. animationEnabled = false;
  20977. }
  20978. }
  20979. return animationEnabled;
  20980. },
  20981. restoreData: function () {
  20982. this.dataTask.dirty();
  20983. },
  20984. getColorFromPalette: function (name, scope, requestColorNum) {
  20985. var ecModel = this.ecModel;
  20986. // PENDING
  20987. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope, requestColorNum);
  20988. if (!color) {
  20989. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  20990. }
  20991. return color;
  20992. },
  20993. /**
  20994. * Use `data.mapDimension(coordDim, true)` instead.
  20995. * @deprecated
  20996. */
  20997. coordDimToDataDim: function (coordDim) {
  20998. return this.getRawData().mapDimension(coordDim, true);
  20999. },
  21000. /**
  21001. * Get progressive rendering count each step
  21002. * @return {number}
  21003. */
  21004. getProgressive: function () {
  21005. return this.get('progressive');
  21006. },
  21007. /**
  21008. * Get progressive rendering count each step
  21009. * @return {number}
  21010. */
  21011. getProgressiveThreshold: function () {
  21012. return this.get('progressiveThreshold');
  21013. },
  21014. /**
  21015. * Get data indices for show tooltip content. See tooltip.
  21016. * @abstract
  21017. * @param {Array.<string>|string} dim
  21018. * @param {Array.<number>} value
  21019. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  21020. * @return {Object} {dataIndices, nestestValue}.
  21021. */
  21022. getAxisTooltipData: null,
  21023. /**
  21024. * See tooltip.
  21025. * @abstract
  21026. * @param {number} dataIndex
  21027. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  21028. */
  21029. getTooltipPosition: null,
  21030. /**
  21031. * @see {module:echarts/stream/Scheduler}
  21032. */
  21033. pipeTask: null,
  21034. /**
  21035. * Convinient for override in extended class.
  21036. * @protected
  21037. * @type {Function}
  21038. */
  21039. preventIncremental: null,
  21040. /**
  21041. * @public
  21042. * @readOnly
  21043. * @type {Object}
  21044. */
  21045. pipelineContext: null
  21046. });
  21047. mixin(SeriesModel, dataFormatMixin);
  21048. mixin(SeriesModel, colorPaletteMixin);
  21049. /**
  21050. * MUST be called after `prepareSource` called
  21051. * Here we need to make auto series, especially for auto legend. But we
  21052. * do not modify series.name in option to avoid side effects.
  21053. */
  21054. function autoSeriesName(seriesModel) {
  21055. // User specified name has higher priority, otherwise it may cause
  21056. // series can not be queried unexpectedly.
  21057. var name = seriesModel.name;
  21058. if (!isNameSpecified(seriesModel)) {
  21059. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  21060. }
  21061. }
  21062. function getSeriesAutoName(seriesModel) {
  21063. var data = seriesModel.getRawData();
  21064. var dataDims = data.mapDimension('seriesName', true);
  21065. var nameArr = [];
  21066. each$1(dataDims, function (dataDim) {
  21067. var dimInfo = data.getDimensionInfo(dataDim);
  21068. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  21069. });
  21070. return nameArr.join(' ');
  21071. }
  21072. function dataTaskCount(context) {
  21073. return context.model.getRawData().count();
  21074. }
  21075. function dataTaskReset(context) {
  21076. var seriesModel = context.model;
  21077. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  21078. return dataTaskProgress;
  21079. }
  21080. function dataTaskProgress(param, context) {
  21081. // Avoid repead cloneShallow when data just created in reset.
  21082. if (param.end > context.outputData.count()) {
  21083. context.model.getRawData().cloneShallow(context.outputData);
  21084. }
  21085. }
  21086. // TODO refactor
  21087. function wrapData(data, seriesModel) {
  21088. each$1(data.CHANGABLE_METHODS, function (methodName) {
  21089. data.wrapMethod(methodName, curry(onDataSelfChange, seriesModel));
  21090. });
  21091. }
  21092. function onDataSelfChange(seriesModel) {
  21093. var task = getCurrentTask(seriesModel);
  21094. if (task) {
  21095. // Consider case: filter, selectRange
  21096. task.setOutputEnd(this.count());
  21097. }
  21098. }
  21099. function getCurrentTask(seriesModel) {
  21100. var scheduler = (seriesModel.ecModel || {}).scheduler;
  21101. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  21102. if (pipeline) {
  21103. // When pipline finished, the currrentTask keep the last
  21104. // task (renderTask).
  21105. var task = pipeline.currentTask;
  21106. if (task) {
  21107. var agentStubMap = task.agentStubMap;
  21108. if (agentStubMap) {
  21109. task = agentStubMap.get(seriesModel.uid);
  21110. }
  21111. }
  21112. return task;
  21113. }
  21114. }
  21115. /*
  21116. * Licensed to the Apache Software Foundation (ASF) under one
  21117. * or more contributor license agreements. See the NOTICE file
  21118. * distributed with this work for additional information
  21119. * regarding copyright ownership. The ASF licenses this file
  21120. * to you under the Apache License, Version 2.0 (the
  21121. * "License"); you may not use this file except in compliance
  21122. * with the License. You may obtain a copy of the License at
  21123. *
  21124. * http://www.apache.org/licenses/LICENSE-2.0
  21125. *
  21126. * Unless required by applicable law or agreed to in writing,
  21127. * software distributed under the License is distributed on an
  21128. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21129. * KIND, either express or implied. See the License for the
  21130. * specific language governing permissions and limitations
  21131. * under the License.
  21132. */
  21133. var Component = function () {
  21134. /**
  21135. * @type {module:zrender/container/Group}
  21136. * @readOnly
  21137. */
  21138. this.group = new Group();
  21139. /**
  21140. * @type {string}
  21141. * @readOnly
  21142. */
  21143. this.uid = getUID('viewComponent');
  21144. };
  21145. Component.prototype = {
  21146. constructor: Component,
  21147. init: function (ecModel, api) {},
  21148. render: function (componentModel, ecModel, api, payload) {},
  21149. dispose: function () {},
  21150. /**
  21151. * @param {string} eventType
  21152. * @param {Object} query
  21153. * @param {module:zrender/Element} targetEl
  21154. * @param {Object} packedEvent
  21155. * @return {boolen} Pass only when return `true`.
  21156. */
  21157. filterForExposedEvent: null
  21158. };
  21159. var componentProto = Component.prototype;
  21160. componentProto.updateView
  21161. = componentProto.updateLayout
  21162. = componentProto.updateVisual
  21163. = function (seriesModel, ecModel, api, payload) {
  21164. // Do nothing;
  21165. };
  21166. // Enable Component.extend.
  21167. enableClassExtend(Component);
  21168. // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  21169. enableClassManagement(Component, {registerWhenExtend: true});
  21170. /*
  21171. * Licensed to the Apache Software Foundation (ASF) under one
  21172. * or more contributor license agreements. See the NOTICE file
  21173. * distributed with this work for additional information
  21174. * regarding copyright ownership. The ASF licenses this file
  21175. * to you under the Apache License, Version 2.0 (the
  21176. * "License"); you may not use this file except in compliance
  21177. * with the License. You may obtain a copy of the License at
  21178. *
  21179. * http://www.apache.org/licenses/LICENSE-2.0
  21180. *
  21181. * Unless required by applicable law or agreed to in writing,
  21182. * software distributed under the License is distributed on an
  21183. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21184. * KIND, either express or implied. See the License for the
  21185. * specific language governing permissions and limitations
  21186. * under the License.
  21187. */
  21188. /**
  21189. * @return {string} If large mode changed, return string 'reset';
  21190. */
  21191. var createRenderPlanner = function () {
  21192. var inner = makeInner();
  21193. return function (seriesModel) {
  21194. var fields = inner(seriesModel);
  21195. var pipelineContext = seriesModel.pipelineContext;
  21196. var originalLarge = fields.large;
  21197. var originalProgressive = fields.progressiveRender;
  21198. var large = fields.large = pipelineContext.large;
  21199. var progressive = fields.progressiveRender = pipelineContext.progressiveRender;
  21200. return !!((originalLarge ^ large) || (originalProgressive ^ progressive)) && 'reset';
  21201. };
  21202. };
  21203. /*
  21204. * Licensed to the Apache Software Foundation (ASF) under one
  21205. * or more contributor license agreements. See the NOTICE file
  21206. * distributed with this work for additional information
  21207. * regarding copyright ownership. The ASF licenses this file
  21208. * to you under the Apache License, Version 2.0 (the
  21209. * "License"); you may not use this file except in compliance
  21210. * with the License. You may obtain a copy of the License at
  21211. *
  21212. * http://www.apache.org/licenses/LICENSE-2.0
  21213. *
  21214. * Unless required by applicable law or agreed to in writing,
  21215. * software distributed under the License is distributed on an
  21216. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21217. * KIND, either express or implied. See the License for the
  21218. * specific language governing permissions and limitations
  21219. * under the License.
  21220. */
  21221. var inner$5 = makeInner();
  21222. var renderPlanner = createRenderPlanner();
  21223. function Chart() {
  21224. /**
  21225. * @type {module:zrender/container/Group}
  21226. * @readOnly
  21227. */
  21228. this.group = new Group();
  21229. /**
  21230. * @type {string}
  21231. * @readOnly
  21232. */
  21233. this.uid = getUID('viewChart');
  21234. this.renderTask = createTask({
  21235. plan: renderTaskPlan,
  21236. reset: renderTaskReset
  21237. });
  21238. this.renderTask.context = {view: this};
  21239. }
  21240. Chart.prototype = {
  21241. type: 'chart',
  21242. /**
  21243. * Init the chart.
  21244. * @param {module:echarts/model/Global} ecModel
  21245. * @param {module:echarts/ExtensionAPI} api
  21246. */
  21247. init: function (ecModel, api) {},
  21248. /**
  21249. * Render the chart.
  21250. * @param {module:echarts/model/Series} seriesModel
  21251. * @param {module:echarts/model/Global} ecModel
  21252. * @param {module:echarts/ExtensionAPI} api
  21253. * @param {Object} payload
  21254. */
  21255. render: function (seriesModel, ecModel, api, payload) {},
  21256. /**
  21257. * Highlight series or specified data item.
  21258. * @param {module:echarts/model/Series} seriesModel
  21259. * @param {module:echarts/model/Global} ecModel
  21260. * @param {module:echarts/ExtensionAPI} api
  21261. * @param {Object} payload
  21262. */
  21263. highlight: function (seriesModel, ecModel, api, payload) {
  21264. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  21265. },
  21266. /**
  21267. * Downplay series or specified data item.
  21268. * @param {module:echarts/model/Series} seriesModel
  21269. * @param {module:echarts/model/Global} ecModel
  21270. * @param {module:echarts/ExtensionAPI} api
  21271. * @param {Object} payload
  21272. */
  21273. downplay: function (seriesModel, ecModel, api, payload) {
  21274. toggleHighlight(seriesModel.getData(), payload, 'normal');
  21275. },
  21276. /**
  21277. * Remove self.
  21278. * @param {module:echarts/model/Global} ecModel
  21279. * @param {module:echarts/ExtensionAPI} api
  21280. */
  21281. remove: function (ecModel, api) {
  21282. this.group.removeAll();
  21283. },
  21284. /**
  21285. * Dispose self.
  21286. * @param {module:echarts/model/Global} ecModel
  21287. * @param {module:echarts/ExtensionAPI} api
  21288. */
  21289. dispose: function () {},
  21290. /**
  21291. * Rendering preparation in progressive mode.
  21292. * @param {module:echarts/model/Series} seriesModel
  21293. * @param {module:echarts/model/Global} ecModel
  21294. * @param {module:echarts/ExtensionAPI} api
  21295. * @param {Object} payload
  21296. */
  21297. incrementalPrepareRender: null,
  21298. /**
  21299. * Render in progressive mode.
  21300. * @param {Object} params See taskParams in `stream/task.js`
  21301. * @param {module:echarts/model/Series} seriesModel
  21302. * @param {module:echarts/model/Global} ecModel
  21303. * @param {module:echarts/ExtensionAPI} api
  21304. * @param {Object} payload
  21305. */
  21306. incrementalRender: null,
  21307. /**
  21308. * Update transform directly.
  21309. * @param {module:echarts/model/Series} seriesModel
  21310. * @param {module:echarts/model/Global} ecModel
  21311. * @param {module:echarts/ExtensionAPI} api
  21312. * @param {Object} payload
  21313. * @return {Object} {update: true}
  21314. */
  21315. updateTransform: null,
  21316. /**
  21317. * The view contains the given point.
  21318. * @interface
  21319. * @param {Array.<number>} point
  21320. * @return {boolean}
  21321. */
  21322. // containPoint: function () {}
  21323. /**
  21324. * @param {string} eventType
  21325. * @param {Object} query
  21326. * @param {module:zrender/Element} targetEl
  21327. * @param {Object} packedEvent
  21328. * @return {boolen} Pass only when return `true`.
  21329. */
  21330. filterForExposedEvent: null
  21331. };
  21332. var chartProto = Chart.prototype;
  21333. chartProto.updateView
  21334. = chartProto.updateLayout
  21335. = chartProto.updateVisual
  21336. = function (seriesModel, ecModel, api, payload) {
  21337. this.render(seriesModel, ecModel, api, payload);
  21338. };
  21339. /**
  21340. * Set state of single element
  21341. * @param {module:zrender/Element} el
  21342. * @param {string} state
  21343. */
  21344. function elSetState(el, state) {
  21345. if (el) {
  21346. el.trigger(state);
  21347. if (el.type === 'group') {
  21348. for (var i = 0; i < el.childCount(); i++) {
  21349. elSetState(el.childAt(i), state);
  21350. }
  21351. }
  21352. }
  21353. }
  21354. /**
  21355. * @param {module:echarts/data/List} data
  21356. * @param {Object} payload
  21357. * @param {string} state 'normal'|'emphasis'
  21358. */
  21359. function toggleHighlight(data, payload, state) {
  21360. var dataIndex = queryDataIndex(data, payload);
  21361. if (dataIndex != null) {
  21362. each$1(normalizeToArray(dataIndex), function (dataIdx) {
  21363. elSetState(data.getItemGraphicEl(dataIdx), state);
  21364. });
  21365. }
  21366. else {
  21367. data.eachItemGraphicEl(function (el) {
  21368. elSetState(el, state);
  21369. });
  21370. }
  21371. }
  21372. // Enable Chart.extend.
  21373. enableClassExtend(Chart, ['dispose']);
  21374. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  21375. enableClassManagement(Chart, {registerWhenExtend: true});
  21376. Chart.markUpdateMethod = function (payload, methodName) {
  21377. inner$5(payload).updateMethod = methodName;
  21378. };
  21379. function renderTaskPlan(context) {
  21380. return renderPlanner(context.model);
  21381. }
  21382. function renderTaskReset(context) {
  21383. var seriesModel = context.model;
  21384. var ecModel = context.ecModel;
  21385. var api = context.api;
  21386. var payload = context.payload;
  21387. // ???! remove updateView updateVisual
  21388. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  21389. var view = context.view;
  21390. var updateMethod = payload && inner$5(payload).updateMethod;
  21391. var methodName = progressiveRender
  21392. ? 'incrementalPrepareRender'
  21393. : (updateMethod && view[updateMethod])
  21394. ? updateMethod
  21395. // `appendData` is also supported when data amount
  21396. // is less than progressive threshold.
  21397. : 'render';
  21398. if (methodName !== 'render') {
  21399. view[methodName](seriesModel, ecModel, api, payload);
  21400. }
  21401. return progressMethodMap[methodName];
  21402. }
  21403. var progressMethodMap = {
  21404. incrementalPrepareRender: {
  21405. progress: function (params, context) {
  21406. context.view.incrementalRender(
  21407. params, context.model, context.ecModel, context.api, context.payload
  21408. );
  21409. }
  21410. },
  21411. render: {
  21412. // Put view.render in `progress` to support appendData. But in this case
  21413. // view.render should not be called in reset, otherwise it will be called
  21414. // twise. Use `forceFirstProgress` to make sure that view.render is called
  21415. // in any cases.
  21416. forceFirstProgress: true,
  21417. progress: function (params, context) {
  21418. context.view.render(
  21419. context.model, context.ecModel, context.api, context.payload
  21420. );
  21421. }
  21422. }
  21423. };
  21424. /*
  21425. * Licensed to the Apache Software Foundation (ASF) under one
  21426. * or more contributor license agreements. See the NOTICE file
  21427. * distributed with this work for additional information
  21428. * regarding copyright ownership. The ASF licenses this file
  21429. * to you under the Apache License, Version 2.0 (the
  21430. * "License"); you may not use this file except in compliance
  21431. * with the License. You may obtain a copy of the License at
  21432. *
  21433. * http://www.apache.org/licenses/LICENSE-2.0
  21434. *
  21435. * Unless required by applicable law or agreed to in writing,
  21436. * software distributed under the License is distributed on an
  21437. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21438. * KIND, either express or implied. See the License for the
  21439. * specific language governing permissions and limitations
  21440. * under the License.
  21441. */
  21442. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  21443. var RATE = '\0__throttleRate';
  21444. var THROTTLE_TYPE = '\0__throttleType';
  21445. /**
  21446. * @public
  21447. * @param {(Function)} fn
  21448. * @param {number} [delay=0] Unit: ms.
  21449. * @param {boolean} [debounce=false]
  21450. * true: If call interval less than `delay`, only the last call works.
  21451. * false: If call interval less than `delay, call works on fixed rate.
  21452. * @return {(Function)} throttled fn.
  21453. */
  21454. function throttle(fn, delay, debounce) {
  21455. var currCall;
  21456. var lastCall = 0;
  21457. var lastExec = 0;
  21458. var timer = null;
  21459. var diff;
  21460. var scope;
  21461. var args;
  21462. var debounceNextCall;
  21463. delay = delay || 0;
  21464. function exec() {
  21465. lastExec = (new Date()).getTime();
  21466. timer = null;
  21467. fn.apply(scope, args || []);
  21468. }
  21469. var cb = function () {
  21470. currCall = (new Date()).getTime();
  21471. scope = this;
  21472. args = arguments;
  21473. var thisDelay = debounceNextCall || delay;
  21474. var thisDebounce = debounceNextCall || debounce;
  21475. debounceNextCall = null;
  21476. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  21477. clearTimeout(timer);
  21478. // Here we should make sure that: the `exec` SHOULD NOT be called later
  21479. // than a new call of `cb`, that is, preserving the command order. Consider
  21480. // calculating "scale rate" when roaming as an example. When a call of `cb`
  21481. // happens, either the `exec` is called dierectly, or the call is delayed.
  21482. // But the delayed call should never be later than next call of `cb`. Under
  21483. // this assurance, we can simply update view state each time `dispatchAction`
  21484. // triggered by user roaming, but not need to add extra code to avoid the
  21485. // state being "rolled-back".
  21486. if (thisDebounce) {
  21487. timer = setTimeout(exec, thisDelay);
  21488. }
  21489. else {
  21490. if (diff >= 0) {
  21491. exec();
  21492. }
  21493. else {
  21494. timer = setTimeout(exec, -diff);
  21495. }
  21496. }
  21497. lastCall = currCall;
  21498. };
  21499. /**
  21500. * Clear throttle.
  21501. * @public
  21502. */
  21503. cb.clear = function () {
  21504. if (timer) {
  21505. clearTimeout(timer);
  21506. timer = null;
  21507. }
  21508. };
  21509. /**
  21510. * Enable debounce once.
  21511. */
  21512. cb.debounceNextCall = function (debounceDelay) {
  21513. debounceNextCall = debounceDelay;
  21514. };
  21515. return cb;
  21516. }
  21517. /**
  21518. * Create throttle method or update throttle rate.
  21519. *
  21520. * @example
  21521. * ComponentView.prototype.render = function () {
  21522. * ...
  21523. * throttle.createOrUpdate(
  21524. * this,
  21525. * '_dispatchAction',
  21526. * this.model.get('throttle'),
  21527. * 'fixRate'
  21528. * );
  21529. * };
  21530. * ComponentView.prototype.remove = function () {
  21531. * throttle.clear(this, '_dispatchAction');
  21532. * };
  21533. * ComponentView.prototype.dispose = function () {
  21534. * throttle.clear(this, '_dispatchAction');
  21535. * };
  21536. *
  21537. * @public
  21538. * @param {Object} obj
  21539. * @param {string} fnAttr
  21540. * @param {number} [rate]
  21541. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  21542. * @return {Function} throttled function.
  21543. */
  21544. function createOrUpdate(obj, fnAttr, rate, throttleType) {
  21545. var fn = obj[fnAttr];
  21546. if (!fn) {
  21547. return;
  21548. }
  21549. var originFn = fn[ORIGIN_METHOD] || fn;
  21550. var lastThrottleType = fn[THROTTLE_TYPE];
  21551. var lastRate = fn[RATE];
  21552. if (lastRate !== rate || lastThrottleType !== throttleType) {
  21553. if (rate == null || !throttleType) {
  21554. return (obj[fnAttr] = originFn);
  21555. }
  21556. fn = obj[fnAttr] = throttle(
  21557. originFn, rate, throttleType === 'debounce'
  21558. );
  21559. fn[ORIGIN_METHOD] = originFn;
  21560. fn[THROTTLE_TYPE] = throttleType;
  21561. fn[RATE] = rate;
  21562. }
  21563. return fn;
  21564. }
  21565. /**
  21566. * Clear throttle. Example see throttle.createOrUpdate.
  21567. *
  21568. * @public
  21569. * @param {Object} obj
  21570. * @param {string} fnAttr
  21571. */
  21572. function clear(obj, fnAttr) {
  21573. var fn = obj[fnAttr];
  21574. if (fn && fn[ORIGIN_METHOD]) {
  21575. obj[fnAttr] = fn[ORIGIN_METHOD];
  21576. }
  21577. }
  21578. /*
  21579. * Licensed to the Apache Software Foundation (ASF) under one
  21580. * or more contributor license agreements. See the NOTICE file
  21581. * distributed with this work for additional information
  21582. * regarding copyright ownership. The ASF licenses this file
  21583. * to you under the Apache License, Version 2.0 (the
  21584. * "License"); you may not use this file except in compliance
  21585. * with the License. You may obtain a copy of the License at
  21586. *
  21587. * http://www.apache.org/licenses/LICENSE-2.0
  21588. *
  21589. * Unless required by applicable law or agreed to in writing,
  21590. * software distributed under the License is distributed on an
  21591. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21592. * KIND, either express or implied. See the License for the
  21593. * specific language governing permissions and limitations
  21594. * under the License.
  21595. */
  21596. var seriesColor = {
  21597. createOnAllSeries: true,
  21598. performRawSeries: true,
  21599. reset: function (seriesModel, ecModel) {
  21600. var data = seriesModel.getData();
  21601. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.color').split('.');
  21602. var color = seriesModel.get(colorAccessPath) // Set in itemStyle
  21603. || seriesModel.getColorFromPalette(
  21604. // TODO series count changed.
  21605. seriesModel.name, null, ecModel.getSeriesCount()
  21606. ); // Default color
  21607. // FIXME Set color function or use the platte color
  21608. data.setVisual('color', color);
  21609. // Only visible series has each data be visual encoded
  21610. if (!ecModel.isSeriesFiltered(seriesModel)) {
  21611. if (typeof color === 'function' && !(color instanceof Gradient)) {
  21612. data.each(function (idx) {
  21613. data.setItemVisual(
  21614. idx, 'color', color(seriesModel.getDataParams(idx))
  21615. );
  21616. });
  21617. }
  21618. // itemStyle in each data item
  21619. var dataEach = function (data, idx) {
  21620. var itemModel = data.getItemModel(idx);
  21621. var color = itemModel.get(colorAccessPath, true);
  21622. if (color != null) {
  21623. data.setItemVisual(idx, 'color', color);
  21624. }
  21625. };
  21626. return { dataEach: data.hasItemOption ? dataEach : null };
  21627. }
  21628. }
  21629. };
  21630. /*
  21631. * Licensed to the Apache Software Foundation (ASF) under one
  21632. * or more contributor license agreements. See the NOTICE file
  21633. * distributed with this work for additional information
  21634. * regarding copyright ownership. The ASF licenses this file
  21635. * to you under the Apache License, Version 2.0 (the
  21636. * "License"); you may not use this file except in compliance
  21637. * with the License. You may obtain a copy of the License at
  21638. *
  21639. * http://www.apache.org/licenses/LICENSE-2.0
  21640. *
  21641. * Unless required by applicable law or agreed to in writing,
  21642. * software distributed under the License is distributed on an
  21643. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21644. * KIND, either express or implied. See the License for the
  21645. * specific language governing permissions and limitations
  21646. * under the License.
  21647. */
  21648. var lang = {
  21649. toolbox: {
  21650. brush: {
  21651. title: {
  21652. rect: '矩形选择',
  21653. polygon: '圈选',
  21654. lineX: '横向选择',
  21655. lineY: '纵向选择',
  21656. keep: '保持选择',
  21657. clear: '清除选择'
  21658. }
  21659. },
  21660. dataView: {
  21661. title: '数据视图',
  21662. lang: ['数据视图', '关闭', '刷新']
  21663. },
  21664. dataZoom: {
  21665. title: {
  21666. zoom: '区域缩放',
  21667. back: '区域缩放还原'
  21668. }
  21669. },
  21670. magicType: {
  21671. title: {
  21672. line: '切换为折线图',
  21673. bar: '切换为柱状图',
  21674. stack: '切换为堆叠',
  21675. tiled: '切换为平铺'
  21676. }
  21677. },
  21678. restore: {
  21679. title: '还原'
  21680. },
  21681. saveAsImage: {
  21682. title: '保存为图片',
  21683. lang: ['右键另存为图片']
  21684. }
  21685. },
  21686. series: {
  21687. typeNames: {
  21688. pie: '饼图',
  21689. bar: '柱状图',
  21690. line: '折线图',
  21691. scatter: '散点图',
  21692. effectScatter: '涟漪散点图',
  21693. radar: '雷达图',
  21694. tree: '树图',
  21695. treemap: '矩形树图',
  21696. boxplot: '箱型图',
  21697. candlestick: 'K线图',
  21698. k: 'K线图',
  21699. heatmap: '热力图',
  21700. map: '地图',
  21701. parallel: '平行坐标图',
  21702. lines: '线图',
  21703. graph: '关系图',
  21704. sankey: '桑基图',
  21705. funnel: '漏斗图',
  21706. gauge: '仪表盘图',
  21707. pictorialBar: '象形柱图',
  21708. themeRiver: '主题河流图',
  21709. sunburst: '旭日图'
  21710. }
  21711. },
  21712. aria: {
  21713. general: {
  21714. withTitle: '这是一个关于“{title}”的图表。',
  21715. withoutTitle: '这是一个图表,'
  21716. },
  21717. series: {
  21718. single: {
  21719. prefix: '',
  21720. withName: '图表类型是{seriesType},表示{seriesName}。',
  21721. withoutName: '图表类型是{seriesType}。'
  21722. },
  21723. multiple: {
  21724. prefix: '它由{seriesCount}个图表系列组成。',
  21725. withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',
  21726. withoutName: '第{seriesId}个系列是一个{seriesType},',
  21727. separator: {
  21728. middle: ';',
  21729. end: '。'
  21730. }
  21731. }
  21732. },
  21733. data: {
  21734. allData: '其数据是——',
  21735. partialData: '其中,前{displayCnt}项是——',
  21736. withName: '{name}的数据是{value}',
  21737. withoutName: '{value}',
  21738. separator: {
  21739. middle: ',',
  21740. end: ''
  21741. }
  21742. }
  21743. }
  21744. };
  21745. /*
  21746. * Licensed to the Apache Software Foundation (ASF) under one
  21747. * or more contributor license agreements. See the NOTICE file
  21748. * distributed with this work for additional information
  21749. * regarding copyright ownership. The ASF licenses this file
  21750. * to you under the Apache License, Version 2.0 (the
  21751. * "License"); you may not use this file except in compliance
  21752. * with the License. You may obtain a copy of the License at
  21753. *
  21754. * http://www.apache.org/licenses/LICENSE-2.0
  21755. *
  21756. * Unless required by applicable law or agreed to in writing,
  21757. * software distributed under the License is distributed on an
  21758. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21759. * KIND, either express or implied. See the License for the
  21760. * specific language governing permissions and limitations
  21761. * under the License.
  21762. */
  21763. var aria = function (dom, ecModel) {
  21764. var ariaModel = ecModel.getModel('aria');
  21765. if (!ariaModel.get('show')) {
  21766. return;
  21767. }
  21768. else if (ariaModel.get('description')) {
  21769. dom.setAttribute('aria-label', ariaModel.get('description'));
  21770. return;
  21771. }
  21772. var seriesCnt = 0;
  21773. ecModel.eachSeries(function (seriesModel, idx) {
  21774. ++seriesCnt;
  21775. }, this);
  21776. var maxDataCnt = ariaModel.get('data.maxCount') || 10;
  21777. var maxSeriesCnt = ariaModel.get('series.maxCount') || 10;
  21778. var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);
  21779. var ariaLabel;
  21780. if (seriesCnt < 1) {
  21781. // No series, no aria label
  21782. return;
  21783. }
  21784. else {
  21785. var title = getTitle();
  21786. if (title) {
  21787. ariaLabel = replace(getConfig('general.withTitle'), {
  21788. title: title
  21789. });
  21790. }
  21791. else {
  21792. ariaLabel = getConfig('general.withoutTitle');
  21793. }
  21794. var seriesLabels = [];
  21795. var prefix = seriesCnt > 1
  21796. ? 'series.multiple.prefix'
  21797. : 'series.single.prefix';
  21798. ariaLabel += replace(getConfig(prefix), { seriesCount: seriesCnt });
  21799. ecModel.eachSeries(function (seriesModel, idx) {
  21800. if (idx < displaySeriesCnt) {
  21801. var seriesLabel;
  21802. var seriesName = seriesModel.get('name');
  21803. var seriesTpl = 'series.'
  21804. + (seriesCnt > 1 ? 'multiple' : 'single') + '.';
  21805. seriesLabel = getConfig(seriesName
  21806. ? seriesTpl + 'withName'
  21807. : seriesTpl + 'withoutName');
  21808. seriesLabel = replace(seriesLabel, {
  21809. seriesId: seriesModel.seriesIndex,
  21810. seriesName: seriesModel.get('name'),
  21811. seriesType: getSeriesTypeName(seriesModel.subType)
  21812. });
  21813. var data = seriesModel.getData();
  21814. window.data = data;
  21815. if (data.count() > maxDataCnt) {
  21816. // Show part of data
  21817. seriesLabel += replace(getConfig('data.partialData'), {
  21818. displayCnt: maxDataCnt
  21819. });
  21820. }
  21821. else {
  21822. seriesLabel += getConfig('data.allData');
  21823. }
  21824. var dataLabels = [];
  21825. for (var i = 0; i < data.count(); i++) {
  21826. if (i < maxDataCnt) {
  21827. var name = data.getName(i);
  21828. var value = retrieveRawValue(data, i);
  21829. dataLabels.push(
  21830. replace(
  21831. name
  21832. ? getConfig('data.withName')
  21833. : getConfig('data.withoutName'),
  21834. {
  21835. name: name,
  21836. value: value
  21837. }
  21838. )
  21839. );
  21840. }
  21841. }
  21842. seriesLabel += dataLabels
  21843. .join(getConfig('data.separator.middle'))
  21844. + getConfig('data.separator.end');
  21845. seriesLabels.push(seriesLabel);
  21846. }
  21847. });
  21848. ariaLabel += seriesLabels
  21849. .join(getConfig('series.multiple.separator.middle'))
  21850. + getConfig('series.multiple.separator.end');
  21851. dom.setAttribute('aria-label', ariaLabel);
  21852. }
  21853. function replace(str, keyValues) {
  21854. if (typeof str !== 'string') {
  21855. return str;
  21856. }
  21857. var result = str;
  21858. each$1(keyValues, function (value, key) {
  21859. result = result.replace(
  21860. new RegExp('\\{\\s*' + key + '\\s*\\}', 'g'),
  21861. value
  21862. );
  21863. });
  21864. return result;
  21865. }
  21866. function getConfig(path) {
  21867. var userConfig = ariaModel.get(path);
  21868. if (userConfig == null) {
  21869. var pathArr = path.split('.');
  21870. var result = lang.aria;
  21871. for (var i = 0; i < pathArr.length; ++i) {
  21872. result = result[pathArr[i]];
  21873. }
  21874. return result;
  21875. }
  21876. else {
  21877. return userConfig;
  21878. }
  21879. }
  21880. function getTitle() {
  21881. var title = ecModel.getModel('title').option;
  21882. if (title && title.length) {
  21883. title = title[0];
  21884. }
  21885. return title && title.text;
  21886. }
  21887. function getSeriesTypeName(type) {
  21888. return lang.series.typeNames[type] || '自定义图';
  21889. }
  21890. };
  21891. /*
  21892. * Licensed to the Apache Software Foundation (ASF) under one
  21893. * or more contributor license agreements. See the NOTICE file
  21894. * distributed with this work for additional information
  21895. * regarding copyright ownership. The ASF licenses this file
  21896. * to you under the Apache License, Version 2.0 (the
  21897. * "License"); you may not use this file except in compliance
  21898. * with the License. You may obtain a copy of the License at
  21899. *
  21900. * http://www.apache.org/licenses/LICENSE-2.0
  21901. *
  21902. * Unless required by applicable law or agreed to in writing,
  21903. * software distributed under the License is distributed on an
  21904. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21905. * KIND, either express or implied. See the License for the
  21906. * specific language governing permissions and limitations
  21907. * under the License.
  21908. */
  21909. var PI$1 = Math.PI;
  21910. /**
  21911. * @param {module:echarts/ExtensionAPI} api
  21912. * @param {Object} [opts]
  21913. * @param {string} [opts.text]
  21914. * @param {string} [opts.color]
  21915. * @param {string} [opts.textColor]
  21916. * @return {module:zrender/Element}
  21917. */
  21918. var loadingDefault = function (api, opts) {
  21919. opts = opts || {};
  21920. defaults(opts, {
  21921. text: 'loading',
  21922. color: '#c23531',
  21923. textColor: '#000',
  21924. maskColor: 'rgba(255, 255, 255, 0.8)',
  21925. zlevel: 0
  21926. });
  21927. var mask = new Rect({
  21928. style: {
  21929. fill: opts.maskColor
  21930. },
  21931. zlevel: opts.zlevel,
  21932. z: 10000
  21933. });
  21934. var arc = new Arc({
  21935. shape: {
  21936. startAngle: -PI$1 / 2,
  21937. endAngle: -PI$1 / 2 + 0.1,
  21938. r: 10
  21939. },
  21940. style: {
  21941. stroke: opts.color,
  21942. lineCap: 'round',
  21943. lineWidth: 5
  21944. },
  21945. zlevel: opts.zlevel,
  21946. z: 10001
  21947. });
  21948. var labelRect = new Rect({
  21949. style: {
  21950. fill: 'none',
  21951. text: opts.text,
  21952. textPosition: 'right',
  21953. textDistance: 10,
  21954. textFill: opts.textColor
  21955. },
  21956. zlevel: opts.zlevel,
  21957. z: 10001
  21958. });
  21959. arc.animateShape(true)
  21960. .when(1000, {
  21961. endAngle: PI$1 * 3 / 2
  21962. })
  21963. .start('circularInOut');
  21964. arc.animateShape(true)
  21965. .when(1000, {
  21966. startAngle: PI$1 * 3 / 2
  21967. })
  21968. .delay(300)
  21969. .start('circularInOut');
  21970. var group = new Group();
  21971. group.add(arc);
  21972. group.add(labelRect);
  21973. group.add(mask);
  21974. // Inject resize
  21975. group.resize = function () {
  21976. var cx = api.getWidth() / 2;
  21977. var cy = api.getHeight() / 2;
  21978. arc.setShape({
  21979. cx: cx,
  21980. cy: cy
  21981. });
  21982. var r = arc.shape.r;
  21983. labelRect.setShape({
  21984. x: cx - r,
  21985. y: cy - r,
  21986. width: r * 2,
  21987. height: r * 2
  21988. });
  21989. mask.setShape({
  21990. x: 0,
  21991. y: 0,
  21992. width: api.getWidth(),
  21993. height: api.getHeight()
  21994. });
  21995. };
  21996. group.resize();
  21997. return group;
  21998. };
  21999. /*
  22000. * Licensed to the Apache Software Foundation (ASF) under one
  22001. * or more contributor license agreements. See the NOTICE file
  22002. * distributed with this work for additional information
  22003. * regarding copyright ownership. The ASF licenses this file
  22004. * to you under the Apache License, Version 2.0 (the
  22005. * "License"); you may not use this file except in compliance
  22006. * with the License. You may obtain a copy of the License at
  22007. *
  22008. * http://www.apache.org/licenses/LICENSE-2.0
  22009. *
  22010. * Unless required by applicable law or agreed to in writing,
  22011. * software distributed under the License is distributed on an
  22012. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22013. * KIND, either express or implied. See the License for the
  22014. * specific language governing permissions and limitations
  22015. * under the License.
  22016. */
  22017. /**
  22018. * @module echarts/stream/Scheduler
  22019. */
  22020. /**
  22021. * @constructor
  22022. */
  22023. function Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {
  22024. this.ecInstance = ecInstance;
  22025. this.api = api;
  22026. this.unfinished;
  22027. // Fix current processors in case that in some rear cases that
  22028. // processors might be registered after echarts instance created.
  22029. // Register processors incrementally for a echarts instance is
  22030. // not supported by this stream architecture.
  22031. var dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();
  22032. var visualHandlers = this._visualHandlers = visualHandlers.slice();
  22033. this._allHandlers = dataProcessorHandlers.concat(visualHandlers);
  22034. /**
  22035. * @private
  22036. * @type {
  22037. * [handlerUID: string]: {
  22038. * seriesTaskMap?: {
  22039. * [seriesUID: string]: Task
  22040. * },
  22041. * overallTask?: Task
  22042. * }
  22043. * }
  22044. */
  22045. this._stageTaskMap = createHashMap();
  22046. }
  22047. var proto = Scheduler.prototype;
  22048. /**
  22049. * @param {module:echarts/model/Global} ecModel
  22050. * @param {Object} payload
  22051. */
  22052. proto.restoreData = function (ecModel, payload) {
  22053. // TODO: Only restroe needed series and components, but not all components.
  22054. // Currently `restoreData` of all of the series and component will be called.
  22055. // But some independent components like `title`, `legend`, `graphic`, `toolbox`,
  22056. // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,
  22057. // and some components like coordinate system, axes, dataZoom, visualMap only
  22058. // need their target series refresh.
  22059. // (1) If we are implementing this feature some day, we should consider these cases:
  22060. // if a data processor depends on a component (e.g., dataZoomProcessor depends
  22061. // on the settings of `dataZoom`), it should be re-performed if the component
  22062. // is modified by `setOption`.
  22063. // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,
  22064. // it should be re-performed when the result array of `getTargetSeries` changed.
  22065. // We use `dependencies` to cover these issues.
  22066. // (3) How to update target series when coordinate system related components modified.
  22067. // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,
  22068. // and this case all of the tasks will be set as dirty.
  22069. ecModel.restoreData(payload);
  22070. // Theoretically an overall task not only depends on each of its target series, but also
  22071. // depends on all of the series.
  22072. // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks
  22073. // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure
  22074. // that the overall task is set as dirty and to be performed, otherwise it probably cause
  22075. // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it
  22076. // probably cause state chaos (consider `dataZoomProcessor`).
  22077. this._stageTaskMap.each(function (taskRecord) {
  22078. var overallTask = taskRecord.overallTask;
  22079. overallTask && overallTask.dirty();
  22080. });
  22081. };
  22082. // If seriesModel provided, incremental threshold is check by series data.
  22083. proto.getPerformArgs = function (task, isBlock) {
  22084. // For overall task
  22085. if (!task.__pipeline) {
  22086. return;
  22087. }
  22088. var pipeline = this._pipelineMap.get(task.__pipeline.id);
  22089. var pCtx = pipeline.context;
  22090. var incremental = !isBlock
  22091. && pipeline.progressiveEnabled
  22092. && (!pCtx || pCtx.progressiveRender)
  22093. && task.__idxInPipeline > pipeline.blockIndex;
  22094. var step = incremental ? pipeline.step : null;
  22095. var modDataCount = pCtx && pCtx.modDataCount;
  22096. var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;
  22097. return {step: step, modBy: modBy, modDataCount: modDataCount};
  22098. };
  22099. proto.getPipeline = function (pipelineId) {
  22100. return this._pipelineMap.get(pipelineId);
  22101. };
  22102. /**
  22103. * Current, progressive rendering starts from visual and layout.
  22104. * Always detect render mode in the same stage, avoiding that incorrect
  22105. * detection caused by data filtering.
  22106. * Caution:
  22107. * `updateStreamModes` use `seriesModel.getData()`.
  22108. */
  22109. proto.updateStreamModes = function (seriesModel, view) {
  22110. var pipeline = this._pipelineMap.get(seriesModel.uid);
  22111. var data = seriesModel.getData();
  22112. var dataLen = data.count();
  22113. // `progressiveRender` means that can render progressively in each
  22114. // animation frame. Note that some types of series do not provide
  22115. // `view.incrementalPrepareRender` but support `chart.appendData`. We
  22116. // use the term `incremental` but not `progressive` to describe the
  22117. // case that `chart.appendData`.
  22118. var progressiveRender = pipeline.progressiveEnabled
  22119. && view.incrementalPrepareRender
  22120. && dataLen >= pipeline.threshold;
  22121. var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold');
  22122. // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.
  22123. // see `test/candlestick-large3.html`
  22124. var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;
  22125. seriesModel.pipelineContext = pipeline.context = {
  22126. progressiveRender: progressiveRender,
  22127. modDataCount: modDataCount,
  22128. large: large
  22129. };
  22130. };
  22131. proto.restorePipelines = function (ecModel) {
  22132. var scheduler = this;
  22133. var pipelineMap = scheduler._pipelineMap = createHashMap();
  22134. ecModel.eachSeries(function (seriesModel) {
  22135. var progressive = seriesModel.getProgressive();
  22136. var pipelineId = seriesModel.uid;
  22137. pipelineMap.set(pipelineId, {
  22138. id: pipelineId,
  22139. head: null,
  22140. tail: null,
  22141. threshold: seriesModel.getProgressiveThreshold(),
  22142. progressiveEnabled: progressive
  22143. && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),
  22144. blockIndex: -1,
  22145. step: Math.round(progressive || 700),
  22146. count: 0
  22147. });
  22148. pipe(scheduler, seriesModel, seriesModel.dataTask);
  22149. });
  22150. };
  22151. proto.prepareStageTasks = function () {
  22152. var stageTaskMap = this._stageTaskMap;
  22153. var ecModel = this.ecInstance.getModel();
  22154. var api = this.api;
  22155. each$1(this._allHandlers, function (handler) {
  22156. var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, []);
  22157. handler.reset && createSeriesStageTask(this, handler, record, ecModel, api);
  22158. handler.overallReset && createOverallStageTask(this, handler, record, ecModel, api);
  22159. }, this);
  22160. };
  22161. proto.prepareView = function (view, model, ecModel, api) {
  22162. var renderTask = view.renderTask;
  22163. var context = renderTask.context;
  22164. context.model = model;
  22165. context.ecModel = ecModel;
  22166. context.api = api;
  22167. renderTask.__block = !view.incrementalPrepareRender;
  22168. pipe(this, model, renderTask);
  22169. };
  22170. proto.performDataProcessorTasks = function (ecModel, payload) {
  22171. // If we do not use `block` here, it should be considered when to update modes.
  22172. performStageTasks(this, this._dataProcessorHandlers, ecModel, payload, {block: true});
  22173. };
  22174. // opt
  22175. // opt.visualType: 'visual' or 'layout'
  22176. // opt.setDirty
  22177. proto.performVisualTasks = function (ecModel, payload, opt) {
  22178. performStageTasks(this, this._visualHandlers, ecModel, payload, opt);
  22179. };
  22180. function performStageTasks(scheduler, stageHandlers, ecModel, payload, opt) {
  22181. opt = opt || {};
  22182. var unfinished;
  22183. each$1(stageHandlers, function (stageHandler, idx) {
  22184. if (opt.visualType && opt.visualType !== stageHandler.visualType) {
  22185. return;
  22186. }
  22187. var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);
  22188. var seriesTaskMap = stageHandlerRecord.seriesTaskMap;
  22189. var overallTask = stageHandlerRecord.overallTask;
  22190. if (overallTask) {
  22191. var overallNeedDirty;
  22192. var agentStubMap = overallTask.agentStubMap;
  22193. agentStubMap.each(function (stub) {
  22194. if (needSetDirty(opt, stub)) {
  22195. stub.dirty();
  22196. overallNeedDirty = true;
  22197. }
  22198. });
  22199. overallNeedDirty && overallTask.dirty();
  22200. updatePayload(overallTask, payload);
  22201. var performArgs = scheduler.getPerformArgs(overallTask, opt.block);
  22202. // Execute stubs firstly, which may set the overall task dirty,
  22203. // then execute the overall task. And stub will call seriesModel.setData,
  22204. // which ensures that in the overallTask seriesModel.getData() will not
  22205. // return incorrect data.
  22206. agentStubMap.each(function (stub) {
  22207. stub.perform(performArgs);
  22208. });
  22209. unfinished |= overallTask.perform(performArgs);
  22210. }
  22211. else if (seriesTaskMap) {
  22212. seriesTaskMap.each(function (task, pipelineId) {
  22213. if (needSetDirty(opt, task)) {
  22214. task.dirty();
  22215. }
  22216. var performArgs = scheduler.getPerformArgs(task, opt.block);
  22217. performArgs.skip = !stageHandler.performRawSeries
  22218. && ecModel.isSeriesFiltered(task.context.model);
  22219. updatePayload(task, payload);
  22220. unfinished |= task.perform(performArgs);
  22221. });
  22222. }
  22223. });
  22224. function needSetDirty(opt, task) {
  22225. return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));
  22226. }
  22227. scheduler.unfinished |= unfinished;
  22228. }
  22229. proto.performSeriesTasks = function (ecModel) {
  22230. var unfinished;
  22231. ecModel.eachSeries(function (seriesModel) {
  22232. // Progress to the end for dataInit and dataRestore.
  22233. unfinished |= seriesModel.dataTask.perform();
  22234. });
  22235. this.unfinished |= unfinished;
  22236. };
  22237. proto.plan = function () {
  22238. // Travel pipelines, check block.
  22239. this._pipelineMap.each(function (pipeline) {
  22240. var task = pipeline.tail;
  22241. do {
  22242. if (task.__block) {
  22243. pipeline.blockIndex = task.__idxInPipeline;
  22244. break;
  22245. }
  22246. task = task.getUpstream();
  22247. }
  22248. while (task);
  22249. });
  22250. };
  22251. var updatePayload = proto.updatePayload = function (task, payload) {
  22252. payload !== 'remain' && (task.context.payload = payload);
  22253. };
  22254. function createSeriesStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  22255. var seriesTaskMap = stageHandlerRecord.seriesTaskMap
  22256. || (stageHandlerRecord.seriesTaskMap = createHashMap());
  22257. var seriesType = stageHandler.seriesType;
  22258. var getTargetSeries = stageHandler.getTargetSeries;
  22259. // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,
  22260. // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,
  22261. // it works but it may cause other irrelevant charts blocked.
  22262. if (stageHandler.createOnAllSeries) {
  22263. ecModel.eachRawSeries(create);
  22264. }
  22265. else if (seriesType) {
  22266. ecModel.eachRawSeriesByType(seriesType, create);
  22267. }
  22268. else if (getTargetSeries) {
  22269. getTargetSeries(ecModel, api).each(create);
  22270. }
  22271. function create(seriesModel) {
  22272. var pipelineId = seriesModel.uid;
  22273. // Init tasks for each seriesModel only once.
  22274. // Reuse original task instance.
  22275. var task = seriesTaskMap.get(pipelineId)
  22276. || seriesTaskMap.set(pipelineId, createTask({
  22277. plan: seriesTaskPlan,
  22278. reset: seriesTaskReset,
  22279. count: seriesTaskCount
  22280. }));
  22281. task.context = {
  22282. model: seriesModel,
  22283. ecModel: ecModel,
  22284. api: api,
  22285. useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,
  22286. plan: stageHandler.plan,
  22287. reset: stageHandler.reset,
  22288. scheduler: scheduler
  22289. };
  22290. pipe(scheduler, seriesModel, task);
  22291. }
  22292. // Clear unused series tasks.
  22293. var pipelineMap = scheduler._pipelineMap;
  22294. seriesTaskMap.each(function (task, pipelineId) {
  22295. if (!pipelineMap.get(pipelineId)) {
  22296. task.dispose();
  22297. seriesTaskMap.removeKey(pipelineId);
  22298. }
  22299. });
  22300. }
  22301. function createOverallStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  22302. var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask
  22303. // For overall task, the function only be called on reset stage.
  22304. || createTask({reset: overallTaskReset});
  22305. overallTask.context = {
  22306. ecModel: ecModel,
  22307. api: api,
  22308. overallReset: stageHandler.overallReset,
  22309. scheduler: scheduler
  22310. };
  22311. // Reuse orignal stubs.
  22312. var agentStubMap = overallTask.agentStubMap = overallTask.agentStubMap || createHashMap();
  22313. var seriesType = stageHandler.seriesType;
  22314. var getTargetSeries = stageHandler.getTargetSeries;
  22315. var overallProgress = true;
  22316. var modifyOutputEnd = stageHandler.modifyOutputEnd;
  22317. // An overall task with seriesType detected or has `getTargetSeries`, we add
  22318. // stub in each pipelines, it will set the overall task dirty when the pipeline
  22319. // progress. Moreover, to avoid call the overall task each frame (too frequent),
  22320. // we set the pipeline block.
  22321. if (seriesType) {
  22322. ecModel.eachRawSeriesByType(seriesType, createStub);
  22323. }
  22324. else if (getTargetSeries) {
  22325. getTargetSeries(ecModel, api).each(createStub);
  22326. }
  22327. // Otherwise, (usually it is legancy case), the overall task will only be
  22328. // executed when upstream dirty. Otherwise the progressive rendering of all
  22329. // pipelines will be disabled unexpectedly. But it still needs stubs to receive
  22330. // dirty info from upsteam.
  22331. else {
  22332. overallProgress = false;
  22333. each$1(ecModel.getSeries(), createStub);
  22334. }
  22335. function createStub(seriesModel) {
  22336. var pipelineId = seriesModel.uid;
  22337. var stub = agentStubMap.get(pipelineId);
  22338. if (!stub) {
  22339. stub = agentStubMap.set(pipelineId, createTask(
  22340. {reset: stubReset, onDirty: stubOnDirty}
  22341. ));
  22342. // When the result of `getTargetSeries` changed, the overallTask
  22343. // should be set as dirty and re-performed.
  22344. overallTask.dirty();
  22345. }
  22346. stub.context = {
  22347. model: seriesModel,
  22348. overallProgress: overallProgress,
  22349. modifyOutputEnd: modifyOutputEnd
  22350. };
  22351. stub.agent = overallTask;
  22352. stub.__block = overallProgress;
  22353. pipe(scheduler, seriesModel, stub);
  22354. }
  22355. // Clear unused stubs.
  22356. var pipelineMap = scheduler._pipelineMap;
  22357. agentStubMap.each(function (stub, pipelineId) {
  22358. if (!pipelineMap.get(pipelineId)) {
  22359. stub.dispose();
  22360. // When the result of `getTargetSeries` changed, the overallTask
  22361. // should be set as dirty and re-performed.
  22362. overallTask.dirty();
  22363. agentStubMap.removeKey(pipelineId);
  22364. }
  22365. });
  22366. }
  22367. function overallTaskReset(context) {
  22368. context.overallReset(
  22369. context.ecModel, context.api, context.payload
  22370. );
  22371. }
  22372. function stubReset(context, upstreamContext) {
  22373. return context.overallProgress && stubProgress;
  22374. }
  22375. function stubProgress() {
  22376. this.agent.dirty();
  22377. this.getDownstream().dirty();
  22378. }
  22379. function stubOnDirty() {
  22380. this.agent && this.agent.dirty();
  22381. }
  22382. function seriesTaskPlan(context) {
  22383. return context.plan && context.plan(
  22384. context.model, context.ecModel, context.api, context.payload
  22385. );
  22386. }
  22387. function seriesTaskReset(context) {
  22388. if (context.useClearVisual) {
  22389. context.data.clearAllVisual();
  22390. }
  22391. var resetDefines = context.resetDefines = normalizeToArray(context.reset(
  22392. context.model, context.ecModel, context.api, context.payload
  22393. ));
  22394. return resetDefines.length > 1
  22395. ? map(resetDefines, function (v, idx) {
  22396. return makeSeriesTaskProgress(idx);
  22397. })
  22398. : singleSeriesTaskProgress;
  22399. }
  22400. var singleSeriesTaskProgress = makeSeriesTaskProgress(0);
  22401. function makeSeriesTaskProgress(resetDefineIdx) {
  22402. return function (params, context) {
  22403. var data = context.data;
  22404. var resetDefine = context.resetDefines[resetDefineIdx];
  22405. if (resetDefine && resetDefine.dataEach) {
  22406. for (var i = params.start; i < params.end; i++) {
  22407. resetDefine.dataEach(data, i);
  22408. }
  22409. }
  22410. else if (resetDefine && resetDefine.progress) {
  22411. resetDefine.progress(params, data);
  22412. }
  22413. };
  22414. }
  22415. function seriesTaskCount(context) {
  22416. return context.data.count();
  22417. }
  22418. function pipe(scheduler, seriesModel, task) {
  22419. var pipelineId = seriesModel.uid;
  22420. var pipeline = scheduler._pipelineMap.get(pipelineId);
  22421. !pipeline.head && (pipeline.head = task);
  22422. pipeline.tail && pipeline.tail.pipe(task);
  22423. pipeline.tail = task;
  22424. task.__idxInPipeline = pipeline.count++;
  22425. task.__pipeline = pipeline;
  22426. }
  22427. Scheduler.wrapStageHandler = function (stageHandler, visualType) {
  22428. if (isFunction$1(stageHandler)) {
  22429. stageHandler = {
  22430. overallReset: stageHandler,
  22431. seriesType: detectSeriseType(stageHandler)
  22432. };
  22433. }
  22434. stageHandler.uid = getUID('stageHandler');
  22435. visualType && (stageHandler.visualType = visualType);
  22436. return stageHandler;
  22437. };
  22438. /**
  22439. * Only some legacy stage handlers (usually in echarts extensions) are pure function.
  22440. * To ensure that they can work normally, they should work in block mode, that is,
  22441. * they should not be started util the previous tasks finished. So they cause the
  22442. * progressive rendering disabled. We try to detect the series type, to narrow down
  22443. * the block range to only the series type they concern, but not all series.
  22444. */
  22445. function detectSeriseType(legacyFunc) {
  22446. seriesType = null;
  22447. try {
  22448. // Assume there is no async when calling `eachSeriesByType`.
  22449. legacyFunc(ecModelMock, apiMock);
  22450. }
  22451. catch (e) {
  22452. }
  22453. return seriesType;
  22454. }
  22455. var ecModelMock = {};
  22456. var apiMock = {};
  22457. var seriesType;
  22458. mockMethods(ecModelMock, GlobalModel);
  22459. mockMethods(apiMock, ExtensionAPI);
  22460. ecModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {
  22461. seriesType = type;
  22462. };
  22463. ecModelMock.eachComponent = function (cond) {
  22464. if (cond.mainType === 'series' && cond.subType) {
  22465. seriesType = cond.subType;
  22466. }
  22467. };
  22468. function mockMethods(target, Clz) {
  22469. /* eslint-disable */
  22470. for (var name in Clz.prototype) {
  22471. // Do not use hasOwnProperty
  22472. target[name] = noop;
  22473. }
  22474. /* eslint-enable */
  22475. }
  22476. /*
  22477. * Licensed to the Apache Software Foundation (ASF) under one
  22478. * or more contributor license agreements. See the NOTICE file
  22479. * distributed with this work for additional information
  22480. * regarding copyright ownership. The ASF licenses this file
  22481. * to you under the Apache License, Version 2.0 (the
  22482. * "License"); you may not use this file except in compliance
  22483. * with the License. You may obtain a copy of the License at
  22484. *
  22485. * http://www.apache.org/licenses/LICENSE-2.0
  22486. *
  22487. * Unless required by applicable law or agreed to in writing,
  22488. * software distributed under the License is distributed on an
  22489. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22490. * KIND, either express or implied. See the License for the
  22491. * specific language governing permissions and limitations
  22492. * under the License.
  22493. */
  22494. var colorAll = [
  22495. '#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C', '#ff9f7f',
  22496. '#fb7293', '#E062AE', '#E690D1', '#e7bcf3', '#9d96f5', '#8378EA', '#96BFFF'
  22497. ];
  22498. var lightTheme = {
  22499. color: colorAll,
  22500. colorLayer: [
  22501. ['#37A2DA', '#ffd85c', '#fd7b5f'],
  22502. ['#37A2DA', '#67E0E3', '#FFDB5C', '#ff9f7f', '#E062AE', '#9d96f5'],
  22503. ['#37A2DA', '#32C5E9', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#e7bcf3', '#8378EA', '#96BFFF'],
  22504. colorAll
  22505. ]
  22506. };
  22507. /*
  22508. * Licensed to the Apache Software Foundation (ASF) under one
  22509. * or more contributor license agreements. See the NOTICE file
  22510. * distributed with this work for additional information
  22511. * regarding copyright ownership. The ASF licenses this file
  22512. * to you under the Apache License, Version 2.0 (the
  22513. * "License"); you may not use this file except in compliance
  22514. * with the License. You may obtain a copy of the License at
  22515. *
  22516. * http://www.apache.org/licenses/LICENSE-2.0
  22517. *
  22518. * Unless required by applicable law or agreed to in writing,
  22519. * software distributed under the License is distributed on an
  22520. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22521. * KIND, either express or implied. See the License for the
  22522. * specific language governing permissions and limitations
  22523. * under the License.
  22524. */
  22525. var contrastColor = '#eee';
  22526. var axisCommon = function () {
  22527. return {
  22528. axisLine: {
  22529. lineStyle: {
  22530. color: contrastColor
  22531. }
  22532. },
  22533. axisTick: {
  22534. lineStyle: {
  22535. color: contrastColor
  22536. }
  22537. },
  22538. axisLabel: {
  22539. textStyle: {
  22540. color: contrastColor
  22541. }
  22542. },
  22543. splitLine: {
  22544. lineStyle: {
  22545. type: 'dashed',
  22546. color: '#aaa'
  22547. }
  22548. },
  22549. splitArea: {
  22550. areaStyle: {
  22551. color: contrastColor
  22552. }
  22553. }
  22554. };
  22555. };
  22556. var colorPalette = [
  22557. '#dd6b66', '#759aa0', '#e69d87', '#8dc1a9', '#ea7e53',
  22558. '#eedd78', '#73a373', '#73b9bc', '#7289ab', '#91ca8c', '#f49f42'
  22559. ];
  22560. var theme = {
  22561. color: colorPalette,
  22562. backgroundColor: '#333',
  22563. tooltip: {
  22564. axisPointer: {
  22565. lineStyle: {
  22566. color: contrastColor
  22567. },
  22568. crossStyle: {
  22569. color: contrastColor
  22570. }
  22571. }
  22572. },
  22573. legend: {
  22574. textStyle: {
  22575. color: contrastColor
  22576. }
  22577. },
  22578. textStyle: {
  22579. color: contrastColor
  22580. },
  22581. title: {
  22582. textStyle: {
  22583. color: contrastColor
  22584. }
  22585. },
  22586. toolbox: {
  22587. iconStyle: {
  22588. normal: {
  22589. borderColor: contrastColor
  22590. }
  22591. }
  22592. },
  22593. dataZoom: {
  22594. textStyle: {
  22595. color: contrastColor
  22596. }
  22597. },
  22598. visualMap: {
  22599. textStyle: {
  22600. color: contrastColor
  22601. }
  22602. },
  22603. timeline: {
  22604. lineStyle: {
  22605. color: contrastColor
  22606. },
  22607. itemStyle: {
  22608. normal: {
  22609. color: colorPalette[1]
  22610. }
  22611. },
  22612. label: {
  22613. normal: {
  22614. textStyle: {
  22615. color: contrastColor
  22616. }
  22617. }
  22618. },
  22619. controlStyle: {
  22620. normal: {
  22621. color: contrastColor,
  22622. borderColor: contrastColor
  22623. }
  22624. }
  22625. },
  22626. timeAxis: axisCommon(),
  22627. logAxis: axisCommon(),
  22628. valueAxis: axisCommon(),
  22629. categoryAxis: axisCommon(),
  22630. line: {
  22631. symbol: 'circle'
  22632. },
  22633. graph: {
  22634. color: colorPalette
  22635. },
  22636. gauge: {
  22637. title: {
  22638. textStyle: {
  22639. color: contrastColor
  22640. }
  22641. }
  22642. },
  22643. candlestick: {
  22644. itemStyle: {
  22645. normal: {
  22646. color: '#FD1050',
  22647. color0: '#0CF49B',
  22648. borderColor: '#FD1050',
  22649. borderColor0: '#0CF49B'
  22650. }
  22651. }
  22652. }
  22653. };
  22654. theme.categoryAxis.splitLine.show = false;
  22655. /*
  22656. * Licensed to the Apache Software Foundation (ASF) under one
  22657. * or more contributor license agreements. See the NOTICE file
  22658. * distributed with this work for additional information
  22659. * regarding copyright ownership. The ASF licenses this file
  22660. * to you under the Apache License, Version 2.0 (the
  22661. * "License"); you may not use this file except in compliance
  22662. * with the License. You may obtain a copy of the License at
  22663. *
  22664. * http://www.apache.org/licenses/LICENSE-2.0
  22665. *
  22666. * Unless required by applicable law or agreed to in writing,
  22667. * software distributed under the License is distributed on an
  22668. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22669. * KIND, either express or implied. See the License for the
  22670. * specific language governing permissions and limitations
  22671. * under the License.
  22672. */
  22673. /**
  22674. * This module is imported by echarts directly.
  22675. *
  22676. * Notice:
  22677. * Always keep this file exists for backward compatibility.
  22678. * Because before 4.1.0, dataset is an optional component,
  22679. * some users may import this module manually.
  22680. */
  22681. ComponentModel.extend({
  22682. type: 'dataset',
  22683. /**
  22684. * @protected
  22685. */
  22686. defaultOption: {
  22687. // 'row', 'column'
  22688. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  22689. // null/'auto': auto detect header, see "module:echarts/data/helper/sourceHelper"
  22690. sourceHeader: null,
  22691. dimensions: null,
  22692. source: null
  22693. },
  22694. optionUpdated: function () {
  22695. detectSourceFormat(this);
  22696. }
  22697. });
  22698. Component.extend({
  22699. type: 'dataset'
  22700. });
  22701. /**
  22702. * 椭圆形状
  22703. * @module zrender/graphic/shape/Ellipse
  22704. */
  22705. var Ellipse = Path.extend({
  22706. type: 'ellipse',
  22707. shape: {
  22708. cx: 0, cy: 0,
  22709. rx: 0, ry: 0
  22710. },
  22711. buildPath: function (ctx, shape) {
  22712. var k = 0.5522848;
  22713. var x = shape.cx;
  22714. var y = shape.cy;
  22715. var a = shape.rx;
  22716. var b = shape.ry;
  22717. var ox = a * k; // 水平控制点偏移量
  22718. var oy = b * k; // 垂直控制点偏移量
  22719. // 从椭圆的左端点开始顺时针绘制四条三次贝塞尔曲线
  22720. ctx.moveTo(x - a, y);
  22721. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  22722. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  22723. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  22724. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  22725. ctx.closePath();
  22726. }
  22727. });
  22728. // import RadialGradient from '../graphic/RadialGradient';
  22729. // import Pattern from '../graphic/Pattern';
  22730. // import * as vector from '../core/vector';
  22731. // Most of the values can be separated by comma and/or white space.
  22732. var DILIMITER_REG = /[\s,]+/;
  22733. /**
  22734. * For big svg string, this method might be time consuming.
  22735. *
  22736. * @param {string} svg xml string
  22737. * @return {Object} xml root.
  22738. */
  22739. function parseXML(svg) {
  22740. if (isString(svg)) {
  22741. var parser = new DOMParser();
  22742. svg = parser.parseFromString(svg, 'text/xml');
  22743. }
  22744. // Document node. If using $.get, doc node may be input.
  22745. if (svg.nodeType === 9) {
  22746. svg = svg.firstChild;
  22747. }
  22748. // nodeName of <!DOCTYPE svg> is also 'svg'.
  22749. while (svg.nodeName.toLowerCase() !== 'svg' || svg.nodeType !== 1) {
  22750. svg = svg.nextSibling;
  22751. }
  22752. return svg;
  22753. }
  22754. function SVGParser() {
  22755. this._defs = {};
  22756. this._root = null;
  22757. this._isDefine = false;
  22758. this._isText = false;
  22759. }
  22760. SVGParser.prototype.parse = function (xml, opt) {
  22761. opt = opt || {};
  22762. var svg = parseXML(xml);
  22763. if (!svg) {
  22764. throw new Error('Illegal svg');
  22765. }
  22766. var root = new Group();
  22767. this._root = root;
  22768. // parse view port
  22769. var viewBox = svg.getAttribute('viewBox') || '';
  22770. // If width/height not specified, means "100%" of `opt.width/height`.
  22771. // TODO: Other percent value not supported yet.
  22772. var width = parseFloat(svg.getAttribute('width') || opt.width);
  22773. var height = parseFloat(svg.getAttribute('height') || opt.height);
  22774. // If width/height not specified, set as null for output.
  22775. isNaN(width) && (width = null);
  22776. isNaN(height) && (height = null);
  22777. // Apply inline style on svg element.
  22778. parseAttributes(svg, root, null, true);
  22779. var child = svg.firstChild;
  22780. while (child) {
  22781. this._parseNode(child, root);
  22782. child = child.nextSibling;
  22783. }
  22784. var viewBoxRect;
  22785. var viewBoxTransform;
  22786. if (viewBox) {
  22787. var viewBoxArr = trim(viewBox).split(DILIMITER_REG);
  22788. // Some invalid case like viewBox: 'none'.
  22789. if (viewBoxArr.length >= 4) {
  22790. viewBoxRect = {
  22791. x: parseFloat(viewBoxArr[0] || 0),
  22792. y: parseFloat(viewBoxArr[1] || 0),
  22793. width: parseFloat(viewBoxArr[2]),
  22794. height: parseFloat(viewBoxArr[3])
  22795. };
  22796. }
  22797. }
  22798. if (viewBoxRect && width != null && height != null) {
  22799. viewBoxTransform = makeViewBoxTransform(viewBoxRect, width, height);
  22800. if (!opt.ignoreViewBox) {
  22801. // If set transform on the output group, it probably bring trouble when
  22802. // some users only intend to show the clipped content inside the viewBox,
  22803. // but not intend to transform the output group. So we keep the output
  22804. // group no transform. If the user intend to use the viewBox as a
  22805. // camera, just set `opt.ignoreViewBox` as `true` and set transfrom
  22806. // manually according to the viewBox info in the output of this method.
  22807. var elRoot = root;
  22808. root = new Group();
  22809. root.add(elRoot);
  22810. elRoot.scale = viewBoxTransform.scale.slice();
  22811. elRoot.position = viewBoxTransform.position.slice();
  22812. }
  22813. }
  22814. // Some shapes might be overflow the viewport, which should be
  22815. // clipped despite whether the viewBox is used, as the SVG does.
  22816. if (!opt.ignoreRootClip && width != null && height != null) {
  22817. root.setClipPath(new Rect({
  22818. shape: {x: 0, y: 0, width: width, height: height}
  22819. }));
  22820. }
  22821. // Set width/height on group just for output the viewport size.
  22822. return {
  22823. root: root,
  22824. width: width,
  22825. height: height,
  22826. viewBoxRect: viewBoxRect,
  22827. viewBoxTransform: viewBoxTransform
  22828. };
  22829. };
  22830. SVGParser.prototype._parseNode = function (xmlNode, parentGroup) {
  22831. var nodeName = xmlNode.nodeName.toLowerCase();
  22832. // TODO
  22833. // support <style>...</style> in svg, where nodeName is 'style',
  22834. // CSS classes is defined globally wherever the style tags are declared.
  22835. if (nodeName === 'defs') {
  22836. // define flag
  22837. this._isDefine = true;
  22838. }
  22839. else if (nodeName === 'text') {
  22840. this._isText = true;
  22841. }
  22842. var el;
  22843. if (this._isDefine) {
  22844. var parser = defineParsers[nodeName];
  22845. if (parser) {
  22846. var def = parser.call(this, xmlNode);
  22847. var id = xmlNode.getAttribute('id');
  22848. if (id) {
  22849. this._defs[id] = def;
  22850. }
  22851. }
  22852. }
  22853. else {
  22854. var parser = nodeParsers[nodeName];
  22855. if (parser) {
  22856. el = parser.call(this, xmlNode, parentGroup);
  22857. parentGroup.add(el);
  22858. }
  22859. }
  22860. var child = xmlNode.firstChild;
  22861. while (child) {
  22862. if (child.nodeType === 1) {
  22863. this._parseNode(child, el);
  22864. }
  22865. // Is text
  22866. if (child.nodeType === 3 && this._isText) {
  22867. this._parseText(child, el);
  22868. }
  22869. child = child.nextSibling;
  22870. }
  22871. // Quit define
  22872. if (nodeName === 'defs') {
  22873. this._isDefine = false;
  22874. }
  22875. else if (nodeName === 'text') {
  22876. this._isText = false;
  22877. }
  22878. };
  22879. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  22880. if (xmlNode.nodeType === 1) {
  22881. var dx = xmlNode.getAttribute('dx') || 0;
  22882. var dy = xmlNode.getAttribute('dy') || 0;
  22883. this._textX += parseFloat(dx);
  22884. this._textY += parseFloat(dy);
  22885. }
  22886. var text = new Text({
  22887. style: {
  22888. text: xmlNode.textContent,
  22889. transformText: true
  22890. },
  22891. position: [this._textX || 0, this._textY || 0]
  22892. });
  22893. inheritStyle(parentGroup, text);
  22894. parseAttributes(xmlNode, text, this._defs);
  22895. var fontSize = text.style.fontSize;
  22896. if (fontSize && fontSize < 9) {
  22897. // PENDING
  22898. text.style.fontSize = 9;
  22899. text.scale = text.scale || [1, 1];
  22900. text.scale[0] *= fontSize / 9;
  22901. text.scale[1] *= fontSize / 9;
  22902. }
  22903. var rect = text.getBoundingRect();
  22904. this._textX += rect.width;
  22905. parentGroup.add(text);
  22906. return text;
  22907. };
  22908. var nodeParsers = {
  22909. 'g': function (xmlNode, parentGroup) {
  22910. var g = new Group();
  22911. inheritStyle(parentGroup, g);
  22912. parseAttributes(xmlNode, g, this._defs);
  22913. return g;
  22914. },
  22915. 'rect': function (xmlNode, parentGroup) {
  22916. var rect = new Rect();
  22917. inheritStyle(parentGroup, rect);
  22918. parseAttributes(xmlNode, rect, this._defs);
  22919. rect.setShape({
  22920. x: parseFloat(xmlNode.getAttribute('x') || 0),
  22921. y: parseFloat(xmlNode.getAttribute('y') || 0),
  22922. width: parseFloat(xmlNode.getAttribute('width') || 0),
  22923. height: parseFloat(xmlNode.getAttribute('height') || 0)
  22924. });
  22925. // console.log(xmlNode.getAttribute('transform'));
  22926. // console.log(rect.transform);
  22927. return rect;
  22928. },
  22929. 'circle': function (xmlNode, parentGroup) {
  22930. var circle = new Circle();
  22931. inheritStyle(parentGroup, circle);
  22932. parseAttributes(xmlNode, circle, this._defs);
  22933. circle.setShape({
  22934. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  22935. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  22936. r: parseFloat(xmlNode.getAttribute('r') || 0)
  22937. });
  22938. return circle;
  22939. },
  22940. 'line': function (xmlNode, parentGroup) {
  22941. var line = new Line();
  22942. inheritStyle(parentGroup, line);
  22943. parseAttributes(xmlNode, line, this._defs);
  22944. line.setShape({
  22945. x1: parseFloat(xmlNode.getAttribute('x1') || 0),
  22946. y1: parseFloat(xmlNode.getAttribute('y1') || 0),
  22947. x2: parseFloat(xmlNode.getAttribute('x2') || 0),
  22948. y2: parseFloat(xmlNode.getAttribute('y2') || 0)
  22949. });
  22950. return line;
  22951. },
  22952. 'ellipse': function (xmlNode, parentGroup) {
  22953. var ellipse = new Ellipse();
  22954. inheritStyle(parentGroup, ellipse);
  22955. parseAttributes(xmlNode, ellipse, this._defs);
  22956. ellipse.setShape({
  22957. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  22958. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  22959. rx: parseFloat(xmlNode.getAttribute('rx') || 0),
  22960. ry: parseFloat(xmlNode.getAttribute('ry') || 0)
  22961. });
  22962. return ellipse;
  22963. },
  22964. 'polygon': function (xmlNode, parentGroup) {
  22965. var points = xmlNode.getAttribute('points');
  22966. if (points) {
  22967. points = parsePoints(points);
  22968. }
  22969. var polygon = new Polygon({
  22970. shape: {
  22971. points: points || []
  22972. }
  22973. });
  22974. inheritStyle(parentGroup, polygon);
  22975. parseAttributes(xmlNode, polygon, this._defs);
  22976. return polygon;
  22977. },
  22978. 'polyline': function (xmlNode, parentGroup) {
  22979. var path = new Path();
  22980. inheritStyle(parentGroup, path);
  22981. parseAttributes(xmlNode, path, this._defs);
  22982. var points = xmlNode.getAttribute('points');
  22983. if (points) {
  22984. points = parsePoints(points);
  22985. }
  22986. var polyline = new Polyline({
  22987. shape: {
  22988. points: points || []
  22989. }
  22990. });
  22991. return polyline;
  22992. },
  22993. 'image': function (xmlNode, parentGroup) {
  22994. var img = new ZImage();
  22995. inheritStyle(parentGroup, img);
  22996. parseAttributes(xmlNode, img, this._defs);
  22997. img.setStyle({
  22998. image: xmlNode.getAttribute('xlink:href'),
  22999. x: xmlNode.getAttribute('x'),
  23000. y: xmlNode.getAttribute('y'),
  23001. width: xmlNode.getAttribute('width'),
  23002. height: xmlNode.getAttribute('height')
  23003. });
  23004. return img;
  23005. },
  23006. 'text': function (xmlNode, parentGroup) {
  23007. var x = xmlNode.getAttribute('x') || 0;
  23008. var y = xmlNode.getAttribute('y') || 0;
  23009. var dx = xmlNode.getAttribute('dx') || 0;
  23010. var dy = xmlNode.getAttribute('dy') || 0;
  23011. this._textX = parseFloat(x) + parseFloat(dx);
  23012. this._textY = parseFloat(y) + parseFloat(dy);
  23013. var g = new Group();
  23014. inheritStyle(parentGroup, g);
  23015. parseAttributes(xmlNode, g, this._defs);
  23016. return g;
  23017. },
  23018. 'tspan': function (xmlNode, parentGroup) {
  23019. var x = xmlNode.getAttribute('x');
  23020. var y = xmlNode.getAttribute('y');
  23021. if (x != null) {
  23022. // new offset x
  23023. this._textX = parseFloat(x);
  23024. }
  23025. if (y != null) {
  23026. // new offset y
  23027. this._textY = parseFloat(y);
  23028. }
  23029. var dx = xmlNode.getAttribute('dx') || 0;
  23030. var dy = xmlNode.getAttribute('dy') || 0;
  23031. var g = new Group();
  23032. inheritStyle(parentGroup, g);
  23033. parseAttributes(xmlNode, g, this._defs);
  23034. this._textX += dx;
  23035. this._textY += dy;
  23036. return g;
  23037. },
  23038. 'path': function (xmlNode, parentGroup) {
  23039. // TODO svg fill rule
  23040. // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
  23041. // path.style.globalCompositeOperation = 'xor';
  23042. var d = xmlNode.getAttribute('d') || '';
  23043. // Performance sensitive.
  23044. var path = createFromString(d);
  23045. inheritStyle(parentGroup, path);
  23046. parseAttributes(xmlNode, path, this._defs);
  23047. return path;
  23048. }
  23049. };
  23050. var defineParsers = {
  23051. 'lineargradient': function (xmlNode) {
  23052. var x1 = parseInt(xmlNode.getAttribute('x1') || 0, 10);
  23053. var y1 = parseInt(xmlNode.getAttribute('y1') || 0, 10);
  23054. var x2 = parseInt(xmlNode.getAttribute('x2') || 10, 10);
  23055. var y2 = parseInt(xmlNode.getAttribute('y2') || 0, 10);
  23056. var gradient = new LinearGradient(x1, y1, x2, y2);
  23057. _parseGradientColorStops(xmlNode, gradient);
  23058. return gradient;
  23059. },
  23060. 'radialgradient': function (xmlNode) {
  23061. }
  23062. };
  23063. function _parseGradientColorStops(xmlNode, gradient) {
  23064. var stop = xmlNode.firstChild;
  23065. while (stop) {
  23066. if (stop.nodeType === 1) {
  23067. var offset = stop.getAttribute('offset');
  23068. if (offset.indexOf('%') > 0) { // percentage
  23069. offset = parseInt(offset, 10) / 100;
  23070. }
  23071. else if (offset) { // number from 0 to 1
  23072. offset = parseFloat(offset);
  23073. }
  23074. else {
  23075. offset = 0;
  23076. }
  23077. var stopColor = stop.getAttribute('stop-color') || '#000000';
  23078. gradient.addColorStop(offset, stopColor);
  23079. }
  23080. stop = stop.nextSibling;
  23081. }
  23082. }
  23083. function inheritStyle(parent, child) {
  23084. if (parent && parent.__inheritedStyle) {
  23085. if (!child.__inheritedStyle) {
  23086. child.__inheritedStyle = {};
  23087. }
  23088. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  23089. }
  23090. }
  23091. function parsePoints(pointsString) {
  23092. var list = trim(pointsString).split(DILIMITER_REG);
  23093. var points = [];
  23094. for (var i = 0; i < list.length; i += 2) {
  23095. var x = parseFloat(list[i]);
  23096. var y = parseFloat(list[i + 1]);
  23097. points.push([x, y]);
  23098. }
  23099. return points;
  23100. }
  23101. var attributesMap = {
  23102. 'fill': 'fill',
  23103. 'stroke': 'stroke',
  23104. 'stroke-width': 'lineWidth',
  23105. 'opacity': 'opacity',
  23106. 'fill-opacity': 'fillOpacity',
  23107. 'stroke-opacity': 'strokeOpacity',
  23108. 'stroke-dasharray': 'lineDash',
  23109. 'stroke-dashoffset': 'lineDashOffset',
  23110. 'stroke-linecap': 'lineCap',
  23111. 'stroke-linejoin': 'lineJoin',
  23112. 'stroke-miterlimit': 'miterLimit',
  23113. 'font-family': 'fontFamily',
  23114. 'font-size': 'fontSize',
  23115. 'font-style': 'fontStyle',
  23116. 'font-weight': 'fontWeight',
  23117. 'text-align': 'textAlign',
  23118. 'alignment-baseline': 'textBaseline'
  23119. };
  23120. function parseAttributes(xmlNode, el, defs, onlyInlineStyle) {
  23121. var zrStyle = el.__inheritedStyle || {};
  23122. var isTextEl = el.type === 'text';
  23123. // TODO Shadow
  23124. if (xmlNode.nodeType === 1) {
  23125. parseTransformAttribute(xmlNode, el);
  23126. extend(zrStyle, parseStyleAttribute(xmlNode));
  23127. if (!onlyInlineStyle) {
  23128. for (var svgAttrName in attributesMap) {
  23129. if (attributesMap.hasOwnProperty(svgAttrName)) {
  23130. var attrValue = xmlNode.getAttribute(svgAttrName);
  23131. if (attrValue != null) {
  23132. zrStyle[attributesMap[svgAttrName]] = attrValue;
  23133. }
  23134. }
  23135. }
  23136. }
  23137. }
  23138. var elFillProp = isTextEl ? 'textFill' : 'fill';
  23139. var elStrokeProp = isTextEl ? 'textStroke' : 'stroke';
  23140. el.style = el.style || new Style();
  23141. var elStyle = el.style;
  23142. zrStyle.fill != null && elStyle.set(elFillProp, getPaint(zrStyle.fill, defs));
  23143. zrStyle.stroke != null && elStyle.set(elStrokeProp, getPaint(zrStyle.stroke, defs));
  23144. each$1([
  23145. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  23146. ], function (propName) {
  23147. var elPropName = (propName === 'lineWidth' && isTextEl) ? 'textStrokeWidth' : propName;
  23148. zrStyle[propName] != null && elStyle.set(elPropName, parseFloat(zrStyle[propName]));
  23149. });
  23150. if (!zrStyle.textBaseline || zrStyle.textBaseline === 'auto') {
  23151. zrStyle.textBaseline = 'alphabetic';
  23152. }
  23153. if (zrStyle.textBaseline === 'alphabetic') {
  23154. zrStyle.textBaseline = 'bottom';
  23155. }
  23156. if (zrStyle.textAlign === 'start') {
  23157. zrStyle.textAlign = 'left';
  23158. }
  23159. if (zrStyle.textAlign === 'end') {
  23160. zrStyle.textAlign = 'right';
  23161. }
  23162. each$1(['lineDashOffset', 'lineCap', 'lineJoin',
  23163. 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign', 'textBaseline'
  23164. ], function (propName) {
  23165. zrStyle[propName] != null && elStyle.set(propName, zrStyle[propName]);
  23166. });
  23167. if (zrStyle.lineDash) {
  23168. el.style.lineDash = trim(zrStyle.lineDash).split(DILIMITER_REG);
  23169. }
  23170. if (elStyle[elStrokeProp] && elStyle[elStrokeProp] !== 'none') {
  23171. // enable stroke
  23172. el[elStrokeProp] = true;
  23173. }
  23174. el.__inheritedStyle = zrStyle;
  23175. }
  23176. var urlRegex = /url\(\s*#(.*?)\)/;
  23177. function getPaint(str, defs) {
  23178. // if (str === 'none') {
  23179. // return;
  23180. // }
  23181. var urlMatch = defs && str && str.match(urlRegex);
  23182. if (urlMatch) {
  23183. var url = trim(urlMatch[1]);
  23184. var def = defs[url];
  23185. return def;
  23186. }
  23187. return str;
  23188. }
  23189. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.e,]*)\)/g;
  23190. function parseTransformAttribute(xmlNode, node) {
  23191. var transform = xmlNode.getAttribute('transform');
  23192. if (transform) {
  23193. transform = transform.replace(/,/g, ' ');
  23194. var m = null;
  23195. var transformOps = [];
  23196. transform.replace(transformRegex, function (str, type, value) {
  23197. transformOps.push(type, value);
  23198. });
  23199. for (var i = transformOps.length - 1; i > 0; i -= 2) {
  23200. var value = transformOps[i];
  23201. var type = transformOps[i - 1];
  23202. m = m || create$1();
  23203. switch (type) {
  23204. case 'translate':
  23205. value = trim(value).split(DILIMITER_REG);
  23206. translate(m, m, [parseFloat(value[0]), parseFloat(value[1] || 0)]);
  23207. break;
  23208. case 'scale':
  23209. value = trim(value).split(DILIMITER_REG);
  23210. scale$1(m, m, [parseFloat(value[0]), parseFloat(value[1] || value[0])]);
  23211. break;
  23212. case 'rotate':
  23213. value = trim(value).split(DILIMITER_REG);
  23214. rotate(m, m, parseFloat(value[0]));
  23215. break;
  23216. case 'skew':
  23217. value = trim(value).split(DILIMITER_REG);
  23218. console.warn('Skew transform is not supported yet');
  23219. break;
  23220. case 'matrix':
  23221. var value = trim(value).split(DILIMITER_REG);
  23222. m[0] = parseFloat(value[0]);
  23223. m[1] = parseFloat(value[1]);
  23224. m[2] = parseFloat(value[2]);
  23225. m[3] = parseFloat(value[3]);
  23226. m[4] = parseFloat(value[4]);
  23227. m[5] = parseFloat(value[5]);
  23228. break;
  23229. }
  23230. }
  23231. node.setLocalTransform(m);
  23232. }
  23233. }
  23234. // Value may contain space.
  23235. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  23236. function parseStyleAttribute(xmlNode) {
  23237. var style = xmlNode.getAttribute('style');
  23238. var result = {};
  23239. if (!style) {
  23240. return result;
  23241. }
  23242. var styleList = {};
  23243. styleRegex.lastIndex = 0;
  23244. var styleRegResult;
  23245. while ((styleRegResult = styleRegex.exec(style)) != null) {
  23246. styleList[styleRegResult[1]] = styleRegResult[2];
  23247. }
  23248. for (var svgAttrName in attributesMap) {
  23249. if (attributesMap.hasOwnProperty(svgAttrName) && styleList[svgAttrName] != null) {
  23250. result[attributesMap[svgAttrName]] = styleList[svgAttrName];
  23251. }
  23252. }
  23253. return result;
  23254. }
  23255. /**
  23256. * @param {Array.<number>} viewBoxRect
  23257. * @param {number} width
  23258. * @param {number} height
  23259. * @return {Object} {scale, position}
  23260. */
  23261. function makeViewBoxTransform(viewBoxRect, width, height) {
  23262. var scaleX = width / viewBoxRect.width;
  23263. var scaleY = height / viewBoxRect.height;
  23264. var scale = Math.min(scaleX, scaleY);
  23265. // preserveAspectRatio 'xMidYMid'
  23266. var viewBoxScale = [scale, scale];
  23267. var viewBoxPosition = [
  23268. -(viewBoxRect.x + viewBoxRect.width / 2) * scale + width / 2,
  23269. -(viewBoxRect.y + viewBoxRect.height / 2) * scale + height / 2
  23270. ];
  23271. return {
  23272. scale: viewBoxScale,
  23273. position: viewBoxPosition
  23274. };
  23275. }
  23276. /**
  23277. * @param {string|XMLElement} xml
  23278. * @param {Object} [opt]
  23279. * @param {number} [opt.width] Default width if svg width not specified or is a percent value.
  23280. * @param {number} [opt.height] Default height if svg height not specified or is a percent value.
  23281. * @param {boolean} [opt.ignoreViewBox]
  23282. * @param {boolean} [opt.ignoreRootClip]
  23283. * @return {Object} result:
  23284. * {
  23285. * root: Group, The root of the the result tree of zrender shapes,
  23286. * width: number, the viewport width of the SVG,
  23287. * height: number, the viewport height of the SVG,
  23288. * viewBoxRect: {x, y, width, height}, the declared viewBox rect of the SVG, if exists,
  23289. * viewBoxTransform: the {scale, position} calculated by viewBox and viewport, is exists.
  23290. * }
  23291. */
  23292. function parseSVG(xml, opt) {
  23293. var parser = new SVGParser();
  23294. return parser.parse(xml, opt);
  23295. }
  23296. /*
  23297. * Licensed to the Apache Software Foundation (ASF) under one
  23298. * or more contributor license agreements. See the NOTICE file
  23299. * distributed with this work for additional information
  23300. * regarding copyright ownership. The ASF licenses this file
  23301. * to you under the Apache License, Version 2.0 (the
  23302. * "License"); you may not use this file except in compliance
  23303. * with the License. You may obtain a copy of the License at
  23304. *
  23305. * http://www.apache.org/licenses/LICENSE-2.0
  23306. *
  23307. * Unless required by applicable law or agreed to in writing,
  23308. * software distributed under the License is distributed on an
  23309. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23310. * KIND, either express or implied. See the License for the
  23311. * specific language governing permissions and limitations
  23312. * under the License.
  23313. */
  23314. var storage = createHashMap();
  23315. // For minimize the code size of common echarts package,
  23316. // do not put too much logic in this module.
  23317. var mapDataStorage = {
  23318. // The format of record: see `echarts.registerMap`.
  23319. // Compatible with previous `echarts.registerMap`.
  23320. registerMap: function (mapName, rawGeoJson, rawSpecialAreas) {
  23321. var records;
  23322. if (isArray(rawGeoJson)) {
  23323. records = rawGeoJson;
  23324. }
  23325. else if (rawGeoJson.svg) {
  23326. records = [{
  23327. type: 'svg',
  23328. source: rawGeoJson.svg,
  23329. specialAreas: rawGeoJson.specialAreas
  23330. }];
  23331. }
  23332. else {
  23333. // Backward compatibility.
  23334. if (rawGeoJson.geoJson && !rawGeoJson.features) {
  23335. rawSpecialAreas = rawGeoJson.specialAreas;
  23336. rawGeoJson = rawGeoJson.geoJson;
  23337. }
  23338. records = [{
  23339. type: 'geoJSON',
  23340. source: rawGeoJson,
  23341. specialAreas: rawSpecialAreas
  23342. }];
  23343. }
  23344. each$1(records, function (record) {
  23345. var type = record.type;
  23346. type === 'geoJson' && (type = record.type = 'geoJSON');
  23347. var parse = parsers[type];
  23348. if (__DEV__) {
  23349. assert$1(parse, 'Illegal map type: ' + type);
  23350. }
  23351. parse(record);
  23352. });
  23353. return storage.set(mapName, records);
  23354. },
  23355. retrieveMap: function (mapName) {
  23356. return storage.get(mapName);
  23357. }
  23358. };
  23359. var parsers = {
  23360. geoJSON: function (record) {
  23361. var source = record.source;
  23362. record.geoJSON = !isString(source)
  23363. ? source
  23364. : (typeof JSON !== 'undefined' && JSON.parse)
  23365. ? JSON.parse(source)
  23366. : (new Function('return (' + source + ');'))();
  23367. },
  23368. // Only perform parse to XML object here, which might be time
  23369. // consiming for large SVG.
  23370. // Although convert XML to zrender element is also time consiming,
  23371. // if we do it here, the clone of zrender elements has to be
  23372. // required. So we do it once for each geo instance, util real
  23373. // performance issues call for optimizing it.
  23374. svg: function (record) {
  23375. record.svgXML = parseXML(record.source);
  23376. }
  23377. };
  23378. /*
  23379. * Licensed to the Apache Software Foundation (ASF) under one
  23380. * or more contributor license agreements. See the NOTICE file
  23381. * distributed with this work for additional information
  23382. * regarding copyright ownership. The ASF licenses this file
  23383. * to you under the Apache License, Version 2.0 (the
  23384. * "License"); you may not use this file except in compliance
  23385. * with the License. You may obtain a copy of the License at
  23386. *
  23387. * http://www.apache.org/licenses/LICENSE-2.0
  23388. *
  23389. * Unless required by applicable law or agreed to in writing,
  23390. * software distributed under the License is distributed on an
  23391. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23392. * KIND, either express or implied. See the License for the
  23393. * specific language governing permissions and limitations
  23394. * under the License.
  23395. */
  23396. var assert = assert$1;
  23397. var each = each$1;
  23398. var isFunction = isFunction$1;
  23399. var isObject = isObject$1;
  23400. var parseClassType = ComponentModel.parseClassType;
  23401. var version = '4.2.1';
  23402. var dependencies = {
  23403. zrender: '4.0.6'
  23404. };
  23405. var TEST_FRAME_REMAIN_TIME = 1;
  23406. var PRIORITY_PROCESSOR_FILTER = 1000;
  23407. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  23408. var PRIORITY_VISUAL_LAYOUT = 1000;
  23409. var PRIORITY_VISUAL_GLOBAL = 2000;
  23410. var PRIORITY_VISUAL_CHART = 3000;
  23411. var PRIORITY_VISUAL_COMPONENT = 4000;
  23412. // FIXME
  23413. // necessary?
  23414. var PRIORITY_VISUAL_BRUSH = 5000;
  23415. var PRIORITY = {
  23416. PROCESSOR: {
  23417. FILTER: PRIORITY_PROCESSOR_FILTER,
  23418. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  23419. },
  23420. VISUAL: {
  23421. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  23422. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  23423. CHART: PRIORITY_VISUAL_CHART,
  23424. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  23425. BRUSH: PRIORITY_VISUAL_BRUSH
  23426. }
  23427. };
  23428. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  23429. // where they must not be invoked nestedly, except the only case: invoke
  23430. // dispatchAction with updateMethod "none" in main process.
  23431. // This flag is used to carry out this rule.
  23432. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  23433. var IN_MAIN_PROCESS = '__flagInMainProcess';
  23434. var OPTION_UPDATED = '__optionUpdated';
  23435. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  23436. function createRegisterEventWithLowercaseName(method) {
  23437. return function (eventName, handler, context) {
  23438. // Event name is all lowercase
  23439. eventName = eventName && eventName.toLowerCase();
  23440. Eventful.prototype[method].call(this, eventName, handler, context);
  23441. };
  23442. }
  23443. /**
  23444. * @module echarts~MessageCenter
  23445. */
  23446. function MessageCenter() {
  23447. Eventful.call(this);
  23448. }
  23449. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
  23450. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
  23451. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
  23452. mixin(MessageCenter, Eventful);
  23453. /**
  23454. * @module echarts~ECharts
  23455. */
  23456. function ECharts(dom, theme$$1, opts) {
  23457. opts = opts || {};
  23458. // Get theme by name
  23459. if (typeof theme$$1 === 'string') {
  23460. theme$$1 = themeStorage[theme$$1];
  23461. }
  23462. /**
  23463. * @type {string}
  23464. */
  23465. this.id;
  23466. /**
  23467. * Group id
  23468. * @type {string}
  23469. */
  23470. this.group;
  23471. /**
  23472. * @type {HTMLElement}
  23473. * @private
  23474. */
  23475. this._dom = dom;
  23476. var defaultRenderer = 'canvas';
  23477. if (__DEV__) {
  23478. defaultRenderer = (
  23479. typeof window === 'undefined' ? global : window
  23480. ).__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
  23481. }
  23482. /**
  23483. * @type {module:zrender/ZRender}
  23484. * @private
  23485. */
  23486. var zr = this._zr = init$1(dom, {
  23487. renderer: opts.renderer || defaultRenderer,
  23488. devicePixelRatio: opts.devicePixelRatio,
  23489. width: opts.width,
  23490. height: opts.height
  23491. });
  23492. /**
  23493. * Expect 60 pfs.
  23494. * @type {Function}
  23495. * @private
  23496. */
  23497. this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  23498. var theme$$1 = clone(theme$$1);
  23499. theme$$1 && backwardCompat(theme$$1, true);
  23500. /**
  23501. * @type {Object}
  23502. * @private
  23503. */
  23504. this._theme = theme$$1;
  23505. /**
  23506. * @type {Array.<module:echarts/view/Chart>}
  23507. * @private
  23508. */
  23509. this._chartsViews = [];
  23510. /**
  23511. * @type {Object.<string, module:echarts/view/Chart>}
  23512. * @private
  23513. */
  23514. this._chartsMap = {};
  23515. /**
  23516. * @type {Array.<module:echarts/view/Component>}
  23517. * @private
  23518. */
  23519. this._componentsViews = [];
  23520. /**
  23521. * @type {Object.<string, module:echarts/view/Component>}
  23522. * @private
  23523. */
  23524. this._componentsMap = {};
  23525. /**
  23526. * @type {module:echarts/CoordinateSystem}
  23527. * @private
  23528. */
  23529. this._coordSysMgr = new CoordinateSystemManager();
  23530. /**
  23531. * @type {module:echarts/ExtensionAPI}
  23532. * @private
  23533. */
  23534. var api = this._api = createExtensionAPI(this);
  23535. // Sort on demand
  23536. function prioritySortFunc(a, b) {
  23537. return a.__prio - b.__prio;
  23538. }
  23539. sort(visualFuncs, prioritySortFunc);
  23540. sort(dataProcessorFuncs, prioritySortFunc);
  23541. /**
  23542. * @type {module:echarts/stream/Scheduler}
  23543. */
  23544. this._scheduler = new Scheduler(this, api, dataProcessorFuncs, visualFuncs);
  23545. Eventful.call(this, this._ecEventProcessor = new EventProcessor());
  23546. /**
  23547. * @type {module:echarts~MessageCenter}
  23548. * @private
  23549. */
  23550. this._messageCenter = new MessageCenter();
  23551. // Init mouse events
  23552. this._initEvents();
  23553. // In case some people write `window.onresize = chart.resize`
  23554. this.resize = bind(this.resize, this);
  23555. // Can't dispatch action during rendering procedure
  23556. this._pendingActions = [];
  23557. zr.animation.on('frame', this._onframe, this);
  23558. bindRenderedEvent(zr, this);
  23559. // ECharts instance can be used as value.
  23560. setAsPrimitive(this);
  23561. }
  23562. var echartsProto = ECharts.prototype;
  23563. echartsProto._onframe = function () {
  23564. if (this._disposed) {
  23565. return;
  23566. }
  23567. var scheduler = this._scheduler;
  23568. // Lazy update
  23569. if (this[OPTION_UPDATED]) {
  23570. var silent = this[OPTION_UPDATED].silent;
  23571. this[IN_MAIN_PROCESS] = true;
  23572. prepare(this);
  23573. updateMethods.update.call(this);
  23574. this[IN_MAIN_PROCESS] = false;
  23575. this[OPTION_UPDATED] = false;
  23576. flushPendingActions.call(this, silent);
  23577. triggerUpdatedEvent.call(this, silent);
  23578. }
  23579. // Avoid do both lazy update and progress in one frame.
  23580. else if (scheduler.unfinished) {
  23581. // Stream progress.
  23582. var remainTime = TEST_FRAME_REMAIN_TIME;
  23583. var ecModel = this._model;
  23584. var api = this._api;
  23585. scheduler.unfinished = false;
  23586. do {
  23587. var startTime = +new Date();
  23588. scheduler.performSeriesTasks(ecModel);
  23589. // Currently dataProcessorFuncs do not check threshold.
  23590. scheduler.performDataProcessorTasks(ecModel);
  23591. updateStreamModes(this, ecModel);
  23592. // Do not update coordinate system here. Because that coord system update in
  23593. // each frame is not a good user experience. So we follow the rule that
  23594. // the extent of the coordinate system is determin in the first frame (the
  23595. // frame is executed immedietely after task reset.
  23596. // this._coordSysMgr.update(ecModel, api);
  23597. // console.log('--- ec frame visual ---', remainTime);
  23598. scheduler.performVisualTasks(ecModel);
  23599. renderSeries(this, this._model, api, 'remain');
  23600. remainTime -= (+new Date() - startTime);
  23601. }
  23602. while (remainTime > 0 && scheduler.unfinished);
  23603. // Call flush explicitly for trigger finished event.
  23604. if (!scheduler.unfinished) {
  23605. this._zr.flush();
  23606. }
  23607. // Else, zr flushing be ensue within the same frame,
  23608. // because zr flushing is after onframe event.
  23609. }
  23610. };
  23611. /**
  23612. * @return {HTMLElement}
  23613. */
  23614. echartsProto.getDom = function () {
  23615. return this._dom;
  23616. };
  23617. /**
  23618. * @return {module:zrender~ZRender}
  23619. */
  23620. echartsProto.getZr = function () {
  23621. return this._zr;
  23622. };
  23623. /**
  23624. * Usage:
  23625. * chart.setOption(option, notMerge, lazyUpdate);
  23626. * chart.setOption(option, {
  23627. * notMerge: ...,
  23628. * lazyUpdate: ...,
  23629. * silent: ...
  23630. * });
  23631. *
  23632. * @param {Object} option
  23633. * @param {Object|boolean} [opts] opts or notMerge.
  23634. * @param {boolean} [opts.notMerge=false]
  23635. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  23636. */
  23637. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  23638. if (__DEV__) {
  23639. assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
  23640. }
  23641. var silent;
  23642. if (isObject(notMerge)) {
  23643. lazyUpdate = notMerge.lazyUpdate;
  23644. silent = notMerge.silent;
  23645. notMerge = notMerge.notMerge;
  23646. }
  23647. this[IN_MAIN_PROCESS] = true;
  23648. if (!this._model || notMerge) {
  23649. var optionManager = new OptionManager(this._api);
  23650. var theme$$1 = this._theme;
  23651. var ecModel = this._model = new GlobalModel(null, null, theme$$1, optionManager);
  23652. ecModel.scheduler = this._scheduler;
  23653. ecModel.init(null, null, theme$$1, optionManager);
  23654. }
  23655. this._model.setOption(option, optionPreprocessorFuncs);
  23656. if (lazyUpdate) {
  23657. this[OPTION_UPDATED] = {silent: silent};
  23658. this[IN_MAIN_PROCESS] = false;
  23659. }
  23660. else {
  23661. prepare(this);
  23662. updateMethods.update.call(this);
  23663. // Ensure zr refresh sychronously, and then pixel in canvas can be
  23664. // fetched after `setOption`.
  23665. this._zr.flush();
  23666. this[OPTION_UPDATED] = false;
  23667. this[IN_MAIN_PROCESS] = false;
  23668. flushPendingActions.call(this, silent);
  23669. triggerUpdatedEvent.call(this, silent);
  23670. }
  23671. };
  23672. /**
  23673. * @DEPRECATED
  23674. */
  23675. echartsProto.setTheme = function () {
  23676. console.error('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  23677. };
  23678. /**
  23679. * @return {module:echarts/model/Global}
  23680. */
  23681. echartsProto.getModel = function () {
  23682. return this._model;
  23683. };
  23684. /**
  23685. * @return {Object}
  23686. */
  23687. echartsProto.getOption = function () {
  23688. return this._model && this._model.getOption();
  23689. };
  23690. /**
  23691. * @return {number}
  23692. */
  23693. echartsProto.getWidth = function () {
  23694. return this._zr.getWidth();
  23695. };
  23696. /**
  23697. * @return {number}
  23698. */
  23699. echartsProto.getHeight = function () {
  23700. return this._zr.getHeight();
  23701. };
  23702. /**
  23703. * @return {number}
  23704. */
  23705. echartsProto.getDevicePixelRatio = function () {
  23706. return this._zr.painter.dpr || window.devicePixelRatio || 1;
  23707. };
  23708. /**
  23709. * Get canvas which has all thing rendered
  23710. * @param {Object} opts
  23711. * @param {string} [opts.backgroundColor]
  23712. * @return {string}
  23713. */
  23714. echartsProto.getRenderedCanvas = function (opts) {
  23715. if (!env$1.canvasSupported) {
  23716. return;
  23717. }
  23718. opts = opts || {};
  23719. opts.pixelRatio = opts.pixelRatio || 1;
  23720. opts.backgroundColor = opts.backgroundColor
  23721. || this._model.get('backgroundColor');
  23722. var zr = this._zr;
  23723. // var list = zr.storage.getDisplayList();
  23724. // Stop animations
  23725. // Never works before in init animation, so remove it.
  23726. // zrUtil.each(list, function (el) {
  23727. // el.stopAnimation(true);
  23728. // });
  23729. return zr.painter.getRenderedCanvas(opts);
  23730. };
  23731. /**
  23732. * Get svg data url
  23733. * @return {string}
  23734. */
  23735. echartsProto.getSvgDataUrl = function () {
  23736. if (!env$1.svgSupported) {
  23737. return;
  23738. }
  23739. var zr = this._zr;
  23740. var list = zr.storage.getDisplayList();
  23741. // Stop animations
  23742. each$1(list, function (el) {
  23743. el.stopAnimation(true);
  23744. });
  23745. return zr.painter.pathToDataUrl();
  23746. };
  23747. /**
  23748. * @return {string}
  23749. * @param {Object} opts
  23750. * @param {string} [opts.type='png']
  23751. * @param {string} [opts.pixelRatio=1]
  23752. * @param {string} [opts.backgroundColor]
  23753. * @param {string} [opts.excludeComponents]
  23754. */
  23755. echartsProto.getDataURL = function (opts) {
  23756. opts = opts || {};
  23757. var excludeComponents = opts.excludeComponents;
  23758. var ecModel = this._model;
  23759. var excludesComponentViews = [];
  23760. var self = this;
  23761. each(excludeComponents, function (componentType) {
  23762. ecModel.eachComponent({
  23763. mainType: componentType
  23764. }, function (component) {
  23765. var view = self._componentsMap[component.__viewId];
  23766. if (!view.group.ignore) {
  23767. excludesComponentViews.push(view);
  23768. view.group.ignore = true;
  23769. }
  23770. });
  23771. });
  23772. var url = this._zr.painter.getType() === 'svg'
  23773. ? this.getSvgDataUrl()
  23774. : this.getRenderedCanvas(opts).toDataURL(
  23775. 'image/' + (opts && opts.type || 'png')
  23776. );
  23777. each(excludesComponentViews, function (view) {
  23778. view.group.ignore = false;
  23779. });
  23780. return url;
  23781. };
  23782. /**
  23783. * @return {string}
  23784. * @param {Object} opts
  23785. * @param {string} [opts.type='png']
  23786. * @param {string} [opts.pixelRatio=1]
  23787. * @param {string} [opts.backgroundColor]
  23788. */
  23789. echartsProto.getConnectedDataURL = function (opts) {
  23790. if (!env$1.canvasSupported) {
  23791. return;
  23792. }
  23793. var groupId = this.group;
  23794. var mathMin = Math.min;
  23795. var mathMax = Math.max;
  23796. var MAX_NUMBER = Infinity;
  23797. if (connectedGroups[groupId]) {
  23798. var left = MAX_NUMBER;
  23799. var top = MAX_NUMBER;
  23800. var right = -MAX_NUMBER;
  23801. var bottom = -MAX_NUMBER;
  23802. var canvasList = [];
  23803. var dpr = (opts && opts.pixelRatio) || 1;
  23804. each$1(instances, function (chart, id) {
  23805. if (chart.group === groupId) {
  23806. var canvas = chart.getRenderedCanvas(
  23807. clone(opts)
  23808. );
  23809. var boundingRect = chart.getDom().getBoundingClientRect();
  23810. left = mathMin(boundingRect.left, left);
  23811. top = mathMin(boundingRect.top, top);
  23812. right = mathMax(boundingRect.right, right);
  23813. bottom = mathMax(boundingRect.bottom, bottom);
  23814. canvasList.push({
  23815. dom: canvas,
  23816. left: boundingRect.left,
  23817. top: boundingRect.top
  23818. });
  23819. }
  23820. });
  23821. left *= dpr;
  23822. top *= dpr;
  23823. right *= dpr;
  23824. bottom *= dpr;
  23825. var width = right - left;
  23826. var height = bottom - top;
  23827. var targetCanvas = createCanvas();
  23828. targetCanvas.width = width;
  23829. targetCanvas.height = height;
  23830. var zr = init$1(targetCanvas);
  23831. each(canvasList, function (item) {
  23832. var img = new ZImage({
  23833. style: {
  23834. x: item.left * dpr - left,
  23835. y: item.top * dpr - top,
  23836. image: item.dom
  23837. }
  23838. });
  23839. zr.add(img);
  23840. });
  23841. zr.refreshImmediately();
  23842. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  23843. }
  23844. else {
  23845. return this.getDataURL(opts);
  23846. }
  23847. };
  23848. /**
  23849. * Convert from logical coordinate system to pixel coordinate system.
  23850. * See CoordinateSystem#convertToPixel.
  23851. * @param {string|Object} finder
  23852. * If string, e.g., 'geo', means {geoIndex: 0}.
  23853. * If Object, could contain some of these properties below:
  23854. * {
  23855. * seriesIndex / seriesId / seriesName,
  23856. * geoIndex / geoId, geoName,
  23857. * bmapIndex / bmapId / bmapName,
  23858. * xAxisIndex / xAxisId / xAxisName,
  23859. * yAxisIndex / yAxisId / yAxisName,
  23860. * gridIndex / gridId / gridName,
  23861. * ... (can be extended)
  23862. * }
  23863. * @param {Array|number} value
  23864. * @return {Array|number} result
  23865. */
  23866. echartsProto.convertToPixel = curry(doConvertPixel, 'convertToPixel');
  23867. /**
  23868. * Convert from pixel coordinate system to logical coordinate system.
  23869. * See CoordinateSystem#convertFromPixel.
  23870. * @param {string|Object} finder
  23871. * If string, e.g., 'geo', means {geoIndex: 0}.
  23872. * If Object, could contain some of these properties below:
  23873. * {
  23874. * seriesIndex / seriesId / seriesName,
  23875. * geoIndex / geoId / geoName,
  23876. * bmapIndex / bmapId / bmapName,
  23877. * xAxisIndex / xAxisId / xAxisName,
  23878. * yAxisIndex / yAxisId / yAxisName
  23879. * gridIndex / gridId / gridName,
  23880. * ... (can be extended)
  23881. * }
  23882. * @param {Array|number} value
  23883. * @return {Array|number} result
  23884. */
  23885. echartsProto.convertFromPixel = curry(doConvertPixel, 'convertFromPixel');
  23886. function doConvertPixel(methodName, finder, value) {
  23887. var ecModel = this._model;
  23888. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  23889. var result;
  23890. finder = parseFinder(ecModel, finder);
  23891. for (var i = 0; i < coordSysList.length; i++) {
  23892. var coordSys = coordSysList[i];
  23893. if (coordSys[methodName]
  23894. && (result = coordSys[methodName](ecModel, finder, value)) != null
  23895. ) {
  23896. return result;
  23897. }
  23898. }
  23899. if (__DEV__) {
  23900. console.warn(
  23901. 'No coordinate system that supports ' + methodName + ' found by the given finder.'
  23902. );
  23903. }
  23904. }
  23905. /**
  23906. * Is the specified coordinate systems or components contain the given pixel point.
  23907. * @param {string|Object} finder
  23908. * If string, e.g., 'geo', means {geoIndex: 0}.
  23909. * If Object, could contain some of these properties below:
  23910. * {
  23911. * seriesIndex / seriesId / seriesName,
  23912. * geoIndex / geoId / geoName,
  23913. * bmapIndex / bmapId / bmapName,
  23914. * xAxisIndex / xAxisId / xAxisName,
  23915. * yAxisIndex / yAxisId / yAxisName,
  23916. * gridIndex / gridId / gridName,
  23917. * ... (can be extended)
  23918. * }
  23919. * @param {Array|number} value
  23920. * @return {boolean} result
  23921. */
  23922. echartsProto.containPixel = function (finder, value) {
  23923. var ecModel = this._model;
  23924. var result;
  23925. finder = parseFinder(ecModel, finder);
  23926. each$1(finder, function (models, key) {
  23927. key.indexOf('Models') >= 0 && each$1(models, function (model) {
  23928. var coordSys = model.coordinateSystem;
  23929. if (coordSys && coordSys.containPoint) {
  23930. result |= !!coordSys.containPoint(value);
  23931. }
  23932. else if (key === 'seriesModels') {
  23933. var view = this._chartsMap[model.__viewId];
  23934. if (view && view.containPoint) {
  23935. result |= view.containPoint(value, model);
  23936. }
  23937. else {
  23938. if (__DEV__) {
  23939. console.warn(key + ': ' + (view
  23940. ? 'The found component do not support containPoint.'
  23941. : 'No view mapping to the found component.'
  23942. ));
  23943. }
  23944. }
  23945. }
  23946. else {
  23947. if (__DEV__) {
  23948. console.warn(key + ': containPoint is not supported');
  23949. }
  23950. }
  23951. }, this);
  23952. }, this);
  23953. return !!result;
  23954. };
  23955. /**
  23956. * Get visual from series or data.
  23957. * @param {string|Object} finder
  23958. * If string, e.g., 'series', means {seriesIndex: 0}.
  23959. * If Object, could contain some of these properties below:
  23960. * {
  23961. * seriesIndex / seriesId / seriesName,
  23962. * dataIndex / dataIndexInside
  23963. * }
  23964. * If dataIndex is not specified, series visual will be fetched,
  23965. * but not data item visual.
  23966. * If all of seriesIndex, seriesId, seriesName are not specified,
  23967. * visual will be fetched from first series.
  23968. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  23969. */
  23970. echartsProto.getVisual = function (finder, visualType) {
  23971. var ecModel = this._model;
  23972. finder = parseFinder(ecModel, finder, {defaultMainType: 'series'});
  23973. var seriesModel = finder.seriesModel;
  23974. if (__DEV__) {
  23975. if (!seriesModel) {
  23976. console.warn('There is no specified seires model');
  23977. }
  23978. }
  23979. var data = seriesModel.getData();
  23980. var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
  23981. ? finder.dataIndexInside
  23982. : finder.hasOwnProperty('dataIndex')
  23983. ? data.indexOfRawIndex(finder.dataIndex)
  23984. : null;
  23985. return dataIndexInside != null
  23986. ? data.getItemVisual(dataIndexInside, visualType)
  23987. : data.getVisual(visualType);
  23988. };
  23989. /**
  23990. * Get view of corresponding component model
  23991. * @param {module:echarts/model/Component} componentModel
  23992. * @return {module:echarts/view/Component}
  23993. */
  23994. echartsProto.getViewOfComponentModel = function (componentModel) {
  23995. return this._componentsMap[componentModel.__viewId];
  23996. };
  23997. /**
  23998. * Get view of corresponding series model
  23999. * @param {module:echarts/model/Series} seriesModel
  24000. * @return {module:echarts/view/Chart}
  24001. */
  24002. echartsProto.getViewOfSeriesModel = function (seriesModel) {
  24003. return this._chartsMap[seriesModel.__viewId];
  24004. };
  24005. var updateMethods = {
  24006. prepareAndUpdate: function (payload) {
  24007. prepare(this);
  24008. updateMethods.update.call(this, payload);
  24009. },
  24010. /**
  24011. * @param {Object} payload
  24012. * @private
  24013. */
  24014. update: function (payload) {
  24015. // console.profile && console.profile('update');
  24016. var ecModel = this._model;
  24017. var api = this._api;
  24018. var zr = this._zr;
  24019. var coordSysMgr = this._coordSysMgr;
  24020. var scheduler = this._scheduler;
  24021. // update before setOption
  24022. if (!ecModel) {
  24023. return;
  24024. }
  24025. scheduler.restoreData(ecModel, payload);
  24026. scheduler.performSeriesTasks(ecModel);
  24027. // TODO
  24028. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  24029. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  24030. // Create new coordinate system each update
  24031. // In LineView may save the old coordinate system and use it to get the orignal point
  24032. coordSysMgr.create(ecModel, api);
  24033. scheduler.performDataProcessorTasks(ecModel, payload);
  24034. // Current stream render is not supported in data process. So we can update
  24035. // stream modes after data processing, where the filtered data is used to
  24036. // deteming whether use progressive rendering.
  24037. updateStreamModes(this, ecModel);
  24038. // We update stream modes before coordinate system updated, then the modes info
  24039. // can be fetched when coord sys updating (consider the barGrid extent fix). But
  24040. // the drawback is the full coord info can not be fetched. Fortunately this full
  24041. // coord is not requied in stream mode updater currently.
  24042. coordSysMgr.update(ecModel, api);
  24043. clearColorPalette(ecModel);
  24044. scheduler.performVisualTasks(ecModel, payload);
  24045. render(this, ecModel, api, payload);
  24046. // Set background
  24047. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  24048. // In IE8
  24049. if (!env$1.canvasSupported) {
  24050. var colorArr = parse(backgroundColor);
  24051. backgroundColor = stringify(colorArr, 'rgb');
  24052. if (colorArr[3] === 0) {
  24053. backgroundColor = 'transparent';
  24054. }
  24055. }
  24056. else {
  24057. zr.setBackgroundColor(backgroundColor);
  24058. }
  24059. performPostUpdateFuncs(ecModel, api);
  24060. // console.profile && console.profileEnd('update');
  24061. },
  24062. /**
  24063. * @param {Object} payload
  24064. * @private
  24065. */
  24066. updateTransform: function (payload) {
  24067. var ecModel = this._model;
  24068. var ecIns = this;
  24069. var api = this._api;
  24070. // update before setOption
  24071. if (!ecModel) {
  24072. return;
  24073. }
  24074. // ChartView.markUpdateMethod(payload, 'updateTransform');
  24075. var componentDirtyList = [];
  24076. ecModel.eachComponent(function (componentType, componentModel) {
  24077. var componentView = ecIns.getViewOfComponentModel(componentModel);
  24078. if (componentView && componentView.__alive) {
  24079. if (componentView.updateTransform) {
  24080. var result = componentView.updateTransform(componentModel, ecModel, api, payload);
  24081. result && result.update && componentDirtyList.push(componentView);
  24082. }
  24083. else {
  24084. componentDirtyList.push(componentView);
  24085. }
  24086. }
  24087. });
  24088. var seriesDirtyMap = createHashMap();
  24089. ecModel.eachSeries(function (seriesModel) {
  24090. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  24091. if (chartView.updateTransform) {
  24092. var result = chartView.updateTransform(seriesModel, ecModel, api, payload);
  24093. result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);
  24094. }
  24095. else {
  24096. seriesDirtyMap.set(seriesModel.uid, 1);
  24097. }
  24098. });
  24099. clearColorPalette(ecModel);
  24100. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24101. // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  24102. this._scheduler.performVisualTasks(
  24103. ecModel, payload, {setDirty: true, dirtyMap: seriesDirtyMap}
  24104. );
  24105. // Currently, not call render of components. Geo render cost a lot.
  24106. // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);
  24107. renderSeries(ecIns, ecModel, api, payload, seriesDirtyMap);
  24108. performPostUpdateFuncs(ecModel, this._api);
  24109. },
  24110. /**
  24111. * @param {Object} payload
  24112. * @private
  24113. */
  24114. updateView: function (payload) {
  24115. var ecModel = this._model;
  24116. // update before setOption
  24117. if (!ecModel) {
  24118. return;
  24119. }
  24120. Chart.markUpdateMethod(payload, 'updateView');
  24121. clearColorPalette(ecModel);
  24122. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24123. this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});
  24124. render(this, this._model, this._api, payload);
  24125. performPostUpdateFuncs(ecModel, this._api);
  24126. },
  24127. /**
  24128. * @param {Object} payload
  24129. * @private
  24130. */
  24131. updateVisual: function (payload) {
  24132. updateMethods.update.call(this, payload);
  24133. // var ecModel = this._model;
  24134. // // update before setOption
  24135. // if (!ecModel) {
  24136. // return;
  24137. // }
  24138. // ChartView.markUpdateMethod(payload, 'updateVisual');
  24139. // clearColorPalette(ecModel);
  24140. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24141. // this._scheduler.performVisualTasks(ecModel, payload, {visualType: 'visual', setDirty: true});
  24142. // render(this, this._model, this._api, payload);
  24143. // performPostUpdateFuncs(ecModel, this._api);
  24144. },
  24145. /**
  24146. * @param {Object} payload
  24147. * @private
  24148. */
  24149. updateLayout: function (payload) {
  24150. updateMethods.update.call(this, payload);
  24151. // var ecModel = this._model;
  24152. // // update before setOption
  24153. // if (!ecModel) {
  24154. // return;
  24155. // }
  24156. // ChartView.markUpdateMethod(payload, 'updateLayout');
  24157. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24158. // // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  24159. // this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});
  24160. // render(this, this._model, this._api, payload);
  24161. // performPostUpdateFuncs(ecModel, this._api);
  24162. }
  24163. };
  24164. function prepare(ecIns) {
  24165. var ecModel = ecIns._model;
  24166. var scheduler = ecIns._scheduler;
  24167. scheduler.restorePipelines(ecModel);
  24168. scheduler.prepareStageTasks();
  24169. prepareView(ecIns, 'component', ecModel, scheduler);
  24170. prepareView(ecIns, 'chart', ecModel, scheduler);
  24171. scheduler.plan();
  24172. }
  24173. /**
  24174. * @private
  24175. */
  24176. function updateDirectly(ecIns, method, payload, mainType, subType) {
  24177. var ecModel = ecIns._model;
  24178. // broadcast
  24179. if (!mainType) {
  24180. // FIXME
  24181. // Chart will not be update directly here, except set dirty.
  24182. // But there is no such scenario now.
  24183. each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
  24184. return;
  24185. }
  24186. var query = {};
  24187. query[mainType + 'Id'] = payload[mainType + 'Id'];
  24188. query[mainType + 'Index'] = payload[mainType + 'Index'];
  24189. query[mainType + 'Name'] = payload[mainType + 'Name'];
  24190. var condition = {mainType: mainType, query: query};
  24191. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  24192. var excludeSeriesId = payload.excludeSeriesId;
  24193. if (excludeSeriesId != null) {
  24194. excludeSeriesId = createHashMap(normalizeToArray(excludeSeriesId));
  24195. }
  24196. // If dispatchAction before setOption, do nothing.
  24197. ecModel && ecModel.eachComponent(condition, function (model) {
  24198. if (!excludeSeriesId || excludeSeriesId.get(model.id) == null) {
  24199. callView(ecIns[
  24200. mainType === 'series' ? '_chartsMap' : '_componentsMap'
  24201. ][model.__viewId]);
  24202. }
  24203. }, ecIns);
  24204. function callView(view) {
  24205. view && view.__alive && view[method] && view[method](
  24206. view.__model, ecModel, ecIns._api, payload
  24207. );
  24208. }
  24209. }
  24210. /**
  24211. * Resize the chart
  24212. * @param {Object} opts
  24213. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  24214. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  24215. * @param {boolean} [opts.silent=false]
  24216. */
  24217. echartsProto.resize = function (opts) {
  24218. if (__DEV__) {
  24219. assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
  24220. }
  24221. this._zr.resize(opts);
  24222. var ecModel = this._model;
  24223. // Resize loading effect
  24224. this._loadingFX && this._loadingFX.resize();
  24225. if (!ecModel) {
  24226. return;
  24227. }
  24228. var optionChanged = ecModel.resetOption('media');
  24229. var silent = opts && opts.silent;
  24230. this[IN_MAIN_PROCESS] = true;
  24231. optionChanged && prepare(this);
  24232. updateMethods.update.call(this);
  24233. this[IN_MAIN_PROCESS] = false;
  24234. flushPendingActions.call(this, silent);
  24235. triggerUpdatedEvent.call(this, silent);
  24236. };
  24237. function updateStreamModes(ecIns, ecModel) {
  24238. var chartsMap = ecIns._chartsMap;
  24239. var scheduler = ecIns._scheduler;
  24240. ecModel.eachSeries(function (seriesModel) {
  24241. scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);
  24242. });
  24243. }
  24244. /**
  24245. * Show loading effect
  24246. * @param {string} [name='default']
  24247. * @param {Object} [cfg]
  24248. */
  24249. echartsProto.showLoading = function (name, cfg) {
  24250. if (isObject(name)) {
  24251. cfg = name;
  24252. name = '';
  24253. }
  24254. name = name || 'default';
  24255. this.hideLoading();
  24256. if (!loadingEffects[name]) {
  24257. if (__DEV__) {
  24258. console.warn('Loading effects ' + name + ' not exists.');
  24259. }
  24260. return;
  24261. }
  24262. var el = loadingEffects[name](this._api, cfg);
  24263. var zr = this._zr;
  24264. this._loadingFX = el;
  24265. zr.add(el);
  24266. };
  24267. /**
  24268. * Hide loading effect
  24269. */
  24270. echartsProto.hideLoading = function () {
  24271. this._loadingFX && this._zr.remove(this._loadingFX);
  24272. this._loadingFX = null;
  24273. };
  24274. /**
  24275. * @param {Object} eventObj
  24276. * @return {Object}
  24277. */
  24278. echartsProto.makeActionFromEvent = function (eventObj) {
  24279. var payload = extend({}, eventObj);
  24280. payload.type = eventActionMap[eventObj.type];
  24281. return payload;
  24282. };
  24283. /**
  24284. * @pubilc
  24285. * @param {Object} payload
  24286. * @param {string} [payload.type] Action type
  24287. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  24288. * @param {boolean} [opt.silent=false] Whether trigger events.
  24289. * @param {boolean} [opt.flush=undefined]
  24290. * true: Flush immediately, and then pixel in canvas can be fetched
  24291. * immediately. Caution: it might affect performance.
  24292. * false: Not not flush.
  24293. * undefined: Auto decide whether perform flush.
  24294. */
  24295. echartsProto.dispatchAction = function (payload, opt) {
  24296. if (!isObject(opt)) {
  24297. opt = {silent: !!opt};
  24298. }
  24299. if (!actions[payload.type]) {
  24300. return;
  24301. }
  24302. // Avoid dispatch action before setOption. Especially in `connect`.
  24303. if (!this._model) {
  24304. return;
  24305. }
  24306. // May dispatchAction in rendering procedure
  24307. if (this[IN_MAIN_PROCESS]) {
  24308. this._pendingActions.push(payload);
  24309. return;
  24310. }
  24311. doDispatchAction.call(this, payload, opt.silent);
  24312. if (opt.flush) {
  24313. this._zr.flush(true);
  24314. }
  24315. else if (opt.flush !== false && env$1.browser.weChat) {
  24316. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  24317. // hang when sliding page (on touch event), which cause that zr does not
  24318. // refresh util user interaction finished, which is not expected.
  24319. // But `dispatchAction` may be called too frequently when pan on touch
  24320. // screen, which impacts performance if do not throttle them.
  24321. this._throttledZrFlush();
  24322. }
  24323. flushPendingActions.call(this, opt.silent);
  24324. triggerUpdatedEvent.call(this, opt.silent);
  24325. };
  24326. function doDispatchAction(payload, silent) {
  24327. var payloadType = payload.type;
  24328. var escapeConnect = payload.escapeConnect;
  24329. var actionWrap = actions[payloadType];
  24330. var actionInfo = actionWrap.actionInfo;
  24331. var cptType = (actionInfo.update || 'update').split(':');
  24332. var updateMethod = cptType.pop();
  24333. cptType = cptType[0] != null && parseClassType(cptType[0]);
  24334. this[IN_MAIN_PROCESS] = true;
  24335. var payloads = [payload];
  24336. var batched = false;
  24337. // Batch action
  24338. if (payload.batch) {
  24339. batched = true;
  24340. payloads = map(payload.batch, function (item) {
  24341. item = defaults(extend({}, item), payload);
  24342. item.batch = null;
  24343. return item;
  24344. });
  24345. }
  24346. var eventObjBatch = [];
  24347. var eventObj;
  24348. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  24349. each(payloads, function (batchItem) {
  24350. // Action can specify the event by return it.
  24351. eventObj = actionWrap.action(batchItem, this._model, this._api);
  24352. // Emit event outside
  24353. eventObj = eventObj || extend({}, batchItem);
  24354. // Convert type to eventType
  24355. eventObj.type = actionInfo.event || eventObj.type;
  24356. eventObjBatch.push(eventObj);
  24357. // light update does not perform data process, layout and visual.
  24358. if (isHighDown) {
  24359. // method, payload, mainType, subType
  24360. updateDirectly(this, updateMethod, batchItem, 'series');
  24361. }
  24362. else if (cptType) {
  24363. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  24364. }
  24365. }, this);
  24366. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  24367. // Still dirty
  24368. if (this[OPTION_UPDATED]) {
  24369. // FIXME Pass payload ?
  24370. prepare(this);
  24371. updateMethods.update.call(this, payload);
  24372. this[OPTION_UPDATED] = false;
  24373. }
  24374. else {
  24375. updateMethods[updateMethod].call(this, payload);
  24376. }
  24377. }
  24378. // Follow the rule of action batch
  24379. if (batched) {
  24380. eventObj = {
  24381. type: actionInfo.event || payloadType,
  24382. escapeConnect: escapeConnect,
  24383. batch: eventObjBatch
  24384. };
  24385. }
  24386. else {
  24387. eventObj = eventObjBatch[0];
  24388. }
  24389. this[IN_MAIN_PROCESS] = false;
  24390. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  24391. }
  24392. function flushPendingActions(silent) {
  24393. var pendingActions = this._pendingActions;
  24394. while (pendingActions.length) {
  24395. var payload = pendingActions.shift();
  24396. doDispatchAction.call(this, payload, silent);
  24397. }
  24398. }
  24399. function triggerUpdatedEvent(silent) {
  24400. !silent && this.trigger('updated');
  24401. }
  24402. /**
  24403. * Event `rendered` is triggered when zr
  24404. * rendered. It is useful for realtime
  24405. * snapshot (reflect animation).
  24406. *
  24407. * Event `finished` is triggered when:
  24408. * (1) zrender rendering finished.
  24409. * (2) initial animation finished.
  24410. * (3) progressive rendering finished.
  24411. * (4) no pending action.
  24412. * (5) no delayed setOption needs to be processed.
  24413. */
  24414. function bindRenderedEvent(zr, ecIns) {
  24415. zr.on('rendered', function () {
  24416. ecIns.trigger('rendered');
  24417. // The `finished` event should not be triggered repeatly,
  24418. // so it should only be triggered when rendering indeed happend
  24419. // in zrender. (Consider the case that dipatchAction is keep
  24420. // triggering when mouse move).
  24421. if (
  24422. // Although zr is dirty if initial animation is not finished
  24423. // and this checking is called on frame, we also check
  24424. // animation finished for robustness.
  24425. zr.animation.isFinished()
  24426. && !ecIns[OPTION_UPDATED]
  24427. && !ecIns._scheduler.unfinished
  24428. && !ecIns._pendingActions.length
  24429. ) {
  24430. ecIns.trigger('finished');
  24431. }
  24432. });
  24433. }
  24434. /**
  24435. * @param {Object} params
  24436. * @param {number} params.seriesIndex
  24437. * @param {Array|TypedArray} params.data
  24438. */
  24439. echartsProto.appendData = function (params) {
  24440. var seriesIndex = params.seriesIndex;
  24441. var ecModel = this.getModel();
  24442. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  24443. if (__DEV__) {
  24444. assert(params.data && seriesModel);
  24445. }
  24446. seriesModel.appendData(params);
  24447. // Note: `appendData` does not support that update extent of coordinate
  24448. // system, util some scenario require that. In the expected usage of
  24449. // `appendData`, the initial extent of coordinate system should better
  24450. // be fixed by axis `min`/`max` setting or initial data, otherwise if
  24451. // the extent changed while `appendData`, the location of the painted
  24452. // graphic elements have to be changed, which make the usage of
  24453. // `appendData` meaningless.
  24454. this._scheduler.unfinished = true;
  24455. };
  24456. /**
  24457. * Register event
  24458. * @method
  24459. */
  24460. echartsProto.on = createRegisterEventWithLowercaseName('on');
  24461. echartsProto.off = createRegisterEventWithLowercaseName('off');
  24462. echartsProto.one = createRegisterEventWithLowercaseName('one');
  24463. /**
  24464. * Prepare view instances of charts and components
  24465. * @param {module:echarts/model/Global} ecModel
  24466. * @private
  24467. */
  24468. function prepareView(ecIns, type, ecModel, scheduler) {
  24469. var isComponent = type === 'component';
  24470. var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;
  24471. var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;
  24472. var zr = ecIns._zr;
  24473. var api = ecIns._api;
  24474. for (var i = 0; i < viewList.length; i++) {
  24475. viewList[i].__alive = false;
  24476. }
  24477. isComponent
  24478. ? ecModel.eachComponent(function (componentType, model) {
  24479. componentType !== 'series' && doPrepare(model);
  24480. })
  24481. : ecModel.eachSeries(doPrepare);
  24482. function doPrepare(model) {
  24483. // Consider: id same and type changed.
  24484. var viewId = '_ec_' + model.id + '_' + model.type;
  24485. var view = viewMap[viewId];
  24486. if (!view) {
  24487. var classType = parseClassType(model.type);
  24488. var Clazz = isComponent
  24489. ? Component.getClass(classType.main, classType.sub)
  24490. : Chart.getClass(classType.sub);
  24491. if (__DEV__) {
  24492. assert(Clazz, classType.sub + ' does not exist.');
  24493. }
  24494. view = new Clazz();
  24495. view.init(ecModel, api);
  24496. viewMap[viewId] = view;
  24497. viewList.push(view);
  24498. zr.add(view.group);
  24499. }
  24500. model.__viewId = view.__id = viewId;
  24501. view.__alive = true;
  24502. view.__model = model;
  24503. view.group.__ecComponentInfo = {
  24504. mainType: model.mainType,
  24505. index: model.componentIndex
  24506. };
  24507. !isComponent && scheduler.prepareView(view, model, ecModel, api);
  24508. }
  24509. for (var i = 0; i < viewList.length;) {
  24510. var view = viewList[i];
  24511. if (!view.__alive) {
  24512. !isComponent && view.renderTask.dispose();
  24513. zr.remove(view.group);
  24514. view.dispose(ecModel, api);
  24515. viewList.splice(i, 1);
  24516. delete viewMap[view.__id];
  24517. view.__id = view.group.__ecComponentInfo = null;
  24518. }
  24519. else {
  24520. i++;
  24521. }
  24522. }
  24523. }
  24524. // /**
  24525. // * Encode visual infomation from data after data processing
  24526. // *
  24527. // * @param {module:echarts/model/Global} ecModel
  24528. // * @param {object} layout
  24529. // * @param {boolean} [layoutFilter] `true`: only layout,
  24530. // * `false`: only not layout,
  24531. // * `null`/`undefined`: all.
  24532. // * @param {string} taskBaseTag
  24533. // * @private
  24534. // */
  24535. // function startVisualEncoding(ecIns, ecModel, api, payload, layoutFilter) {
  24536. // each(visualFuncs, function (visual, index) {
  24537. // var isLayout = visual.isLayout;
  24538. // if (layoutFilter == null
  24539. // || (layoutFilter === false && !isLayout)
  24540. // || (layoutFilter === true && isLayout)
  24541. // ) {
  24542. // visual.func(ecModel, api, payload);
  24543. // }
  24544. // });
  24545. // }
  24546. function clearColorPalette(ecModel) {
  24547. ecModel.clearColorPalette();
  24548. ecModel.eachSeries(function (seriesModel) {
  24549. seriesModel.clearColorPalette();
  24550. });
  24551. }
  24552. function render(ecIns, ecModel, api, payload) {
  24553. renderComponents(ecIns, ecModel, api, payload);
  24554. each(ecIns._chartsViews, function (chart) {
  24555. chart.__alive = false;
  24556. });
  24557. renderSeries(ecIns, ecModel, api, payload);
  24558. // Remove groups of unrendered charts
  24559. each(ecIns._chartsViews, function (chart) {
  24560. if (!chart.__alive) {
  24561. chart.remove(ecModel, api);
  24562. }
  24563. });
  24564. }
  24565. function renderComponents(ecIns, ecModel, api, payload, dirtyList) {
  24566. each(dirtyList || ecIns._componentsViews, function (componentView) {
  24567. var componentModel = componentView.__model;
  24568. componentView.render(componentModel, ecModel, api, payload);
  24569. updateZ(componentModel, componentView);
  24570. });
  24571. }
  24572. /**
  24573. * Render each chart and component
  24574. * @private
  24575. */
  24576. function renderSeries(ecIns, ecModel, api, payload, dirtyMap) {
  24577. // Render all charts
  24578. var scheduler = ecIns._scheduler;
  24579. var unfinished;
  24580. ecModel.eachSeries(function (seriesModel) {
  24581. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  24582. chartView.__alive = true;
  24583. var renderTask = chartView.renderTask;
  24584. scheduler.updatePayload(renderTask, payload);
  24585. if (dirtyMap && dirtyMap.get(seriesModel.uid)) {
  24586. renderTask.dirty();
  24587. }
  24588. unfinished |= renderTask.perform(scheduler.getPerformArgs(renderTask));
  24589. chartView.group.silent = !!seriesModel.get('silent');
  24590. updateZ(seriesModel, chartView);
  24591. updateBlend(seriesModel, chartView);
  24592. });
  24593. scheduler.unfinished |= unfinished;
  24594. // If use hover layer
  24595. updateHoverLayerStatus(ecIns._zr, ecModel);
  24596. // Add aria
  24597. aria(ecIns._zr.dom, ecModel);
  24598. }
  24599. function performPostUpdateFuncs(ecModel, api) {
  24600. each(postUpdateFuncs, function (func) {
  24601. func(ecModel, api);
  24602. });
  24603. }
  24604. var MOUSE_EVENT_NAMES = [
  24605. 'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
  24606. 'mousedown', 'mouseup', 'globalout', 'contextmenu'
  24607. ];
  24608. /**
  24609. * @private
  24610. */
  24611. echartsProto._initEvents = function () {
  24612. each(MOUSE_EVENT_NAMES, function (eveName) {
  24613. var handler = function (e) {
  24614. var ecModel = this.getModel();
  24615. var el = e.target;
  24616. var params;
  24617. var isGlobalOut = eveName === 'globalout';
  24618. // no e.target when 'globalout'.
  24619. if (isGlobalOut) {
  24620. params = {};
  24621. }
  24622. else if (el && el.dataIndex != null) {
  24623. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  24624. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType, el) || {};
  24625. }
  24626. // If element has custom eventData of components
  24627. else if (el && el.eventData) {
  24628. params = extend({}, el.eventData);
  24629. }
  24630. // Contract: if params prepared in mouse event,
  24631. // these properties must be specified:
  24632. // {
  24633. // componentType: string (component main type)
  24634. // componentIndex: number
  24635. // }
  24636. // Otherwise event query can not work.
  24637. if (params) {
  24638. var componentType = params.componentType;
  24639. var componentIndex = params.componentIndex;
  24640. // Special handling for historic reason: when trigger by
  24641. // markLine/markPoint/markArea, the componentType is
  24642. // 'markLine'/'markPoint'/'markArea', but we should better
  24643. // enable them to be queried by seriesIndex, since their
  24644. // option is set in each series.
  24645. if (componentType === 'markLine'
  24646. || componentType === 'markPoint'
  24647. || componentType === 'markArea'
  24648. ) {
  24649. componentType = 'series';
  24650. componentIndex = params.seriesIndex;
  24651. }
  24652. var model = componentType && componentIndex != null
  24653. && ecModel.getComponent(componentType, componentIndex);
  24654. var view = model && this[
  24655. model.mainType === 'series' ? '_chartsMap' : '_componentsMap'
  24656. ][model.__viewId];
  24657. if (__DEV__) {
  24658. // `event.componentType` and `event[componentTpype + 'Index']` must not
  24659. // be missed, otherwise there is no way to distinguish source component.
  24660. // See `dataFormat.getDataParams`.
  24661. if (!isGlobalOut && !(model && view)) {
  24662. console.warn('model or view can not be found by params');
  24663. }
  24664. }
  24665. params.event = e;
  24666. params.type = eveName;
  24667. this._ecEventProcessor.eventInfo = {
  24668. targetEl: el,
  24669. packedEvent: params,
  24670. model: model,
  24671. view: view
  24672. };
  24673. this.trigger(eveName, params);
  24674. }
  24675. };
  24676. // Consider that some component (like tooltip, brush, ...)
  24677. // register zr event handler, but user event handler might
  24678. // do anything, such as call `setOption` or `dispatchAction`,
  24679. // which probably update any of the content and probably
  24680. // cause problem if it is called previous other inner handlers.
  24681. handler.zrEventfulCallAtLast = true;
  24682. this._zr.on(eveName, handler, this);
  24683. }, this);
  24684. each(eventActionMap, function (actionType, eventType) {
  24685. this._messageCenter.on(eventType, function (event) {
  24686. this.trigger(eventType, event);
  24687. }, this);
  24688. }, this);
  24689. };
  24690. /**
  24691. * @return {boolean}
  24692. */
  24693. echartsProto.isDisposed = function () {
  24694. return this._disposed;
  24695. };
  24696. /**
  24697. * Clear
  24698. */
  24699. echartsProto.clear = function () {
  24700. this.setOption({ series: [] }, true);
  24701. };
  24702. /**
  24703. * Dispose instance
  24704. */
  24705. echartsProto.dispose = function () {
  24706. if (this._disposed) {
  24707. if (__DEV__) {
  24708. console.warn('Instance ' + this.id + ' has been disposed');
  24709. }
  24710. return;
  24711. }
  24712. this._disposed = true;
  24713. setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
  24714. var api = this._api;
  24715. var ecModel = this._model;
  24716. each(this._componentsViews, function (component) {
  24717. component.dispose(ecModel, api);
  24718. });
  24719. each(this._chartsViews, function (chart) {
  24720. chart.dispose(ecModel, api);
  24721. });
  24722. // Dispose after all views disposed
  24723. this._zr.dispose();
  24724. delete instances[this.id];
  24725. };
  24726. mixin(ECharts, Eventful);
  24727. function updateHoverLayerStatus(zr, ecModel) {
  24728. var storage = zr.storage;
  24729. var elCount = 0;
  24730. storage.traverse(function (el) {
  24731. if (!el.isGroup) {
  24732. elCount++;
  24733. }
  24734. });
  24735. if (elCount > ecModel.get('hoverLayerThreshold') && !env$1.node) {
  24736. storage.traverse(function (el) {
  24737. if (!el.isGroup) {
  24738. // Don't switch back.
  24739. el.useHoverLayer = true;
  24740. }
  24741. });
  24742. }
  24743. }
  24744. /**
  24745. * Update chart progressive and blend.
  24746. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  24747. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  24748. */
  24749. function updateBlend(seriesModel, chartView) {
  24750. var blendMode = seriesModel.get('blendMode') || null;
  24751. if (__DEV__) {
  24752. if (!env$1.canvasSupported && blendMode && blendMode !== 'source-over') {
  24753. console.warn('Only canvas support blendMode');
  24754. }
  24755. }
  24756. chartView.group.traverse(function (el) {
  24757. // FIXME marker and other components
  24758. if (!el.isGroup) {
  24759. // Only set if blendMode is changed. In case element is incremental and don't wan't to rerender.
  24760. if (el.style.blend !== blendMode) {
  24761. el.setStyle('blend', blendMode);
  24762. }
  24763. }
  24764. if (el.eachPendingDisplayable) {
  24765. el.eachPendingDisplayable(function (displayable) {
  24766. displayable.setStyle('blend', blendMode);
  24767. });
  24768. }
  24769. });
  24770. }
  24771. /**
  24772. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  24773. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  24774. */
  24775. function updateZ(model, view) {
  24776. var z = model.get('z');
  24777. var zlevel = model.get('zlevel');
  24778. // Set z and zlevel
  24779. view.group.traverse(function (el) {
  24780. if (el.type !== 'group') {
  24781. z != null && (el.z = z);
  24782. zlevel != null && (el.zlevel = zlevel);
  24783. }
  24784. });
  24785. }
  24786. function createExtensionAPI(ecInstance) {
  24787. var coordSysMgr = ecInstance._coordSysMgr;
  24788. return extend(new ExtensionAPI(ecInstance), {
  24789. // Inject methods
  24790. getCoordinateSystems: bind(
  24791. coordSysMgr.getCoordinateSystems, coordSysMgr
  24792. ),
  24793. getComponentByElement: function (el) {
  24794. while (el) {
  24795. var modelInfo = el.__ecComponentInfo;
  24796. if (modelInfo != null) {
  24797. return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
  24798. }
  24799. el = el.parent;
  24800. }
  24801. }
  24802. });
  24803. }
  24804. /**
  24805. * @class
  24806. * Usage of query:
  24807. * `chart.on('click', query, handler);`
  24808. * The `query` can be:
  24809. * + The component type query string, only `mainType` or `mainType.subType`,
  24810. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  24811. * + The component query object, like:
  24812. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  24813. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  24814. * + The data query object, like:
  24815. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  24816. * + The other query object (cmponent customized query), like:
  24817. * `{element: 'some'}` (only available in custom series).
  24818. *
  24819. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  24820. * same as there is no such prop in the `query` object.
  24821. */
  24822. function EventProcessor() {
  24823. // These info required: targetEl, packedEvent, model, view
  24824. this.eventInfo;
  24825. }
  24826. EventProcessor.prototype = {
  24827. constructor: EventProcessor,
  24828. normalizeQuery: function (query) {
  24829. var cptQuery = {};
  24830. var dataQuery = {};
  24831. var otherQuery = {};
  24832. // `query` is `mainType` or `mainType.subType` of component.
  24833. if (isString(query)) {
  24834. var condCptType = parseClassType(query);
  24835. // `.main` and `.sub` may be ''.
  24836. cptQuery.mainType = condCptType.main || null;
  24837. cptQuery.subType = condCptType.sub || null;
  24838. }
  24839. // `query` is an object, convert to {mainType, index, name, id}.
  24840. else {
  24841. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  24842. // can not be used in `compomentModel.filterForExposedEvent`.
  24843. var suffixes = ['Index', 'Name', 'Id'];
  24844. var dataKeys = {name: 1, dataIndex: 1, dataType: 1};
  24845. each$1(query, function (val, key) {
  24846. var reserved = false;
  24847. for (var i = 0; i < suffixes.length; i++) {
  24848. var propSuffix = suffixes[i];
  24849. var suffixPos = key.lastIndexOf(propSuffix);
  24850. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  24851. var mainType = key.slice(0, suffixPos);
  24852. // Consider `dataIndex`.
  24853. if (mainType !== 'data') {
  24854. cptQuery.mainType = mainType;
  24855. cptQuery[propSuffix.toLowerCase()] = val;
  24856. reserved = true;
  24857. }
  24858. }
  24859. }
  24860. if (dataKeys.hasOwnProperty(key)) {
  24861. dataQuery[key] = val;
  24862. reserved = true;
  24863. }
  24864. if (!reserved) {
  24865. otherQuery[key] = val;
  24866. }
  24867. });
  24868. }
  24869. return {
  24870. cptQuery: cptQuery,
  24871. dataQuery: dataQuery,
  24872. otherQuery: otherQuery
  24873. };
  24874. },
  24875. filter: function (eventType, query, args) {
  24876. // They should be assigned before each trigger call.
  24877. var eventInfo = this.eventInfo;
  24878. if (!eventInfo) {
  24879. return true;
  24880. }
  24881. var targetEl = eventInfo.targetEl;
  24882. var packedEvent = eventInfo.packedEvent;
  24883. var model = eventInfo.model;
  24884. var view = eventInfo.view;
  24885. // For event like 'globalout'.
  24886. if (!model || !view) {
  24887. return true;
  24888. }
  24889. var cptQuery = query.cptQuery;
  24890. var dataQuery = query.dataQuery;
  24891. return check(cptQuery, model, 'mainType')
  24892. && check(cptQuery, model, 'subType')
  24893. && check(cptQuery, model, 'index', 'componentIndex')
  24894. && check(cptQuery, model, 'name')
  24895. && check(cptQuery, model, 'id')
  24896. && check(dataQuery, packedEvent, 'name')
  24897. && check(dataQuery, packedEvent, 'dataIndex')
  24898. && check(dataQuery, packedEvent, 'dataType')
  24899. && (!view.filterForExposedEvent || view.filterForExposedEvent(
  24900. eventType, query.otherQuery, targetEl, packedEvent
  24901. ));
  24902. function check(query, host, prop, propOnHost) {
  24903. return query[prop] == null || host[propOnHost || prop] === query[prop];
  24904. }
  24905. },
  24906. afterTrigger: function () {
  24907. // Make sure the eventInfo wont be used in next trigger.
  24908. this.eventInfo = null;
  24909. }
  24910. };
  24911. /**
  24912. * @type {Object} key: actionType.
  24913. * @inner
  24914. */
  24915. var actions = {};
  24916. /**
  24917. * Map eventType to actionType
  24918. * @type {Object}
  24919. */
  24920. var eventActionMap = {};
  24921. /**
  24922. * Data processor functions of each stage
  24923. * @type {Array.<Object.<string, Function>>}
  24924. * @inner
  24925. */
  24926. var dataProcessorFuncs = [];
  24927. /**
  24928. * @type {Array.<Function>}
  24929. * @inner
  24930. */
  24931. var optionPreprocessorFuncs = [];
  24932. /**
  24933. * @type {Array.<Function>}
  24934. * @inner
  24935. */
  24936. var postUpdateFuncs = [];
  24937. /**
  24938. * Visual encoding functions of each stage
  24939. * @type {Array.<Object.<string, Function>>}
  24940. */
  24941. var visualFuncs = [];
  24942. /**
  24943. * Theme storage
  24944. * @type {Object.<key, Object>}
  24945. */
  24946. var themeStorage = {};
  24947. /**
  24948. * Loading effects
  24949. */
  24950. var loadingEffects = {};
  24951. var instances = {};
  24952. var connectedGroups = {};
  24953. var idBase = new Date() - 0;
  24954. var groupIdBase = new Date() - 0;
  24955. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  24956. function enableConnect(chart) {
  24957. var STATUS_PENDING = 0;
  24958. var STATUS_UPDATING = 1;
  24959. var STATUS_UPDATED = 2;
  24960. var STATUS_KEY = '__connectUpdateStatus';
  24961. function updateConnectedChartsStatus(charts, status) {
  24962. for (var i = 0; i < charts.length; i++) {
  24963. var otherChart = charts[i];
  24964. otherChart[STATUS_KEY] = status;
  24965. }
  24966. }
  24967. each(eventActionMap, function (actionType, eventType) {
  24968. chart._messageCenter.on(eventType, function (event) {
  24969. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  24970. if (event && event.escapeConnect) {
  24971. return;
  24972. }
  24973. var action = chart.makeActionFromEvent(event);
  24974. var otherCharts = [];
  24975. each(instances, function (otherChart) {
  24976. if (otherChart !== chart && otherChart.group === chart.group) {
  24977. otherCharts.push(otherChart);
  24978. }
  24979. });
  24980. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  24981. each(otherCharts, function (otherChart) {
  24982. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  24983. otherChart.dispatchAction(action);
  24984. }
  24985. });
  24986. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  24987. }
  24988. });
  24989. });
  24990. }
  24991. /**
  24992. * @param {HTMLElement} dom
  24993. * @param {Object} [theme]
  24994. * @param {Object} opts
  24995. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  24996. * @param {string} [opts.renderer] Currently only 'canvas' is supported.
  24997. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  24998. * Can be 'auto' (the same as null/undefined)
  24999. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  25000. * Can be 'auto' (the same as null/undefined)
  25001. */
  25002. function init(dom, theme$$1, opts) {
  25003. if (__DEV__) {
  25004. // Check version
  25005. if ((version$1.replace('.', '') - 0) < (dependencies.zrender.replace('.', '') - 0)) {
  25006. throw new Error(
  25007. 'zrender/src ' + version$1
  25008. + ' is too old for ECharts ' + version
  25009. + '. Current version need ZRender '
  25010. + dependencies.zrender + '+'
  25011. );
  25012. }
  25013. if (!dom) {
  25014. throw new Error('Initialize failed: invalid dom.');
  25015. }
  25016. }
  25017. var existInstance = getInstanceByDom(dom);
  25018. if (existInstance) {
  25019. if (__DEV__) {
  25020. console.warn('There is a chart instance already initialized on the dom.');
  25021. }
  25022. return existInstance;
  25023. }
  25024. if (__DEV__) {
  25025. if (isDom(dom)
  25026. && dom.nodeName.toUpperCase() !== 'CANVAS'
  25027. && (
  25028. (!dom.clientWidth && (!opts || opts.width == null))
  25029. || (!dom.clientHeight && (!opts || opts.height == null))
  25030. )
  25031. ) {
  25032. console.warn('Can\'t get dom width or height');
  25033. }
  25034. }
  25035. var chart = new ECharts(dom, theme$$1, opts);
  25036. chart.id = 'ec_' + idBase++;
  25037. instances[chart.id] = chart;
  25038. setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);
  25039. enableConnect(chart);
  25040. return chart;
  25041. }
  25042. /**
  25043. * @return {string|Array.<module:echarts~ECharts>} groupId
  25044. */
  25045. function connect(groupId) {
  25046. // Is array of charts
  25047. if (isArray(groupId)) {
  25048. var charts = groupId;
  25049. groupId = null;
  25050. // If any chart has group
  25051. each(charts, function (chart) {
  25052. if (chart.group != null) {
  25053. groupId = chart.group;
  25054. }
  25055. });
  25056. groupId = groupId || ('g_' + groupIdBase++);
  25057. each(charts, function (chart) {
  25058. chart.group = groupId;
  25059. });
  25060. }
  25061. connectedGroups[groupId] = true;
  25062. return groupId;
  25063. }
  25064. /**
  25065. * @DEPRECATED
  25066. * @return {string} groupId
  25067. */
  25068. function disConnect(groupId) {
  25069. connectedGroups[groupId] = false;
  25070. }
  25071. /**
  25072. * @return {string} groupId
  25073. */
  25074. var disconnect = disConnect;
  25075. /**
  25076. * Dispose a chart instance
  25077. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  25078. */
  25079. function dispose(chart) {
  25080. if (typeof chart === 'string') {
  25081. chart = instances[chart];
  25082. }
  25083. else if (!(chart instanceof ECharts)) {
  25084. // Try to treat as dom
  25085. chart = getInstanceByDom(chart);
  25086. }
  25087. if ((chart instanceof ECharts) && !chart.isDisposed()) {
  25088. chart.dispose();
  25089. }
  25090. }
  25091. /**
  25092. * @param {HTMLElement} dom
  25093. * @return {echarts~ECharts}
  25094. */
  25095. function getInstanceByDom(dom) {
  25096. return instances[getAttribute(dom, DOM_ATTRIBUTE_KEY)];
  25097. }
  25098. /**
  25099. * @param {string} key
  25100. * @return {echarts~ECharts}
  25101. */
  25102. function getInstanceById(key) {
  25103. return instances[key];
  25104. }
  25105. /**
  25106. * Register theme
  25107. */
  25108. function registerTheme(name, theme$$1) {
  25109. themeStorage[name] = theme$$1;
  25110. }
  25111. /**
  25112. * Register option preprocessor
  25113. * @param {Function} preprocessorFunc
  25114. */
  25115. function registerPreprocessor(preprocessorFunc) {
  25116. optionPreprocessorFuncs.push(preprocessorFunc);
  25117. }
  25118. /**
  25119. * @param {number} [priority=1000]
  25120. * @param {Object|Function} processor
  25121. */
  25122. function registerProcessor(priority, processor) {
  25123. normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_FILTER);
  25124. }
  25125. /**
  25126. * Register postUpdater
  25127. * @param {Function} postUpdateFunc
  25128. */
  25129. function registerPostUpdate(postUpdateFunc) {
  25130. postUpdateFuncs.push(postUpdateFunc);
  25131. }
  25132. /**
  25133. * Usage:
  25134. * registerAction('someAction', 'someEvent', function () { ... });
  25135. * registerAction('someAction', function () { ... });
  25136. * registerAction(
  25137. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  25138. * function () { ... }
  25139. * );
  25140. *
  25141. * @param {(string|Object)} actionInfo
  25142. * @param {string} actionInfo.type
  25143. * @param {string} [actionInfo.event]
  25144. * @param {string} [actionInfo.update]
  25145. * @param {string} [eventName]
  25146. * @param {Function} action
  25147. */
  25148. function registerAction(actionInfo, eventName, action) {
  25149. if (typeof eventName === 'function') {
  25150. action = eventName;
  25151. eventName = '';
  25152. }
  25153. var actionType = isObject(actionInfo)
  25154. ? actionInfo.type
  25155. : ([actionInfo, actionInfo = {
  25156. event: eventName
  25157. }][0]);
  25158. // Event name is all lowercase
  25159. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  25160. eventName = actionInfo.event;
  25161. // Validate action type and event name.
  25162. assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  25163. if (!actions[actionType]) {
  25164. actions[actionType] = {action: action, actionInfo: actionInfo};
  25165. }
  25166. eventActionMap[eventName] = actionType;
  25167. }
  25168. /**
  25169. * @param {string} type
  25170. * @param {*} CoordinateSystem
  25171. */
  25172. function registerCoordinateSystem(type, CoordinateSystem$$1) {
  25173. CoordinateSystemManager.register(type, CoordinateSystem$$1);
  25174. }
  25175. /**
  25176. * Get dimensions of specified coordinate system.
  25177. * @param {string} type
  25178. * @return {Array.<string|Object>}
  25179. */
  25180. function getCoordinateSystemDimensions(type) {
  25181. var coordSysCreator = CoordinateSystemManager.get(type);
  25182. if (coordSysCreator) {
  25183. return coordSysCreator.getDimensionsInfo
  25184. ? coordSysCreator.getDimensionsInfo()
  25185. : coordSysCreator.dimensions.slice();
  25186. }
  25187. }
  25188. /**
  25189. * Layout is a special stage of visual encoding
  25190. * Most visual encoding like color are common for different chart
  25191. * But each chart has it's own layout algorithm
  25192. *
  25193. * @param {number} [priority=1000]
  25194. * @param {Function} layoutTask
  25195. */
  25196. function registerLayout(priority, layoutTask) {
  25197. normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');
  25198. }
  25199. /**
  25200. * @param {number} [priority=3000]
  25201. * @param {module:echarts/stream/Task} visualTask
  25202. */
  25203. function registerVisual(priority, visualTask) {
  25204. normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');
  25205. }
  25206. /**
  25207. * @param {Object|Function} fn: {seriesType, createOnAllSeries, performRawSeries, reset}
  25208. */
  25209. function normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {
  25210. if (isFunction(priority) || isObject(priority)) {
  25211. fn = priority;
  25212. priority = defaultPriority;
  25213. }
  25214. if (__DEV__) {
  25215. if (isNaN(priority) || priority == null) {
  25216. throw new Error('Illegal priority');
  25217. }
  25218. // Check duplicate
  25219. each(targetList, function (wrap) {
  25220. assert(wrap.__raw !== fn);
  25221. });
  25222. }
  25223. var stageHandler = Scheduler.wrapStageHandler(fn, visualType);
  25224. stageHandler.__prio = priority;
  25225. stageHandler.__raw = fn;
  25226. targetList.push(stageHandler);
  25227. return stageHandler;
  25228. }
  25229. /**
  25230. * @param {string} name
  25231. */
  25232. function registerLoading(name, loadingFx) {
  25233. loadingEffects[name] = loadingFx;
  25234. }
  25235. /**
  25236. * @param {Object} opts
  25237. * @param {string} [superClass]
  25238. */
  25239. function extendComponentModel(opts/*, superClass*/) {
  25240. // var Clazz = ComponentModel;
  25241. // if (superClass) {
  25242. // var classType = parseClassType(superClass);
  25243. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  25244. // }
  25245. return ComponentModel.extend(opts);
  25246. }
  25247. /**
  25248. * @param {Object} opts
  25249. * @param {string} [superClass]
  25250. */
  25251. function extendComponentView(opts/*, superClass*/) {
  25252. // var Clazz = ComponentView;
  25253. // if (superClass) {
  25254. // var classType = parseClassType(superClass);
  25255. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  25256. // }
  25257. return Component.extend(opts);
  25258. }
  25259. /**
  25260. * @param {Object} opts
  25261. * @param {string} [superClass]
  25262. */
  25263. function extendSeriesModel(opts/*, superClass*/) {
  25264. // var Clazz = SeriesModel;
  25265. // if (superClass) {
  25266. // superClass = 'series.' + superClass.replace('series.', '');
  25267. // var classType = parseClassType(superClass);
  25268. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  25269. // }
  25270. return SeriesModel.extend(opts);
  25271. }
  25272. /**
  25273. * @param {Object} opts
  25274. * @param {string} [superClass]
  25275. */
  25276. function extendChartView(opts/*, superClass*/) {
  25277. // var Clazz = ChartView;
  25278. // if (superClass) {
  25279. // superClass = superClass.replace('series.', '');
  25280. // var classType = parseClassType(superClass);
  25281. // Clazz = ChartView.getClass(classType.main, true);
  25282. // }
  25283. return Chart.extend(opts);
  25284. }
  25285. /**
  25286. * ZRender need a canvas context to do measureText.
  25287. * But in node environment canvas may be created by node-canvas.
  25288. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  25289. *
  25290. * Be careful of using it in the browser.
  25291. *
  25292. * @param {Function} creator
  25293. * @example
  25294. * var Canvas = require('canvas');
  25295. * var echarts = require('echarts');
  25296. * echarts.setCanvasCreator(function () {
  25297. * // Small size is enough.
  25298. * return new Canvas(32, 32);
  25299. * });
  25300. */
  25301. function setCanvasCreator(creator) {
  25302. $override('createCanvas', creator);
  25303. }
  25304. /**
  25305. * @param {string} mapName
  25306. * @param {Array.<Object>|Object|string} geoJson
  25307. * @param {Object} [specialAreas]
  25308. *
  25309. * @example GeoJSON
  25310. * $.get('USA.json', function (geoJson) {
  25311. * echarts.registerMap('USA', geoJson);
  25312. * // Or
  25313. * echarts.registerMap('USA', {
  25314. * geoJson: geoJson,
  25315. * specialAreas: {}
  25316. * })
  25317. * });
  25318. *
  25319. * $.get('airport.svg', function (svg) {
  25320. * echarts.registerMap('airport', {
  25321. * svg: svg
  25322. * }
  25323. * });
  25324. *
  25325. * echarts.registerMap('eu', [
  25326. * {svg: eu-topographic.svg},
  25327. * {geoJSON: eu.json}
  25328. * ])
  25329. */
  25330. function registerMap(mapName, geoJson, specialAreas) {
  25331. mapDataStorage.registerMap(mapName, geoJson, specialAreas);
  25332. }
  25333. /**
  25334. * @param {string} mapName
  25335. * @return {Object}
  25336. */
  25337. function getMap(mapName) {
  25338. // For backward compatibility, only return the first one.
  25339. var records = mapDataStorage.retrieveMap(mapName);
  25340. return records && records[0] && {
  25341. geoJson: records[0].geoJSON,
  25342. specialAreas: records[0].specialAreas
  25343. };
  25344. }
  25345. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesColor);
  25346. registerPreprocessor(backwardCompat);
  25347. registerProcessor(PRIORITY_PROCESSOR_STATISTIC, dataStack);
  25348. registerLoading('default', loadingDefault);
  25349. // Default actions
  25350. registerAction({
  25351. type: 'highlight',
  25352. event: 'highlight',
  25353. update: 'highlight'
  25354. }, noop);
  25355. registerAction({
  25356. type: 'downplay',
  25357. event: 'downplay',
  25358. update: 'downplay'
  25359. }, noop);
  25360. // Default theme
  25361. registerTheme('light', lightTheme);
  25362. registerTheme('dark', theme);
  25363. // For backward compatibility, where the namespace `dataTool` will
  25364. // be mounted on `echarts` is the extension `dataTool` is imported.
  25365. var dataTool = {};
  25366. /*
  25367. * Licensed to the Apache Software Foundation (ASF) under one
  25368. * or more contributor license agreements. See the NOTICE file
  25369. * distributed with this work for additional information
  25370. * regarding copyright ownership. The ASF licenses this file
  25371. * to you under the Apache License, Version 2.0 (the
  25372. * "License"); you may not use this file except in compliance
  25373. * with the License. You may obtain a copy of the License at
  25374. *
  25375. * http://www.apache.org/licenses/LICENSE-2.0
  25376. *
  25377. * Unless required by applicable law or agreed to in writing,
  25378. * software distributed under the License is distributed on an
  25379. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25380. * KIND, either express or implied. See the License for the
  25381. * specific language governing permissions and limitations
  25382. * under the License.
  25383. */
  25384. function defaultKeyGetter(item) {
  25385. return item;
  25386. }
  25387. /**
  25388. * @param {Array} oldArr
  25389. * @param {Array} newArr
  25390. * @param {Function} oldKeyGetter
  25391. * @param {Function} newKeyGetter
  25392. * @param {Object} [context] Can be visited by this.context in callback.
  25393. */
  25394. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context) {
  25395. this._old = oldArr;
  25396. this._new = newArr;
  25397. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  25398. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  25399. this.context = context;
  25400. }
  25401. DataDiffer.prototype = {
  25402. constructor: DataDiffer,
  25403. /**
  25404. * Callback function when add a data
  25405. */
  25406. add: function (func) {
  25407. this._add = func;
  25408. return this;
  25409. },
  25410. /**
  25411. * Callback function when update a data
  25412. */
  25413. update: function (func) {
  25414. this._update = func;
  25415. return this;
  25416. },
  25417. /**
  25418. * Callback function when remove a data
  25419. */
  25420. remove: function (func) {
  25421. this._remove = func;
  25422. return this;
  25423. },
  25424. execute: function () {
  25425. var oldArr = this._old;
  25426. var newArr = this._new;
  25427. var oldDataIndexMap = {};
  25428. var newDataIndexMap = {};
  25429. var oldDataKeyArr = [];
  25430. var newDataKeyArr = [];
  25431. var i;
  25432. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter', this);
  25433. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter', this);
  25434. // Travel by inverted order to make sure order consistency
  25435. // when duplicate keys exists (consider newDataIndex.pop() below).
  25436. // For performance consideration, these code below do not look neat.
  25437. for (i = 0; i < oldArr.length; i++) {
  25438. var key = oldDataKeyArr[i];
  25439. var idx = newDataIndexMap[key];
  25440. // idx can never be empty array here. see 'set null' logic below.
  25441. if (idx != null) {
  25442. // Consider there is duplicate key (for example, use dataItem.name as key).
  25443. // We should make sure every item in newArr and oldArr can be visited.
  25444. var len = idx.length;
  25445. if (len) {
  25446. len === 1 && (newDataIndexMap[key] = null);
  25447. idx = idx.unshift();
  25448. }
  25449. else {
  25450. newDataIndexMap[key] = null;
  25451. }
  25452. this._update && this._update(idx, i);
  25453. }
  25454. else {
  25455. this._remove && this._remove(i);
  25456. }
  25457. }
  25458. for (var i = 0; i < newDataKeyArr.length; i++) {
  25459. var key = newDataKeyArr[i];
  25460. if (newDataIndexMap.hasOwnProperty(key)) {
  25461. var idx = newDataIndexMap[key];
  25462. if (idx == null) {
  25463. continue;
  25464. }
  25465. // idx can never be empty array here. see 'set null' logic above.
  25466. if (!idx.length) {
  25467. this._add && this._add(idx);
  25468. }
  25469. else {
  25470. for (var j = 0, len = idx.length; j < len; j++) {
  25471. this._add && this._add(idx[j]);
  25472. }
  25473. }
  25474. }
  25475. }
  25476. }
  25477. };
  25478. function initIndexMap(arr, map, keyArr, keyGetterName, dataDiffer) {
  25479. for (var i = 0; i < arr.length; i++) {
  25480. // Add prefix to avoid conflict with Object.prototype.
  25481. var key = '_ec_' + dataDiffer[keyGetterName](arr[i], i);
  25482. var existence = map[key];
  25483. if (existence == null) {
  25484. keyArr.push(key);
  25485. map[key] = i;
  25486. }
  25487. else {
  25488. if (!existence.length) {
  25489. map[key] = existence = [existence];
  25490. }
  25491. existence.push(i);
  25492. }
  25493. }
  25494. }
  25495. /*
  25496. * Licensed to the Apache Software Foundation (ASF) under one
  25497. * or more contributor license agreements. See the NOTICE file
  25498. * distributed with this work for additional information
  25499. * regarding copyright ownership. The ASF licenses this file
  25500. * to you under the Apache License, Version 2.0 (the
  25501. * "License"); you may not use this file except in compliance
  25502. * with the License. You may obtain a copy of the License at
  25503. *
  25504. * http://www.apache.org/licenses/LICENSE-2.0
  25505. *
  25506. * Unless required by applicable law or agreed to in writing,
  25507. * software distributed under the License is distributed on an
  25508. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25509. * KIND, either express or implied. See the License for the
  25510. * specific language governing permissions and limitations
  25511. * under the License.
  25512. */
  25513. var OTHER_DIMENSIONS = createHashMap([
  25514. 'tooltip', 'label', 'itemName', 'itemId', 'seriesName'
  25515. ]);
  25516. function summarizeDimensions(data) {
  25517. var summary = {};
  25518. var encode = summary.encode = {};
  25519. var notExtraCoordDimMap = createHashMap();
  25520. var defaultedLabel = [];
  25521. var defaultedTooltip = [];
  25522. each$1(data.dimensions, function (dimName) {
  25523. var dimItem = data.getDimensionInfo(dimName);
  25524. var coordDim = dimItem.coordDim;
  25525. if (coordDim) {
  25526. if (__DEV__) {
  25527. assert$1(OTHER_DIMENSIONS.get(coordDim) == null);
  25528. }
  25529. var coordDimArr = encode[coordDim];
  25530. if (!encode.hasOwnProperty(coordDim)) {
  25531. coordDimArr = encode[coordDim] = [];
  25532. }
  25533. coordDimArr[dimItem.coordDimIndex] = dimName;
  25534. if (!dimItem.isExtraCoord) {
  25535. notExtraCoordDimMap.set(coordDim, 1);
  25536. // Use the last coord dim (and label friendly) as default label,
  25537. // because when dataset is used, it is hard to guess which dimension
  25538. // can be value dimension. If both show x, y on label is not look good,
  25539. // and conventionally y axis is focused more.
  25540. if (mayLabelDimType(dimItem.type)) {
  25541. defaultedLabel[0] = dimName;
  25542. }
  25543. }
  25544. if (dimItem.defaultTooltip) {
  25545. defaultedTooltip.push(dimName);
  25546. }
  25547. }
  25548. OTHER_DIMENSIONS.each(function (v, otherDim) {
  25549. var otherDimArr = encode[otherDim];
  25550. if (!encode.hasOwnProperty(otherDim)) {
  25551. otherDimArr = encode[otherDim] = [];
  25552. }
  25553. var dimIndex = dimItem.otherDims[otherDim];
  25554. if (dimIndex != null && dimIndex !== false) {
  25555. otherDimArr[dimIndex] = dimItem.name;
  25556. }
  25557. });
  25558. });
  25559. var dataDimsOnCoord = [];
  25560. var encodeFirstDimNotExtra = {};
  25561. notExtraCoordDimMap.each(function (v, coordDim) {
  25562. var dimArr = encode[coordDim];
  25563. // ??? FIXME extra coord should not be set in dataDimsOnCoord.
  25564. // But should fix the case that radar axes: simplify the logic
  25565. // of `completeDimension`, remove `extraPrefix`.
  25566. encodeFirstDimNotExtra[coordDim] = dimArr[0];
  25567. // Not necessary to remove duplicate, because a data
  25568. // dim canot on more than one coordDim.
  25569. dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
  25570. });
  25571. summary.dataDimsOnCoord = dataDimsOnCoord;
  25572. summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
  25573. var encodeLabel = encode.label;
  25574. // FIXME `encode.label` is not recommanded, because formatter can not be set
  25575. // in this way. Use label.formatter instead. May be remove this approach someday.
  25576. if (encodeLabel && encodeLabel.length) {
  25577. defaultedLabel = encodeLabel.slice();
  25578. }
  25579. var encodeTooltip = encode.tooltip;
  25580. if (encodeTooltip && encodeTooltip.length) {
  25581. defaultedTooltip = encodeTooltip.slice();
  25582. }
  25583. else if (!defaultedTooltip.length) {
  25584. defaultedTooltip = defaultedLabel.slice();
  25585. }
  25586. encode.defaultedLabel = defaultedLabel;
  25587. encode.defaultedTooltip = defaultedTooltip;
  25588. return summary;
  25589. }
  25590. function getDimensionTypeByAxis(axisType) {
  25591. return axisType === 'category'
  25592. ? 'ordinal'
  25593. : axisType === 'time'
  25594. ? 'time'
  25595. : 'float';
  25596. }
  25597. function mayLabelDimType(dimType) {
  25598. // In most cases, ordinal and time do not suitable for label.
  25599. // Ordinal info can be displayed on axis. Time is too long.
  25600. return !(dimType === 'ordinal' || dimType === 'time');
  25601. }
  25602. // function findTheLastDimMayLabel(data) {
  25603. // // Get last value dim
  25604. // var dimensions = data.dimensions.slice();
  25605. // var valueType;
  25606. // var valueDim;
  25607. // while (dimensions.length && (
  25608. // valueDim = dimensions.pop(),
  25609. // valueType = data.getDimensionInfo(valueDim).type,
  25610. // valueType === 'ordinal' || valueType === 'time'
  25611. // )) {} // jshint ignore:line
  25612. // return valueDim;
  25613. // }
  25614. /*
  25615. * Licensed to the Apache Software Foundation (ASF) under one
  25616. * or more contributor license agreements. See the NOTICE file
  25617. * distributed with this work for additional information
  25618. * regarding copyright ownership. The ASF licenses this file
  25619. * to you under the Apache License, Version 2.0 (the
  25620. * "License"); you may not use this file except in compliance
  25621. * with the License. You may obtain a copy of the License at
  25622. *
  25623. * http://www.apache.org/licenses/LICENSE-2.0
  25624. *
  25625. * Unless required by applicable law or agreed to in writing,
  25626. * software distributed under the License is distributed on an
  25627. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25628. * KIND, either express or implied. See the License for the
  25629. * specific language governing permissions and limitations
  25630. * under the License.
  25631. */
  25632. /* global Float64Array, Int32Array, Uint32Array, Uint16Array */
  25633. /**
  25634. * List for data storage
  25635. * @module echarts/data/List
  25636. */
  25637. var isObject$4 = isObject$1;
  25638. var UNDEFINED = 'undefined';
  25639. var INDEX_NOT_FOUND = -1;
  25640. // Use prefix to avoid index to be the same as otherIdList[idx],
  25641. // which will cause weird udpate animation.
  25642. var ID_PREFIX = 'e\0\0';
  25643. var dataCtors = {
  25644. 'float': typeof Float64Array === UNDEFINED
  25645. ? Array : Float64Array,
  25646. 'int': typeof Int32Array === UNDEFINED
  25647. ? Array : Int32Array,
  25648. // Ordinal data type can be string or int
  25649. 'ordinal': Array,
  25650. 'number': Array,
  25651. 'time': Array
  25652. };
  25653. // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is
  25654. // different from the Ctor of typed array.
  25655. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
  25656. var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
  25657. var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
  25658. function getIndicesCtor(list) {
  25659. // The possible max value in this._indicies is always this._rawCount despite of filtering.
  25660. return list._rawCount > 65535 ? CtorUint32Array : CtorUint16Array;
  25661. }
  25662. function cloneChunk(originalChunk) {
  25663. var Ctor = originalChunk.constructor;
  25664. // Only shallow clone is enough when Array.
  25665. return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);
  25666. }
  25667. var TRANSFERABLE_PROPERTIES = [
  25668. 'hasItemOption', '_nameList', '_idList', '_invertedIndicesMap',
  25669. '_rawData', '_chunkSize', '_chunkCount', '_dimValueGetter',
  25670. '_count', '_rawCount', '_nameDimIdx', '_idDimIdx'
  25671. ];
  25672. var CLONE_PROPERTIES = [
  25673. '_extent', '_approximateExtent', '_rawExtent'
  25674. ];
  25675. function transferProperties(target, source) {
  25676. each$1(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {
  25677. if (source.hasOwnProperty(propName)) {
  25678. target[propName] = source[propName];
  25679. }
  25680. });
  25681. target.__wrappedMethods = source.__wrappedMethods;
  25682. each$1(CLONE_PROPERTIES, function (propName) {
  25683. target[propName] = clone(source[propName]);
  25684. });
  25685. target._calculationInfo = extend(source._calculationInfo);
  25686. }
  25687. /**
  25688. * @constructor
  25689. * @alias module:echarts/data/List
  25690. *
  25691. * @param {Array.<string|Object>} dimensions
  25692. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  25693. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  25694. * Spetial fields: {
  25695. * ordinalMeta: <module:echarts/data/OrdinalMeta>
  25696. * createInvertedIndices: <boolean>
  25697. * }
  25698. * @param {module:echarts/model/Model} hostModel
  25699. */
  25700. var List = function (dimensions, hostModel) {
  25701. dimensions = dimensions || ['x', 'y'];
  25702. var dimensionInfos = {};
  25703. var dimensionNames = [];
  25704. var invertedIndicesMap = {};
  25705. for (var i = 0; i < dimensions.length; i++) {
  25706. // Use the original dimensions[i], where other flag props may exists.
  25707. var dimensionInfo = dimensions[i];
  25708. if (isString(dimensionInfo)) {
  25709. dimensionInfo = {name: dimensionInfo};
  25710. }
  25711. var dimensionName = dimensionInfo.name;
  25712. dimensionInfo.type = dimensionInfo.type || 'float';
  25713. if (!dimensionInfo.coordDim) {
  25714. dimensionInfo.coordDim = dimensionName;
  25715. dimensionInfo.coordDimIndex = 0;
  25716. }
  25717. dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  25718. dimensionNames.push(dimensionName);
  25719. dimensionInfos[dimensionName] = dimensionInfo;
  25720. dimensionInfo.index = i;
  25721. if (dimensionInfo.createInvertedIndices) {
  25722. invertedIndicesMap[dimensionName] = [];
  25723. }
  25724. }
  25725. /**
  25726. * @readOnly
  25727. * @type {Array.<string>}
  25728. */
  25729. this.dimensions = dimensionNames;
  25730. /**
  25731. * Infomation of each data dimension, like data type.
  25732. * @type {Object}
  25733. */
  25734. this._dimensionInfos = dimensionInfos;
  25735. /**
  25736. * @type {module:echarts/model/Model}
  25737. */
  25738. this.hostModel = hostModel;
  25739. /**
  25740. * @type {module:echarts/model/Model}
  25741. */
  25742. this.dataType;
  25743. /**
  25744. * Indices stores the indices of data subset after filtered.
  25745. * This data subset will be used in chart.
  25746. * @type {Array.<number>}
  25747. * @readOnly
  25748. */
  25749. this._indices = null;
  25750. this._count = 0;
  25751. this._rawCount = 0;
  25752. /**
  25753. * Data storage
  25754. * @type {Object.<key, Array.<TypedArray|Array>>}
  25755. * @private
  25756. */
  25757. this._storage = {};
  25758. /**
  25759. * @type {Array.<string>}
  25760. */
  25761. this._nameList = [];
  25762. /**
  25763. * @type {Array.<string>}
  25764. */
  25765. this._idList = [];
  25766. /**
  25767. * Models of data option is stored sparse for optimizing memory cost
  25768. * @type {Array.<module:echarts/model/Model>}
  25769. * @private
  25770. */
  25771. this._optionModels = [];
  25772. /**
  25773. * Global visual properties after visual coding
  25774. * @type {Object}
  25775. * @private
  25776. */
  25777. this._visual = {};
  25778. /**
  25779. * Globel layout properties.
  25780. * @type {Object}
  25781. * @private
  25782. */
  25783. this._layout = {};
  25784. /**
  25785. * Item visual properties after visual coding
  25786. * @type {Array.<Object>}
  25787. * @private
  25788. */
  25789. this._itemVisuals = [];
  25790. /**
  25791. * Key: visual type, Value: boolean
  25792. * @type {Object}
  25793. * @readOnly
  25794. */
  25795. this.hasItemVisual = {};
  25796. /**
  25797. * Item layout properties after layout
  25798. * @type {Array.<Object>}
  25799. * @private
  25800. */
  25801. this._itemLayouts = [];
  25802. /**
  25803. * Graphic elemnents
  25804. * @type {Array.<module:zrender/Element>}
  25805. * @private
  25806. */
  25807. this._graphicEls = [];
  25808. /**
  25809. * Max size of each chunk.
  25810. * @type {number}
  25811. * @private
  25812. */
  25813. this._chunkSize = 1e5;
  25814. /**
  25815. * @type {number}
  25816. * @private
  25817. */
  25818. this._chunkCount = 0;
  25819. /**
  25820. * @type {Array.<Array|Object>}
  25821. * @private
  25822. */
  25823. this._rawData;
  25824. /**
  25825. * Raw extent will not be cloned, but only transfered.
  25826. * It will not be calculated util needed.
  25827. * key: dim,
  25828. * value: {end: number, extent: Array.<number>}
  25829. * @type {Object}
  25830. * @private
  25831. */
  25832. this._rawExtent = {};
  25833. /**
  25834. * @type {Object}
  25835. * @private
  25836. */
  25837. this._extent = {};
  25838. /**
  25839. * key: dim
  25840. * value: extent
  25841. * @type {Object}
  25842. * @private
  25843. */
  25844. this._approximateExtent = {};
  25845. /**
  25846. * Cache summary info for fast visit. See "dimensionHelper".
  25847. * @type {Object}
  25848. * @private
  25849. */
  25850. this._dimensionsSummary = summarizeDimensions(this);
  25851. /**
  25852. * @type {Object.<Array|TypedArray>}
  25853. * @private
  25854. */
  25855. this._invertedIndicesMap = invertedIndicesMap;
  25856. /**
  25857. * @type {Object}
  25858. * @private
  25859. */
  25860. this._calculationInfo = {};
  25861. };
  25862. var listProto = List.prototype;
  25863. listProto.type = 'list';
  25864. /**
  25865. * If each data item has it's own option
  25866. * @type {boolean}
  25867. */
  25868. listProto.hasItemOption = true;
  25869. /**
  25870. * Get dimension name
  25871. * @param {string|number} dim
  25872. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  25873. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  25874. * @return {string} Concrete dim name.
  25875. */
  25876. listProto.getDimension = function (dim) {
  25877. if (!isNaN(dim)) {
  25878. dim = this.dimensions[dim] || dim;
  25879. }
  25880. return dim;
  25881. };
  25882. /**
  25883. * Get type and calculation info of particular dimension
  25884. * @param {string|number} dim
  25885. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  25886. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  25887. */
  25888. listProto.getDimensionInfo = function (dim) {
  25889. // Do not clone, because there may be categories in dimInfo.
  25890. return this._dimensionInfos[this.getDimension(dim)];
  25891. };
  25892. /**
  25893. * @return {Array.<string>} concrete dimension name list on coord.
  25894. */
  25895. listProto.getDimensionsOnCoord = function () {
  25896. return this._dimensionsSummary.dataDimsOnCoord.slice();
  25897. };
  25898. /**
  25899. * @param {string} coordDim
  25900. * @param {number} [idx] A coordDim may map to more than one data dim.
  25901. * If idx is `true`, return a array of all mapped dims.
  25902. * If idx is not specified, return the first dim not extra.
  25903. * @return {string|Array.<string>} concrete data dim.
  25904. * If idx is number, and not found, return null/undefined.
  25905. * If idx is `true`, and not found, return empty array (always return array).
  25906. */
  25907. listProto.mapDimension = function (coordDim, idx) {
  25908. var dimensionsSummary = this._dimensionsSummary;
  25909. if (idx == null) {
  25910. return dimensionsSummary.encodeFirstDimNotExtra[coordDim];
  25911. }
  25912. var dims = dimensionsSummary.encode[coordDim];
  25913. return idx === true
  25914. // always return array if idx is `true`
  25915. ? (dims || []).slice()
  25916. : (dims && dims[idx]);
  25917. };
  25918. /**
  25919. * Initialize from data
  25920. * @param {Array.<Object|number|Array>} data source or data or data provider.
  25921. * @param {Array.<string>} [nameLIst] The name of a datum is used on data diff and
  25922. * defualt label/tooltip.
  25923. * A name can be specified in encode.itemName,
  25924. * or dataItem.name (only for series option data),
  25925. * or provided in nameList from outside.
  25926. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  25927. */
  25928. listProto.initData = function (data, nameList, dimValueGetter) {
  25929. var notProvider = Source.isInstance(data) || isArrayLike(data);
  25930. if (notProvider) {
  25931. data = new DefaultDataProvider(data, this.dimensions.length);
  25932. }
  25933. if (__DEV__) {
  25934. if (!notProvider && (typeof data.getItem !== 'function' || typeof data.count !== 'function')) {
  25935. throw new Error('Inavlid data provider.');
  25936. }
  25937. }
  25938. this._rawData = data;
  25939. // Clear
  25940. this._storage = {};
  25941. this._indices = null;
  25942. this._nameList = nameList || [];
  25943. this._idList = [];
  25944. this._nameRepeatCount = {};
  25945. if (!dimValueGetter) {
  25946. this.hasItemOption = false;
  25947. }
  25948. /**
  25949. * @readOnly
  25950. */
  25951. this.defaultDimValueGetter = defaultDimValueGetters[
  25952. this._rawData.getSource().sourceFormat
  25953. ];
  25954. // Default dim value getter
  25955. this._dimValueGetter = dimValueGetter = dimValueGetter
  25956. || this.defaultDimValueGetter;
  25957. this._dimValueGetterArrayRows = defaultDimValueGetters.arrayRows;
  25958. // Reset raw extent.
  25959. this._rawExtent = {};
  25960. this._initDataFromProvider(0, data.count());
  25961. // If data has no item option.
  25962. if (data.pure) {
  25963. this.hasItemOption = false;
  25964. }
  25965. };
  25966. listProto.getProvider = function () {
  25967. return this._rawData;
  25968. };
  25969. /**
  25970. * Caution: Can be only called on raw data (before `this._indices` created).
  25971. */
  25972. listProto.appendData = function (data) {
  25973. if (__DEV__) {
  25974. assert$1(!this._indices, 'appendData can only be called on raw data.');
  25975. }
  25976. var rawData = this._rawData;
  25977. var start = this.count();
  25978. rawData.appendData(data);
  25979. var end = rawData.count();
  25980. if (!rawData.persistent) {
  25981. end += start;
  25982. }
  25983. this._initDataFromProvider(start, end);
  25984. };
  25985. /**
  25986. * Caution: Can be only called on raw data (before `this._indices` created).
  25987. * This method does not modify `rawData` (`dataProvider`), but only
  25988. * add values to storage.
  25989. *
  25990. * The final count will be increased by `Math.max(values.length, names.length)`.
  25991. *
  25992. * @param {Array.<Array.<*>>} values That is the SourceType: 'arrayRows', like
  25993. * [
  25994. * [12, 33, 44],
  25995. * [NaN, 43, 1],
  25996. * ['-', 'asdf', 0]
  25997. * ]
  25998. * Each item is exaclty cooresponding to a dimension.
  25999. * @param {Array.<string>} [names]
  26000. */
  26001. listProto.appendValues = function (values, names) {
  26002. var chunkSize = this._chunkSize;
  26003. var storage = this._storage;
  26004. var dimensions = this.dimensions;
  26005. var dimLen = dimensions.length;
  26006. var rawExtent = this._rawExtent;
  26007. var start = this.count();
  26008. var end = start + Math.max(values.length, names ? names.length : 0);
  26009. var originalChunkCount = this._chunkCount;
  26010. for (var i = 0; i < dimLen; i++) {
  26011. var dim = dimensions[i];
  26012. if (!rawExtent[dim]) {
  26013. rawExtent[dim] = getInitialExtent();
  26014. }
  26015. if (!storage[dim]) {
  26016. storage[dim] = [];
  26017. }
  26018. prepareChunks(storage, this._dimensionInfos[dim], chunkSize, originalChunkCount, end);
  26019. this._chunkCount = storage[dim].length;
  26020. }
  26021. var emptyDataItem = new Array(dimLen);
  26022. for (var idx = start; idx < end; idx++) {
  26023. var sourceIdx = idx - start;
  26024. var chunkIndex = Math.floor(idx / chunkSize);
  26025. var chunkOffset = idx % chunkSize;
  26026. // Store the data by dimensions
  26027. for (var k = 0; k < dimLen; k++) {
  26028. var dim = dimensions[k];
  26029. var val = this._dimValueGetterArrayRows(
  26030. values[sourceIdx] || emptyDataItem, dim, sourceIdx, k
  26031. );
  26032. storage[dim][chunkIndex][chunkOffset] = val;
  26033. var dimRawExtent = rawExtent[dim];
  26034. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  26035. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  26036. }
  26037. if (names) {
  26038. this._nameList[idx] = names[sourceIdx];
  26039. }
  26040. }
  26041. this._rawCount = this._count = end;
  26042. // Reset data extent
  26043. this._extent = {};
  26044. prepareInvertedIndex(this);
  26045. };
  26046. listProto._initDataFromProvider = function (start, end) {
  26047. // Optimize.
  26048. if (start >= end) {
  26049. return;
  26050. }
  26051. var chunkSize = this._chunkSize;
  26052. var rawData = this._rawData;
  26053. var storage = this._storage;
  26054. var dimensions = this.dimensions;
  26055. var dimLen = dimensions.length;
  26056. var dimensionInfoMap = this._dimensionInfos;
  26057. var nameList = this._nameList;
  26058. var idList = this._idList;
  26059. var rawExtent = this._rawExtent;
  26060. var nameRepeatCount = this._nameRepeatCount = {};
  26061. var nameDimIdx;
  26062. var originalChunkCount = this._chunkCount;
  26063. for (var i = 0; i < dimLen; i++) {
  26064. var dim = dimensions[i];
  26065. if (!rawExtent[dim]) {
  26066. rawExtent[dim] = getInitialExtent();
  26067. }
  26068. var dimInfo = dimensionInfoMap[dim];
  26069. if (dimInfo.otherDims.itemName === 0) {
  26070. nameDimIdx = this._nameDimIdx = i;
  26071. }
  26072. if (dimInfo.otherDims.itemId === 0) {
  26073. this._idDimIdx = i;
  26074. }
  26075. if (!storage[dim]) {
  26076. storage[dim] = [];
  26077. }
  26078. prepareChunks(storage, dimInfo, chunkSize, originalChunkCount, end);
  26079. this._chunkCount = storage[dim].length;
  26080. }
  26081. var dataItem = new Array(dimLen);
  26082. for (var idx = start; idx < end; idx++) {
  26083. // NOTICE: Try not to write things into dataItem
  26084. dataItem = rawData.getItem(idx, dataItem);
  26085. // Each data item is value
  26086. // [1, 2]
  26087. // 2
  26088. // Bar chart, line chart which uses category axis
  26089. // only gives the 'y' value. 'x' value is the indices of category
  26090. // Use a tempValue to normalize the value to be a (x, y) value
  26091. var chunkIndex = Math.floor(idx / chunkSize);
  26092. var chunkOffset = idx % chunkSize;
  26093. // Store the data by dimensions
  26094. for (var k = 0; k < dimLen; k++) {
  26095. var dim = dimensions[k];
  26096. var dimStorage = storage[dim][chunkIndex];
  26097. // PENDING NULL is empty or zero
  26098. var val = this._dimValueGetter(dataItem, dim, idx, k);
  26099. dimStorage[chunkOffset] = val;
  26100. var dimRawExtent = rawExtent[dim];
  26101. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  26102. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  26103. }
  26104. // ??? FIXME not check by pure but sourceFormat?
  26105. // TODO refactor these logic.
  26106. if (!rawData.pure) {
  26107. var name = nameList[idx];
  26108. if (dataItem && name == null) {
  26109. // If dataItem is {name: ...}, it has highest priority.
  26110. // That is appropriate for many common cases.
  26111. if (dataItem.name != null) {
  26112. // There is no other place to persistent dataItem.name,
  26113. // so save it to nameList.
  26114. nameList[idx] = name = dataItem.name;
  26115. }
  26116. else if (nameDimIdx != null) {
  26117. var nameDim = dimensions[nameDimIdx];
  26118. var nameDimChunk = storage[nameDim][chunkIndex];
  26119. if (nameDimChunk) {
  26120. name = nameDimChunk[chunkOffset];
  26121. var ordinalMeta = dimensionInfoMap[nameDim].ordinalMeta;
  26122. if (ordinalMeta && ordinalMeta.categories.length) {
  26123. name = ordinalMeta.categories[name];
  26124. }
  26125. }
  26126. }
  26127. }
  26128. // Try using the id in option
  26129. // id or name is used on dynamical data, mapping old and new items.
  26130. var id = dataItem == null ? null : dataItem.id;
  26131. if (id == null && name != null) {
  26132. // Use name as id and add counter to avoid same name
  26133. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  26134. id = name;
  26135. if (nameRepeatCount[name] > 0) {
  26136. id += '__ec__' + nameRepeatCount[name];
  26137. }
  26138. nameRepeatCount[name]++;
  26139. }
  26140. id != null && (idList[idx] = id);
  26141. }
  26142. }
  26143. if (!rawData.persistent && rawData.clean) {
  26144. // Clean unused data if data source is typed array.
  26145. rawData.clean();
  26146. }
  26147. this._rawCount = this._count = end;
  26148. // Reset data extent
  26149. this._extent = {};
  26150. prepareInvertedIndex(this);
  26151. };
  26152. function prepareChunks(storage, dimInfo, chunkSize, chunkCount, end) {
  26153. var DataCtor = dataCtors[dimInfo.type];
  26154. var lastChunkIndex = chunkCount - 1;
  26155. var dim = dimInfo.name;
  26156. var resizeChunkArray = storage[dim][lastChunkIndex];
  26157. if (resizeChunkArray && resizeChunkArray.length < chunkSize) {
  26158. var newStore = new DataCtor(Math.min(end - lastChunkIndex * chunkSize, chunkSize));
  26159. // The cost of the copy is probably inconsiderable
  26160. // within the initial chunkSize.
  26161. for (var j = 0; j < resizeChunkArray.length; j++) {
  26162. newStore[j] = resizeChunkArray[j];
  26163. }
  26164. storage[dim][lastChunkIndex] = newStore;
  26165. }
  26166. // Create new chunks.
  26167. for (var k = chunkCount * chunkSize; k < end; k += chunkSize) {
  26168. storage[dim].push(new DataCtor(Math.min(end - k, chunkSize)));
  26169. }
  26170. }
  26171. function prepareInvertedIndex(list) {
  26172. var invertedIndicesMap = list._invertedIndicesMap;
  26173. each$1(invertedIndicesMap, function (invertedIndices, dim) {
  26174. var dimInfo = list._dimensionInfos[dim];
  26175. // Currently, only dimensions that has ordinalMeta can create inverted indices.
  26176. var ordinalMeta = dimInfo.ordinalMeta;
  26177. if (ordinalMeta) {
  26178. invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array(
  26179. ordinalMeta.categories.length
  26180. );
  26181. // The default value of TypedArray is 0. To avoid miss
  26182. // mapping to 0, we should set it as INDEX_NOT_FOUND.
  26183. for (var i = 0; i < invertedIndices.length; i++) {
  26184. invertedIndices[i] = INDEX_NOT_FOUND;
  26185. }
  26186. for (var i = 0; i < list._count; i++) {
  26187. // Only support the case that all values are distinct.
  26188. invertedIndices[list.get(dim, i)] = i;
  26189. }
  26190. }
  26191. });
  26192. }
  26193. function getRawValueFromStore(list, dimIndex, rawIndex) {
  26194. var val;
  26195. if (dimIndex != null) {
  26196. var chunkSize = list._chunkSize;
  26197. var chunkIndex = Math.floor(rawIndex / chunkSize);
  26198. var chunkOffset = rawIndex % chunkSize;
  26199. var dim = list.dimensions[dimIndex];
  26200. var chunk = list._storage[dim][chunkIndex];
  26201. if (chunk) {
  26202. val = chunk[chunkOffset];
  26203. var ordinalMeta = list._dimensionInfos[dim].ordinalMeta;
  26204. if (ordinalMeta && ordinalMeta.categories.length) {
  26205. val = ordinalMeta.categories[val];
  26206. }
  26207. }
  26208. }
  26209. return val;
  26210. }
  26211. /**
  26212. * @return {number}
  26213. */
  26214. listProto.count = function () {
  26215. return this._count;
  26216. };
  26217. listProto.getIndices = function () {
  26218. var newIndices;
  26219. var indices = this._indices;
  26220. if (indices) {
  26221. var Ctor = indices.constructor;
  26222. var thisCount = this._count;
  26223. // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.
  26224. if (Ctor === Array) {
  26225. newIndices = new Ctor(thisCount);
  26226. for (var i = 0; i < thisCount; i++) {
  26227. newIndices[i] = indices[i];
  26228. }
  26229. }
  26230. else {
  26231. newIndices = new Ctor(indices.buffer, 0, thisCount);
  26232. }
  26233. }
  26234. else {
  26235. var Ctor = getIndicesCtor(this);
  26236. var newIndices = new Ctor(this.count());
  26237. for (var i = 0; i < newIndices.length; i++) {
  26238. newIndices[i] = i;
  26239. }
  26240. }
  26241. return newIndices;
  26242. };
  26243. /**
  26244. * Get value. Return NaN if idx is out of range.
  26245. * @param {string} dim Dim must be concrete name.
  26246. * @param {number} idx
  26247. * @param {boolean} stack
  26248. * @return {number}
  26249. */
  26250. listProto.get = function (dim, idx /*, stack */) {
  26251. if (!(idx >= 0 && idx < this._count)) {
  26252. return NaN;
  26253. }
  26254. var storage = this._storage;
  26255. if (!storage[dim]) {
  26256. // TODO Warn ?
  26257. return NaN;
  26258. }
  26259. idx = this.getRawIndex(idx);
  26260. var chunkIndex = Math.floor(idx / this._chunkSize);
  26261. var chunkOffset = idx % this._chunkSize;
  26262. var chunkStore = storage[dim][chunkIndex];
  26263. var value = chunkStore[chunkOffset];
  26264. // FIXME ordinal data type is not stackable
  26265. // if (stack) {
  26266. // var dimensionInfo = this._dimensionInfos[dim];
  26267. // if (dimensionInfo && dimensionInfo.stackable) {
  26268. // var stackedOn = this.stackedOn;
  26269. // while (stackedOn) {
  26270. // // Get no stacked data of stacked on
  26271. // var stackedValue = stackedOn.get(dim, idx);
  26272. // // Considering positive stack, negative stack and empty data
  26273. // if ((value >= 0 && stackedValue > 0) // Positive stack
  26274. // || (value <= 0 && stackedValue < 0) // Negative stack
  26275. // ) {
  26276. // value += stackedValue;
  26277. // }
  26278. // stackedOn = stackedOn.stackedOn;
  26279. // }
  26280. // }
  26281. // }
  26282. return value;
  26283. };
  26284. /**
  26285. * @param {string} dim concrete dim
  26286. * @param {number} rawIndex
  26287. * @return {number|string}
  26288. */
  26289. listProto.getByRawIndex = function (dim, rawIdx) {
  26290. if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {
  26291. return NaN;
  26292. }
  26293. var dimStore = this._storage[dim];
  26294. if (!dimStore) {
  26295. // TODO Warn ?
  26296. return NaN;
  26297. }
  26298. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  26299. var chunkOffset = rawIdx % this._chunkSize;
  26300. var chunkStore = dimStore[chunkIndex];
  26301. return chunkStore[chunkOffset];
  26302. };
  26303. /**
  26304. * FIXME Use `get` on chrome maybe slow(in filterSelf and selectRange).
  26305. * Hack a much simpler _getFast
  26306. * @private
  26307. */
  26308. listProto._getFast = function (dim, rawIdx) {
  26309. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  26310. var chunkOffset = rawIdx % this._chunkSize;
  26311. var chunkStore = this._storage[dim][chunkIndex];
  26312. return chunkStore[chunkOffset];
  26313. };
  26314. /**
  26315. * Get value for multi dimensions.
  26316. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  26317. * @param {number} idx
  26318. * @return {number}
  26319. */
  26320. listProto.getValues = function (dimensions, idx /*, stack */) {
  26321. var values = [];
  26322. if (!isArray(dimensions)) {
  26323. // stack = idx;
  26324. idx = dimensions;
  26325. dimensions = this.dimensions;
  26326. }
  26327. for (var i = 0, len = dimensions.length; i < len; i++) {
  26328. values.push(this.get(dimensions[i], idx /*, stack */));
  26329. }
  26330. return values;
  26331. };
  26332. /**
  26333. * If value is NaN. Inlcuding '-'
  26334. * Only check the coord dimensions.
  26335. * @param {string} dim
  26336. * @param {number} idx
  26337. * @return {number}
  26338. */
  26339. listProto.hasValue = function (idx) {
  26340. var dataDimsOnCoord = this._dimensionsSummary.dataDimsOnCoord;
  26341. var dimensionInfos = this._dimensionInfos;
  26342. for (var i = 0, len = dataDimsOnCoord.length; i < len; i++) {
  26343. if (
  26344. // Ordinal type can be string or number
  26345. dimensionInfos[dataDimsOnCoord[i]].type !== 'ordinal'
  26346. // FIXME check ordinal when using index?
  26347. && isNaN(this.get(dataDimsOnCoord[i], idx))
  26348. ) {
  26349. return false;
  26350. }
  26351. }
  26352. return true;
  26353. };
  26354. /**
  26355. * Get extent of data in one dimension
  26356. * @param {string} dim
  26357. * @param {boolean} stack
  26358. */
  26359. listProto.getDataExtent = function (dim /*, stack */) {
  26360. // Make sure use concrete dim as cache name.
  26361. dim = this.getDimension(dim);
  26362. var dimData = this._storage[dim];
  26363. var initialExtent = getInitialExtent();
  26364. // stack = !!((stack || false) && this.getCalculationInfo(dim));
  26365. if (!dimData) {
  26366. return initialExtent;
  26367. }
  26368. // Make more strict checkings to ensure hitting cache.
  26369. var currEnd = this.count();
  26370. // var cacheName = [dim, !!stack].join('_');
  26371. // var cacheName = dim;
  26372. // Consider the most cases when using data zoom, `getDataExtent`
  26373. // happened before filtering. We cache raw extent, which is not
  26374. // necessary to be cleared and recalculated when restore data.
  26375. var useRaw = !this._indices; // && !stack;
  26376. var dimExtent;
  26377. if (useRaw) {
  26378. return this._rawExtent[dim].slice();
  26379. }
  26380. dimExtent = this._extent[dim];
  26381. if (dimExtent) {
  26382. return dimExtent.slice();
  26383. }
  26384. dimExtent = initialExtent;
  26385. var min = dimExtent[0];
  26386. var max = dimExtent[1];
  26387. for (var i = 0; i < currEnd; i++) {
  26388. // var value = stack ? this.get(dim, i, true) : this._getFast(dim, this.getRawIndex(i));
  26389. var value = this._getFast(dim, this.getRawIndex(i));
  26390. value < min && (min = value);
  26391. value > max && (max = value);
  26392. }
  26393. dimExtent = [min, max];
  26394. this._extent[dim] = dimExtent;
  26395. return dimExtent;
  26396. };
  26397. /**
  26398. * Optimize for the scenario that data is filtered by a given extent.
  26399. * Consider that if data amount is more than hundreds of thousand,
  26400. * extent calculation will cost more than 10ms and the cache will
  26401. * be erased because of the filtering.
  26402. */
  26403. listProto.getApproximateExtent = function (dim /*, stack */) {
  26404. dim = this.getDimension(dim);
  26405. return this._approximateExtent[dim] || this.getDataExtent(dim /*, stack */);
  26406. };
  26407. listProto.setApproximateExtent = function (extent, dim /*, stack */) {
  26408. dim = this.getDimension(dim);
  26409. this._approximateExtent[dim] = extent.slice();
  26410. };
  26411. /**
  26412. * @param {string} key
  26413. * @return {*}
  26414. */
  26415. listProto.getCalculationInfo = function (key) {
  26416. return this._calculationInfo[key];
  26417. };
  26418. /**
  26419. * @param {string|Object} key or k-v object
  26420. * @param {*} [value]
  26421. */
  26422. listProto.setCalculationInfo = function (key, value) {
  26423. isObject$4(key)
  26424. ? extend(this._calculationInfo, key)
  26425. : (this._calculationInfo[key] = value);
  26426. };
  26427. /**
  26428. * Get sum of data in one dimension
  26429. * @param {string} dim
  26430. */
  26431. listProto.getSum = function (dim /*, stack */) {
  26432. var dimData = this._storage[dim];
  26433. var sum = 0;
  26434. if (dimData) {
  26435. for (var i = 0, len = this.count(); i < len; i++) {
  26436. var value = this.get(dim, i /*, stack */);
  26437. if (!isNaN(value)) {
  26438. sum += value;
  26439. }
  26440. }
  26441. }
  26442. return sum;
  26443. };
  26444. /**
  26445. * Get median of data in one dimension
  26446. * @param {string} dim
  26447. */
  26448. listProto.getMedian = function (dim /*, stack */) {
  26449. var dimDataArray = [];
  26450. // map all data of one dimension
  26451. this.each(dim, function (val, idx) {
  26452. if (!isNaN(val)) {
  26453. dimDataArray.push(val);
  26454. }
  26455. });
  26456. // TODO
  26457. // Use quick select?
  26458. // immutability & sort
  26459. var sortedDimDataArray = [].concat(dimDataArray).sort(function (a, b) {
  26460. return a - b;
  26461. });
  26462. var len = this.count();
  26463. // calculate median
  26464. return len === 0
  26465. ? 0
  26466. : len % 2 === 1
  26467. ? sortedDimDataArray[(len - 1) / 2]
  26468. : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;
  26469. };
  26470. // /**
  26471. // * Retreive the index with given value
  26472. // * @param {string} dim Concrete dimension.
  26473. // * @param {number} value
  26474. // * @return {number}
  26475. // */
  26476. // Currently incorrect: should return dataIndex but not rawIndex.
  26477. // Do not fix it until this method is to be used somewhere.
  26478. // FIXME Precision of float value
  26479. // listProto.indexOf = function (dim, value) {
  26480. // var storage = this._storage;
  26481. // var dimData = storage[dim];
  26482. // var chunkSize = this._chunkSize;
  26483. // if (dimData) {
  26484. // for (var i = 0, len = this.count(); i < len; i++) {
  26485. // var chunkIndex = Math.floor(i / chunkSize);
  26486. // var chunkOffset = i % chunkSize;
  26487. // if (dimData[chunkIndex][chunkOffset] === value) {
  26488. // return i;
  26489. // }
  26490. // }
  26491. // }
  26492. // return -1;
  26493. // };
  26494. /**
  26495. * Only support the dimension which inverted index created.
  26496. * Do not support other cases until required.
  26497. * @param {string} concrete dim
  26498. * @param {number|string} value
  26499. * @return {number} rawIndex
  26500. */
  26501. listProto.rawIndexOf = function (dim, value) {
  26502. var invertedIndices = dim && this._invertedIndicesMap[dim];
  26503. if (__DEV__) {
  26504. if (!invertedIndices) {
  26505. throw new Error('Do not supported yet');
  26506. }
  26507. }
  26508. var rawIndex = invertedIndices[value];
  26509. if (rawIndex == null || isNaN(rawIndex)) {
  26510. return INDEX_NOT_FOUND;
  26511. }
  26512. return rawIndex;
  26513. };
  26514. /**
  26515. * Retreive the index with given name
  26516. * @param {number} idx
  26517. * @param {number} name
  26518. * @return {number}
  26519. */
  26520. listProto.indexOfName = function (name) {
  26521. for (var i = 0, len = this.count(); i < len; i++) {
  26522. if (this.getName(i) === name) {
  26523. return i;
  26524. }
  26525. }
  26526. return -1;
  26527. };
  26528. /**
  26529. * Retreive the index with given raw data index
  26530. * @param {number} idx
  26531. * @param {number} name
  26532. * @return {number}
  26533. */
  26534. listProto.indexOfRawIndex = function (rawIndex) {
  26535. if (!this._indices) {
  26536. return rawIndex;
  26537. }
  26538. if (rawIndex >= this._rawCount || rawIndex < 0) {
  26539. return -1;
  26540. }
  26541. // Indices are ascending
  26542. var indices = this._indices;
  26543. // If rawIndex === dataIndex
  26544. var rawDataIndex = indices[rawIndex];
  26545. if (rawDataIndex != null && rawDataIndex < this._count && rawDataIndex === rawIndex) {
  26546. return rawIndex;
  26547. }
  26548. var left = 0;
  26549. var right = this._count - 1;
  26550. while (left <= right) {
  26551. var mid = (left + right) / 2 | 0;
  26552. if (indices[mid] < rawIndex) {
  26553. left = mid + 1;
  26554. }
  26555. else if (indices[mid] > rawIndex) {
  26556. right = mid - 1;
  26557. }
  26558. else {
  26559. return mid;
  26560. }
  26561. }
  26562. return -1;
  26563. };
  26564. /**
  26565. * Retreive the index of nearest value
  26566. * @param {string} dim
  26567. * @param {number} value
  26568. * @param {number} [maxDistance=Infinity]
  26569. * @return {Array.<number>} Considere multiple points has the same value.
  26570. */
  26571. listProto.indicesOfNearest = function (dim, value, maxDistance) {
  26572. var storage = this._storage;
  26573. var dimData = storage[dim];
  26574. var nearestIndices = [];
  26575. if (!dimData) {
  26576. return nearestIndices;
  26577. }
  26578. if (maxDistance == null) {
  26579. maxDistance = Infinity;
  26580. }
  26581. var minDist = Number.MAX_VALUE;
  26582. var minDiff = -1;
  26583. for (var i = 0, len = this.count(); i < len; i++) {
  26584. var diff = value - this.get(dim, i /*, stack */);
  26585. var dist = Math.abs(diff);
  26586. if (diff <= maxDistance && dist <= minDist) {
  26587. // For the case of two data are same on xAxis, which has sequence data.
  26588. // Show the nearest index
  26589. // https://github.com/ecomfe/echarts/issues/2869
  26590. if (dist < minDist || (diff >= 0 && minDiff < 0)) {
  26591. minDist = dist;
  26592. minDiff = diff;
  26593. nearestIndices.length = 0;
  26594. }
  26595. nearestIndices.push(i);
  26596. }
  26597. }
  26598. return nearestIndices;
  26599. };
  26600. /**
  26601. * Get raw data index
  26602. * @param {number} idx
  26603. * @return {number}
  26604. */
  26605. listProto.getRawIndex = getRawIndexWithoutIndices;
  26606. function getRawIndexWithoutIndices(idx) {
  26607. return idx;
  26608. }
  26609. function getRawIndexWithIndices(idx) {
  26610. if (idx < this._count && idx >= 0) {
  26611. return this._indices[idx];
  26612. }
  26613. return -1;
  26614. }
  26615. /**
  26616. * Get raw data item
  26617. * @param {number} idx
  26618. * @return {number}
  26619. */
  26620. listProto.getRawDataItem = function (idx) {
  26621. if (!this._rawData.persistent) {
  26622. var val = [];
  26623. for (var i = 0; i < this.dimensions.length; i++) {
  26624. var dim = this.dimensions[i];
  26625. val.push(this.get(dim, idx));
  26626. }
  26627. return val;
  26628. }
  26629. else {
  26630. return this._rawData.getItem(this.getRawIndex(idx));
  26631. }
  26632. };
  26633. /**
  26634. * @param {number} idx
  26635. * @param {boolean} [notDefaultIdx=false]
  26636. * @return {string}
  26637. */
  26638. listProto.getName = function (idx) {
  26639. var rawIndex = this.getRawIndex(idx);
  26640. return this._nameList[rawIndex]
  26641. || getRawValueFromStore(this, this._nameDimIdx, rawIndex)
  26642. || '';
  26643. };
  26644. /**
  26645. * @param {number} idx
  26646. * @param {boolean} [notDefaultIdx=false]
  26647. * @return {string}
  26648. */
  26649. listProto.getId = function (idx) {
  26650. return getId(this, this.getRawIndex(idx));
  26651. };
  26652. function getId(list, rawIndex) {
  26653. var id = list._idList[rawIndex];
  26654. if (id == null) {
  26655. id = getRawValueFromStore(list, list._idDimIdx, rawIndex);
  26656. }
  26657. if (id == null) {
  26658. // FIXME Check the usage in graph, should not use prefix.
  26659. id = ID_PREFIX + rawIndex;
  26660. }
  26661. return id;
  26662. }
  26663. function normalizeDimensions(dimensions) {
  26664. if (!isArray(dimensions)) {
  26665. dimensions = [dimensions];
  26666. }
  26667. return dimensions;
  26668. }
  26669. function validateDimensions(list, dims) {
  26670. for (var i = 0; i < dims.length; i++) {
  26671. // stroage may be empty when no data, so use
  26672. // dimensionInfos to check.
  26673. if (!list._dimensionInfos[dims[i]]) {
  26674. console.error('Unkown dimension ' + dims[i]);
  26675. }
  26676. }
  26677. }
  26678. /**
  26679. * Data iteration
  26680. * @param {string|Array.<string>}
  26681. * @param {Function} cb
  26682. * @param {*} [context=this]
  26683. *
  26684. * @example
  26685. * list.each('x', function (x, idx) {});
  26686. * list.each(['x', 'y'], function (x, y, idx) {});
  26687. * list.each(function (idx) {})
  26688. */
  26689. listProto.each = function (dims, cb, context, contextCompat) {
  26690. 'use strict';
  26691. if (!this._count) {
  26692. return;
  26693. }
  26694. if (typeof dims === 'function') {
  26695. contextCompat = context;
  26696. context = cb;
  26697. cb = dims;
  26698. dims = [];
  26699. }
  26700. // contextCompat just for compat echarts3
  26701. context = context || contextCompat || this;
  26702. dims = map(normalizeDimensions(dims), this.getDimension, this);
  26703. if (__DEV__) {
  26704. validateDimensions(this, dims);
  26705. }
  26706. var dimSize = dims.length;
  26707. for (var i = 0; i < this.count(); i++) {
  26708. // Simple optimization
  26709. switch (dimSize) {
  26710. case 0:
  26711. cb.call(context, i);
  26712. break;
  26713. case 1:
  26714. cb.call(context, this.get(dims[0], i), i);
  26715. break;
  26716. case 2:
  26717. cb.call(context, this.get(dims[0], i), this.get(dims[1], i), i);
  26718. break;
  26719. default:
  26720. var k = 0;
  26721. var value = [];
  26722. for (; k < dimSize; k++) {
  26723. value[k] = this.get(dims[k], i);
  26724. }
  26725. // Index
  26726. value[k] = i;
  26727. cb.apply(context, value);
  26728. }
  26729. }
  26730. };
  26731. /**
  26732. * Data filter
  26733. * @param {string|Array.<string>}
  26734. * @param {Function} cb
  26735. * @param {*} [context=this]
  26736. */
  26737. listProto.filterSelf = function (dimensions, cb, context, contextCompat) {
  26738. 'use strict';
  26739. if (!this._count) {
  26740. return;
  26741. }
  26742. if (typeof dimensions === 'function') {
  26743. contextCompat = context;
  26744. context = cb;
  26745. cb = dimensions;
  26746. dimensions = [];
  26747. }
  26748. // contextCompat just for compat echarts3
  26749. context = context || contextCompat || this;
  26750. dimensions = map(
  26751. normalizeDimensions(dimensions), this.getDimension, this
  26752. );
  26753. if (__DEV__) {
  26754. validateDimensions(this, dimensions);
  26755. }
  26756. var count = this.count();
  26757. var Ctor = getIndicesCtor(this);
  26758. var newIndices = new Ctor(count);
  26759. var value = [];
  26760. var dimSize = dimensions.length;
  26761. var offset = 0;
  26762. var dim0 = dimensions[0];
  26763. for (var i = 0; i < count; i++) {
  26764. var keep;
  26765. var rawIdx = this.getRawIndex(i);
  26766. // Simple optimization
  26767. if (dimSize === 0) {
  26768. keep = cb.call(context, i);
  26769. }
  26770. else if (dimSize === 1) {
  26771. var val = this._getFast(dim0, rawIdx);
  26772. keep = cb.call(context, val, i);
  26773. }
  26774. else {
  26775. for (var k = 0; k < dimSize; k++) {
  26776. value[k] = this._getFast(dim0, rawIdx);
  26777. }
  26778. value[k] = i;
  26779. keep = cb.apply(context, value);
  26780. }
  26781. if (keep) {
  26782. newIndices[offset++] = rawIdx;
  26783. }
  26784. }
  26785. // Set indices after filtered.
  26786. if (offset < count) {
  26787. this._indices = newIndices;
  26788. }
  26789. this._count = offset;
  26790. // Reset data extent
  26791. this._extent = {};
  26792. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  26793. return this;
  26794. };
  26795. /**
  26796. * Select data in range. (For optimization of filter)
  26797. * (Manually inline code, support 5 million data filtering in data zoom.)
  26798. */
  26799. listProto.selectRange = function (range) {
  26800. 'use strict';
  26801. if (!this._count) {
  26802. return;
  26803. }
  26804. var dimensions = [];
  26805. for (var dim in range) {
  26806. if (range.hasOwnProperty(dim)) {
  26807. dimensions.push(dim);
  26808. }
  26809. }
  26810. if (__DEV__) {
  26811. validateDimensions(this, dimensions);
  26812. }
  26813. var dimSize = dimensions.length;
  26814. if (!dimSize) {
  26815. return;
  26816. }
  26817. var originalCount = this.count();
  26818. var Ctor = getIndicesCtor(this);
  26819. var newIndices = new Ctor(originalCount);
  26820. var offset = 0;
  26821. var dim0 = dimensions[0];
  26822. var min = range[dim0][0];
  26823. var max = range[dim0][1];
  26824. var quickFinished = false;
  26825. if (!this._indices) {
  26826. // Extreme optimization for common case. About 2x faster in chrome.
  26827. var idx = 0;
  26828. if (dimSize === 1) {
  26829. var dimStorage = this._storage[dimensions[0]];
  26830. for (var k = 0; k < this._chunkCount; k++) {
  26831. var chunkStorage = dimStorage[k];
  26832. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  26833. for (var i = 0; i < len; i++) {
  26834. var val = chunkStorage[i];
  26835. // NaN will not be filtered. Consider the case, in line chart, empty
  26836. // value indicates the line should be broken. But for the case like
  26837. // scatter plot, a data item with empty value will not be rendered,
  26838. // but the axis extent may be effected if some other dim of the data
  26839. // item has value. Fortunately it is not a significant negative effect.
  26840. if (
  26841. (val >= min && val <= max) || isNaN(val)
  26842. ) {
  26843. newIndices[offset++] = idx;
  26844. }
  26845. idx++;
  26846. }
  26847. }
  26848. quickFinished = true;
  26849. }
  26850. else if (dimSize === 2) {
  26851. var dimStorage = this._storage[dim0];
  26852. var dimStorage2 = this._storage[dimensions[1]];
  26853. var min2 = range[dimensions[1]][0];
  26854. var max2 = range[dimensions[1]][1];
  26855. for (var k = 0; k < this._chunkCount; k++) {
  26856. var chunkStorage = dimStorage[k];
  26857. var chunkStorage2 = dimStorage2[k];
  26858. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  26859. for (var i = 0; i < len; i++) {
  26860. var val = chunkStorage[i];
  26861. var val2 = chunkStorage2[i];
  26862. // Do not filter NaN, see comment above.
  26863. if ((
  26864. (val >= min && val <= max) || isNaN(val)
  26865. )
  26866. && (
  26867. (val2 >= min2 && val2 <= max2) || isNaN(val2)
  26868. )
  26869. ) {
  26870. newIndices[offset++] = idx;
  26871. }
  26872. idx++;
  26873. }
  26874. }
  26875. quickFinished = true;
  26876. }
  26877. }
  26878. if (!quickFinished) {
  26879. if (dimSize === 1) {
  26880. for (var i = 0; i < originalCount; i++) {
  26881. var rawIndex = this.getRawIndex(i);
  26882. var val = this._getFast(dim0, rawIndex);
  26883. // Do not filter NaN, see comment above.
  26884. if (
  26885. (val >= min && val <= max) || isNaN(val)
  26886. ) {
  26887. newIndices[offset++] = rawIndex;
  26888. }
  26889. }
  26890. }
  26891. else {
  26892. for (var i = 0; i < originalCount; i++) {
  26893. var keep = true;
  26894. var rawIndex = this.getRawIndex(i);
  26895. for (var k = 0; k < dimSize; k++) {
  26896. var dimk = dimensions[k];
  26897. var val = this._getFast(dim, rawIndex);
  26898. // Do not filter NaN, see comment above.
  26899. if (val < range[dimk][0] || val > range[dimk][1]) {
  26900. keep = false;
  26901. }
  26902. }
  26903. if (keep) {
  26904. newIndices[offset++] = this.getRawIndex(i);
  26905. }
  26906. }
  26907. }
  26908. }
  26909. // Set indices after filtered.
  26910. if (offset < originalCount) {
  26911. this._indices = newIndices;
  26912. }
  26913. this._count = offset;
  26914. // Reset data extent
  26915. this._extent = {};
  26916. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  26917. return this;
  26918. };
  26919. /**
  26920. * Data mapping to a plain array
  26921. * @param {string|Array.<string>} [dimensions]
  26922. * @param {Function} cb
  26923. * @param {*} [context=this]
  26924. * @return {Array}
  26925. */
  26926. listProto.mapArray = function (dimensions, cb, context, contextCompat) {
  26927. 'use strict';
  26928. if (typeof dimensions === 'function') {
  26929. contextCompat = context;
  26930. context = cb;
  26931. cb = dimensions;
  26932. dimensions = [];
  26933. }
  26934. // contextCompat just for compat echarts3
  26935. context = context || contextCompat || this;
  26936. var result = [];
  26937. this.each(dimensions, function () {
  26938. result.push(cb && cb.apply(this, arguments));
  26939. }, context);
  26940. return result;
  26941. };
  26942. // Data in excludeDimensions is copied, otherwise transfered.
  26943. function cloneListForMapAndSample(original, excludeDimensions) {
  26944. var allDimensions = original.dimensions;
  26945. var list = new List(
  26946. map(allDimensions, original.getDimensionInfo, original),
  26947. original.hostModel
  26948. );
  26949. // FIXME If needs stackedOn, value may already been stacked
  26950. transferProperties(list, original);
  26951. var storage = list._storage = {};
  26952. var originalStorage = original._storage;
  26953. // Init storage
  26954. for (var i = 0; i < allDimensions.length; i++) {
  26955. var dim = allDimensions[i];
  26956. if (originalStorage[dim]) {
  26957. // Notice that we do not reset invertedIndicesMap here, becuase
  26958. // there is no scenario of mapping or sampling ordinal dimension.
  26959. if (indexOf(excludeDimensions, dim) >= 0) {
  26960. storage[dim] = cloneDimStore(originalStorage[dim]);
  26961. list._rawExtent[dim] = getInitialExtent();
  26962. list._extent[dim] = null;
  26963. }
  26964. else {
  26965. // Direct reference for other dimensions
  26966. storage[dim] = originalStorage[dim];
  26967. }
  26968. }
  26969. }
  26970. return list;
  26971. }
  26972. function cloneDimStore(originalDimStore) {
  26973. var newDimStore = new Array(originalDimStore.length);
  26974. for (var j = 0; j < originalDimStore.length; j++) {
  26975. newDimStore[j] = cloneChunk(originalDimStore[j]);
  26976. }
  26977. return newDimStore;
  26978. }
  26979. function getInitialExtent() {
  26980. return [Infinity, -Infinity];
  26981. }
  26982. /**
  26983. * Data mapping to a new List with given dimensions
  26984. * @param {string|Array.<string>} dimensions
  26985. * @param {Function} cb
  26986. * @param {*} [context=this]
  26987. * @return {Array}
  26988. */
  26989. listProto.map = function (dimensions, cb, context, contextCompat) {
  26990. 'use strict';
  26991. // contextCompat just for compat echarts3
  26992. context = context || contextCompat || this;
  26993. dimensions = map(
  26994. normalizeDimensions(dimensions), this.getDimension, this
  26995. );
  26996. if (__DEV__) {
  26997. validateDimensions(this, dimensions);
  26998. }
  26999. var list = cloneListForMapAndSample(this, dimensions);
  27000. // Following properties are all immutable.
  27001. // So we can reference to the same value
  27002. list._indices = this._indices;
  27003. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27004. var storage = list._storage;
  27005. var tmpRetValue = [];
  27006. var chunkSize = this._chunkSize;
  27007. var dimSize = dimensions.length;
  27008. var dataCount = this.count();
  27009. var values = [];
  27010. var rawExtent = list._rawExtent;
  27011. for (var dataIndex = 0; dataIndex < dataCount; dataIndex++) {
  27012. for (var dimIndex = 0; dimIndex < dimSize; dimIndex++) {
  27013. values[dimIndex] = this.get(dimensions[dimIndex], dataIndex /*, stack */);
  27014. }
  27015. values[dimSize] = dataIndex;
  27016. var retValue = cb && cb.apply(context, values);
  27017. if (retValue != null) {
  27018. // a number or string (in oridinal dimension)?
  27019. if (typeof retValue !== 'object') {
  27020. tmpRetValue[0] = retValue;
  27021. retValue = tmpRetValue;
  27022. }
  27023. var rawIndex = this.getRawIndex(dataIndex);
  27024. var chunkIndex = Math.floor(rawIndex / chunkSize);
  27025. var chunkOffset = rawIndex % chunkSize;
  27026. for (var i = 0; i < retValue.length; i++) {
  27027. var dim = dimensions[i];
  27028. var val = retValue[i];
  27029. var rawExtentOnDim = rawExtent[dim];
  27030. var dimStore = storage[dim];
  27031. if (dimStore) {
  27032. dimStore[chunkIndex][chunkOffset] = val;
  27033. }
  27034. if (val < rawExtentOnDim[0]) {
  27035. rawExtentOnDim[0] = val;
  27036. }
  27037. if (val > rawExtentOnDim[1]) {
  27038. rawExtentOnDim[1] = val;
  27039. }
  27040. }
  27041. }
  27042. }
  27043. return list;
  27044. };
  27045. /**
  27046. * Large data down sampling on given dimension
  27047. * @param {string} dimension
  27048. * @param {number} rate
  27049. * @param {Function} sampleValue
  27050. * @param {Function} sampleIndex Sample index for name and id
  27051. */
  27052. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  27053. var list = cloneListForMapAndSample(this, [dimension]);
  27054. var targetStorage = list._storage;
  27055. var frameValues = [];
  27056. var frameSize = Math.floor(1 / rate);
  27057. var dimStore = targetStorage[dimension];
  27058. var len = this.count();
  27059. var chunkSize = this._chunkSize;
  27060. var rawExtentOnDim = list._rawExtent[dimension];
  27061. var newIndices = new (getIndicesCtor(this))(len);
  27062. var offset = 0;
  27063. for (var i = 0; i < len; i += frameSize) {
  27064. // Last frame
  27065. if (frameSize > len - i) {
  27066. frameSize = len - i;
  27067. frameValues.length = frameSize;
  27068. }
  27069. for (var k = 0; k < frameSize; k++) {
  27070. var dataIdx = this.getRawIndex(i + k);
  27071. var originalChunkIndex = Math.floor(dataIdx / chunkSize);
  27072. var originalChunkOffset = dataIdx % chunkSize;
  27073. frameValues[k] = dimStore[originalChunkIndex][originalChunkOffset];
  27074. }
  27075. var value = sampleValue(frameValues);
  27076. var sampleFrameIdx = this.getRawIndex(
  27077. Math.min(i + sampleIndex(frameValues, value) || 0, len - 1)
  27078. );
  27079. var sampleChunkIndex = Math.floor(sampleFrameIdx / chunkSize);
  27080. var sampleChunkOffset = sampleFrameIdx % chunkSize;
  27081. // Only write value on the filtered data
  27082. dimStore[sampleChunkIndex][sampleChunkOffset] = value;
  27083. if (value < rawExtentOnDim[0]) {
  27084. rawExtentOnDim[0] = value;
  27085. }
  27086. if (value > rawExtentOnDim[1]) {
  27087. rawExtentOnDim[1] = value;
  27088. }
  27089. newIndices[offset++] = sampleFrameIdx;
  27090. }
  27091. list._count = offset;
  27092. list._indices = newIndices;
  27093. list.getRawIndex = getRawIndexWithIndices;
  27094. return list;
  27095. };
  27096. /**
  27097. * Get model of one data item.
  27098. *
  27099. * @param {number} idx
  27100. */
  27101. // FIXME Model proxy ?
  27102. listProto.getItemModel = function (idx) {
  27103. var hostModel = this.hostModel;
  27104. return new Model(this.getRawDataItem(idx), hostModel, hostModel && hostModel.ecModel);
  27105. };
  27106. /**
  27107. * Create a data differ
  27108. * @param {module:echarts/data/List} otherList
  27109. * @return {module:echarts/data/DataDiffer}
  27110. */
  27111. listProto.diff = function (otherList) {
  27112. var thisList = this;
  27113. return new DataDiffer(
  27114. otherList ? otherList.getIndices() : [],
  27115. this.getIndices(),
  27116. function (idx) {
  27117. return getId(otherList, idx);
  27118. },
  27119. function (idx) {
  27120. return getId(thisList, idx);
  27121. }
  27122. );
  27123. };
  27124. /**
  27125. * Get visual property.
  27126. * @param {string} key
  27127. */
  27128. listProto.getVisual = function (key) {
  27129. var visual = this._visual;
  27130. return visual && visual[key];
  27131. };
  27132. /**
  27133. * Set visual property
  27134. * @param {string|Object} key
  27135. * @param {*} [value]
  27136. *
  27137. * @example
  27138. * setVisual('color', color);
  27139. * setVisual({
  27140. * 'color': color
  27141. * });
  27142. */
  27143. listProto.setVisual = function (key, val) {
  27144. if (isObject$4(key)) {
  27145. for (var name in key) {
  27146. if (key.hasOwnProperty(name)) {
  27147. this.setVisual(name, key[name]);
  27148. }
  27149. }
  27150. return;
  27151. }
  27152. this._visual = this._visual || {};
  27153. this._visual[key] = val;
  27154. };
  27155. /**
  27156. * Set layout property.
  27157. * @param {string|Object} key
  27158. * @param {*} [val]
  27159. */
  27160. listProto.setLayout = function (key, val) {
  27161. if (isObject$4(key)) {
  27162. for (var name in key) {
  27163. if (key.hasOwnProperty(name)) {
  27164. this.setLayout(name, key[name]);
  27165. }
  27166. }
  27167. return;
  27168. }
  27169. this._layout[key] = val;
  27170. };
  27171. /**
  27172. * Get layout property.
  27173. * @param {string} key.
  27174. * @return {*}
  27175. */
  27176. listProto.getLayout = function (key) {
  27177. return this._layout[key];
  27178. };
  27179. /**
  27180. * Get layout of single data item
  27181. * @param {number} idx
  27182. */
  27183. listProto.getItemLayout = function (idx) {
  27184. return this._itemLayouts[idx];
  27185. };
  27186. /**
  27187. * Set layout of single data item
  27188. * @param {number} idx
  27189. * @param {Object} layout
  27190. * @param {boolean=} [merge=false]
  27191. */
  27192. listProto.setItemLayout = function (idx, layout, merge$$1) {
  27193. this._itemLayouts[idx] = merge$$1
  27194. ? extend(this._itemLayouts[idx] || {}, layout)
  27195. : layout;
  27196. };
  27197. /**
  27198. * Clear all layout of single data item
  27199. */
  27200. listProto.clearItemLayouts = function () {
  27201. this._itemLayouts.length = 0;
  27202. };
  27203. /**
  27204. * Get visual property of single data item
  27205. * @param {number} idx
  27206. * @param {string} key
  27207. * @param {boolean} [ignoreParent=false]
  27208. */
  27209. listProto.getItemVisual = function (idx, key, ignoreParent) {
  27210. var itemVisual = this._itemVisuals[idx];
  27211. var val = itemVisual && itemVisual[key];
  27212. if (val == null && !ignoreParent) {
  27213. // Use global visual property
  27214. return this.getVisual(key);
  27215. }
  27216. return val;
  27217. };
  27218. /**
  27219. * Set visual property of single data item
  27220. *
  27221. * @param {number} idx
  27222. * @param {string|Object} key
  27223. * @param {*} [value]
  27224. *
  27225. * @example
  27226. * setItemVisual(0, 'color', color);
  27227. * setItemVisual(0, {
  27228. * 'color': color
  27229. * });
  27230. */
  27231. listProto.setItemVisual = function (idx, key, value) {
  27232. var itemVisual = this._itemVisuals[idx] || {};
  27233. var hasItemVisual = this.hasItemVisual;
  27234. this._itemVisuals[idx] = itemVisual;
  27235. if (isObject$4(key)) {
  27236. for (var name in key) {
  27237. if (key.hasOwnProperty(name)) {
  27238. itemVisual[name] = key[name];
  27239. hasItemVisual[name] = true;
  27240. }
  27241. }
  27242. return;
  27243. }
  27244. itemVisual[key] = value;
  27245. hasItemVisual[key] = true;
  27246. };
  27247. /**
  27248. * Clear itemVisuals and list visual.
  27249. */
  27250. listProto.clearAllVisual = function () {
  27251. this._visual = {};
  27252. this._itemVisuals = [];
  27253. this.hasItemVisual = {};
  27254. };
  27255. var setItemDataAndSeriesIndex = function (child) {
  27256. child.seriesIndex = this.seriesIndex;
  27257. child.dataIndex = this.dataIndex;
  27258. child.dataType = this.dataType;
  27259. };
  27260. /**
  27261. * Set graphic element relative to data. It can be set as null
  27262. * @param {number} idx
  27263. * @param {module:zrender/Element} [el]
  27264. */
  27265. listProto.setItemGraphicEl = function (idx, el) {
  27266. var hostModel = this.hostModel;
  27267. if (el) {
  27268. // Add data index and series index for indexing the data by element
  27269. // Useful in tooltip
  27270. el.dataIndex = idx;
  27271. el.dataType = this.dataType;
  27272. el.seriesIndex = hostModel && hostModel.seriesIndex;
  27273. if (el.type === 'group') {
  27274. el.traverse(setItemDataAndSeriesIndex, el);
  27275. }
  27276. }
  27277. this._graphicEls[idx] = el;
  27278. };
  27279. /**
  27280. * @param {number} idx
  27281. * @return {module:zrender/Element}
  27282. */
  27283. listProto.getItemGraphicEl = function (idx) {
  27284. return this._graphicEls[idx];
  27285. };
  27286. /**
  27287. * @param {Function} cb
  27288. * @param {*} context
  27289. */
  27290. listProto.eachItemGraphicEl = function (cb, context) {
  27291. each$1(this._graphicEls, function (el, idx) {
  27292. if (el) {
  27293. cb && cb.call(context, el, idx);
  27294. }
  27295. });
  27296. };
  27297. /**
  27298. * Shallow clone a new list except visual and layout properties, and graph elements.
  27299. * New list only change the indices.
  27300. */
  27301. listProto.cloneShallow = function (list) {
  27302. if (!list) {
  27303. var dimensionInfoList = map(this.dimensions, this.getDimensionInfo, this);
  27304. list = new List(dimensionInfoList, this.hostModel);
  27305. }
  27306. // FIXME
  27307. list._storage = this._storage;
  27308. transferProperties(list, this);
  27309. // Clone will not change the data extent and indices
  27310. if (this._indices) {
  27311. var Ctor = this._indices.constructor;
  27312. list._indices = new Ctor(this._indices);
  27313. }
  27314. else {
  27315. list._indices = null;
  27316. }
  27317. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27318. return list;
  27319. };
  27320. /**
  27321. * Wrap some method to add more feature
  27322. * @param {string} methodName
  27323. * @param {Function} injectFunction
  27324. */
  27325. listProto.wrapMethod = function (methodName, injectFunction) {
  27326. var originalMethod = this[methodName];
  27327. if (typeof originalMethod !== 'function') {
  27328. return;
  27329. }
  27330. this.__wrappedMethods = this.__wrappedMethods || [];
  27331. this.__wrappedMethods.push(methodName);
  27332. this[methodName] = function () {
  27333. var res = originalMethod.apply(this, arguments);
  27334. return injectFunction.apply(this, [res].concat(slice(arguments)));
  27335. };
  27336. };
  27337. // Methods that create a new list based on this list should be listed here.
  27338. // Notice that those method should `RETURN` the new list.
  27339. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
  27340. // Methods that change indices of this list should be listed here.
  27341. listProto.CHANGABLE_METHODS = ['filterSelf', 'selectRange'];
  27342. /*
  27343. * Licensed to the Apache Software Foundation (ASF) under one
  27344. * or more contributor license agreements. See the NOTICE file
  27345. * distributed with this work for additional information
  27346. * regarding copyright ownership. The ASF licenses this file
  27347. * to you under the Apache License, Version 2.0 (the
  27348. * "License"); you may not use this file except in compliance
  27349. * with the License. You may obtain a copy of the License at
  27350. *
  27351. * http://www.apache.org/licenses/LICENSE-2.0
  27352. *
  27353. * Unless required by applicable law or agreed to in writing,
  27354. * software distributed under the License is distributed on an
  27355. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27356. * KIND, either express or implied. See the License for the
  27357. * specific language governing permissions and limitations
  27358. * under the License.
  27359. */
  27360. /**
  27361. * @deprecated
  27362. * Use `echarts/data/helper/createDimensions` instead.
  27363. */
  27364. /**
  27365. * @see {module:echarts/test/ut/spec/data/completeDimensions}
  27366. *
  27367. * Complete the dimensions array, by user defined `dimension` and `encode`,
  27368. * and guessing from the data structure.
  27369. * If no 'value' dimension specified, the first no-named dimension will be
  27370. * named as 'value'.
  27371. *
  27372. * @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
  27373. * provides not only dim template, but also default order.
  27374. * properties: 'name', 'type', 'displayName'.
  27375. * `name` of each item provides default coord name.
  27376. * [{dimsDef: [string|Object, ...]}, ...] dimsDef of sysDim item provides default dim name, and
  27377. * provide dims count that the sysDim required.
  27378. * [{ordinalMeta}] can be specified.
  27379. * @param {module:echarts/data/Source|Array|Object} source or data (for compatibal with pervious)
  27380. * @param {Object} [opt]
  27381. * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
  27382. * For example: ['asdf', {name, type}, ...].
  27383. * @param {Object|HashMap} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
  27384. * @param {string} [opt.generateCoord] Generate coord dim with the given name.
  27385. * If not specified, extra dim names will be:
  27386. * 'value', 'value0', 'value1', ...
  27387. * @param {number} [opt.generateCoordCount] By default, the generated dim name is `generateCoord`.
  27388. * If `generateCoordCount` specified, the generated dim names will be:
  27389. * `generateCoord` + 0, `generateCoord` + 1, ...
  27390. * can be Infinity, indicate that use all of the remain columns.
  27391. * @param {number} [opt.dimCount] If not specified, guess by the first data item.
  27392. * @param {number} [opt.encodeDefaulter] If not specified, auto find the next available data dim.
  27393. * @return {Array.<Object>} [{
  27394. * name: string mandatory,
  27395. * displayName: string, the origin name in dimsDef, see source helper.
  27396. * If displayName given, the tooltip will displayed vertically.
  27397. * coordDim: string mandatory,
  27398. * coordDimIndex: number mandatory,
  27399. * type: string optional,
  27400. * otherDims: { never null/undefined
  27401. * tooltip: number optional,
  27402. * label: number optional,
  27403. * itemName: number optional,
  27404. * seriesName: number optional,
  27405. * },
  27406. * isExtraCoord: boolean true if coord is generated
  27407. * (not specified in encode and not series specified)
  27408. * other props ...
  27409. * }]
  27410. */
  27411. function completeDimensions(sysDims, source, opt) {
  27412. if (!Source.isInstance(source)) {
  27413. source = Source.seriesDataToSource(source);
  27414. }
  27415. opt = opt || {};
  27416. sysDims = (sysDims || []).slice();
  27417. var dimsDef = (opt.dimsDef || []).slice();
  27418. var encodeDef = createHashMap(opt.encodeDef);
  27419. var dataDimNameMap = createHashMap();
  27420. var coordDimNameMap = createHashMap();
  27421. // var valueCandidate;
  27422. var result = [];
  27423. var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimCount);
  27424. // Apply user defined dims (`name` and `type`) and init result.
  27425. for (var i = 0; i < dimCount; i++) {
  27426. var dimDefItem = dimsDef[i] = extend(
  27427. {}, isObject$1(dimsDef[i]) ? dimsDef[i] : {name: dimsDef[i]}
  27428. );
  27429. var userDimName = dimDefItem.name;
  27430. var resultItem = result[i] = {otherDims: {}};
  27431. // Name will be applied later for avoiding duplication.
  27432. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  27433. // Only if `series.dimensions` is defined in option
  27434. // displayName, will be set, and dimension will be diplayed vertically in
  27435. // tooltip by default.
  27436. resultItem.name = resultItem.displayName = userDimName;
  27437. dataDimNameMap.set(userDimName, i);
  27438. }
  27439. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  27440. dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
  27441. }
  27442. // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
  27443. encodeDef.each(function (dataDims, coordDim) {
  27444. dataDims = normalizeToArray(dataDims).slice();
  27445. // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
  27446. // `{encode: {x: -1, y: 1}}`. Should not filter anything in
  27447. // this case.
  27448. if (dataDims.length === 1 && dataDims[0] < 0) {
  27449. encodeDef.set(coordDim, false);
  27450. return;
  27451. }
  27452. var validDataDims = encodeDef.set(coordDim, []);
  27453. each$1(dataDims, function (resultDimIdx, idx) {
  27454. // The input resultDimIdx can be dim name or index.
  27455. isString(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
  27456. if (resultDimIdx != null && resultDimIdx < dimCount) {
  27457. validDataDims[idx] = resultDimIdx;
  27458. applyDim(result[resultDimIdx], coordDim, idx);
  27459. }
  27460. });
  27461. });
  27462. // Apply templetes and default order from `sysDims`.
  27463. var availDimIdx = 0;
  27464. each$1(sysDims, function (sysDimItem, sysDimIndex) {
  27465. var coordDim;
  27466. var sysDimItem;
  27467. var sysDimItemDimsDef;
  27468. var sysDimItemOtherDims;
  27469. if (isString(sysDimItem)) {
  27470. coordDim = sysDimItem;
  27471. sysDimItem = {};
  27472. }
  27473. else {
  27474. coordDim = sysDimItem.name;
  27475. var ordinalMeta = sysDimItem.ordinalMeta;
  27476. sysDimItem.ordinalMeta = null;
  27477. sysDimItem = clone(sysDimItem);
  27478. sysDimItem.ordinalMeta = ordinalMeta;
  27479. // `coordDimIndex` should not be set directly.
  27480. sysDimItemDimsDef = sysDimItem.dimsDef;
  27481. sysDimItemOtherDims = sysDimItem.otherDims;
  27482. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex
  27483. = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  27484. }
  27485. var dataDims = encodeDef.get(coordDim);
  27486. // negative resultDimIdx means no need to mapping.
  27487. if (dataDims === false) {
  27488. return;
  27489. }
  27490. var dataDims = normalizeToArray(dataDims);
  27491. // dimensions provides default dim sequences.
  27492. if (!dataDims.length) {
  27493. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  27494. while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
  27495. availDimIdx++;
  27496. }
  27497. availDimIdx < result.length && dataDims.push(availDimIdx++);
  27498. }
  27499. }
  27500. // Apply templates.
  27501. each$1(dataDims, function (resultDimIdx, coordDimIndex) {
  27502. var resultItem = result[resultDimIdx];
  27503. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  27504. if (resultItem.name == null && sysDimItemDimsDef) {
  27505. var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
  27506. !isObject$1(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {name: sysDimItemDimsDefItem});
  27507. resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
  27508. resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
  27509. }
  27510. // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
  27511. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  27512. });
  27513. });
  27514. function applyDim(resultItem, coordDim, coordDimIndex) {
  27515. if (OTHER_DIMENSIONS.get(coordDim) != null) {
  27516. resultItem.otherDims[coordDim] = coordDimIndex;
  27517. }
  27518. else {
  27519. resultItem.coordDim = coordDim;
  27520. resultItem.coordDimIndex = coordDimIndex;
  27521. coordDimNameMap.set(coordDim, true);
  27522. }
  27523. }
  27524. // Make sure the first extra dim is 'value'.
  27525. var generateCoord = opt.generateCoord;
  27526. var generateCoordCount = opt.generateCoordCount;
  27527. var fromZero = generateCoordCount != null;
  27528. generateCoordCount = generateCoord ? (generateCoordCount || 1) : 0;
  27529. var extra = generateCoord || 'value';
  27530. // Set dim `name` and other `coordDim` and other props.
  27531. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  27532. var resultItem = result[resultDimIdx] = result[resultDimIdx] || {};
  27533. var coordDim = resultItem.coordDim;
  27534. if (coordDim == null) {
  27535. resultItem.coordDim = genName(
  27536. extra, coordDimNameMap, fromZero
  27537. );
  27538. resultItem.coordDimIndex = 0;
  27539. if (!generateCoord || generateCoordCount <= 0) {
  27540. resultItem.isExtraCoord = true;
  27541. }
  27542. generateCoordCount--;
  27543. }
  27544. resultItem.name == null && (resultItem.name = genName(
  27545. resultItem.coordDim,
  27546. dataDimNameMap
  27547. ));
  27548. if (resultItem.type == null && guessOrdinal(source, resultDimIdx, resultItem.name)) {
  27549. resultItem.type = 'ordinal';
  27550. }
  27551. }
  27552. return result;
  27553. }
  27554. // ??? TODO
  27555. // Originally detect dimCount by data[0]. Should we
  27556. // optimize it to only by sysDims and dimensions and encode.
  27557. // So only necessary dims will be initialized.
  27558. // But
  27559. // (1) custom series should be considered. where other dims
  27560. // may be visited.
  27561. // (2) sometimes user need to calcualte bubble size or use visualMap
  27562. // on other dimensions besides coordSys needed.
  27563. // So, dims that is not used by system, should be shared in storage?
  27564. function getDimCount(source, sysDims, dimsDef, optDimCount) {
  27565. // Note that the result dimCount should not small than columns count
  27566. // of data, otherwise `dataDimNameMap` checking will be incorrect.
  27567. var dimCount = Math.max(
  27568. source.dimensionsDetectCount || 1,
  27569. sysDims.length,
  27570. dimsDef.length,
  27571. optDimCount || 0
  27572. );
  27573. each$1(sysDims, function (sysDimItem) {
  27574. var sysDimItemDimsDef = sysDimItem.dimsDef;
  27575. sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
  27576. });
  27577. return dimCount;
  27578. }
  27579. function genName(name, map$$1, fromZero) {
  27580. if (fromZero || map$$1.get(name) != null) {
  27581. var i = 0;
  27582. while (map$$1.get(name + i) != null) {
  27583. i++;
  27584. }
  27585. name += i;
  27586. }
  27587. map$$1.set(name, true);
  27588. return name;
  27589. }
  27590. /*
  27591. * Licensed to the Apache Software Foundation (ASF) under one
  27592. * or more contributor license agreements. See the NOTICE file
  27593. * distributed with this work for additional information
  27594. * regarding copyright ownership. The ASF licenses this file
  27595. * to you under the Apache License, Version 2.0 (the
  27596. * "License"); you may not use this file except in compliance
  27597. * with the License. You may obtain a copy of the License at
  27598. *
  27599. * http://www.apache.org/licenses/LICENSE-2.0
  27600. *
  27601. * Unless required by applicable law or agreed to in writing,
  27602. * software distributed under the License is distributed on an
  27603. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27604. * KIND, either express or implied. See the License for the
  27605. * specific language governing permissions and limitations
  27606. * under the License.
  27607. */
  27608. /**
  27609. * Substitute `completeDimensions`.
  27610. * `completeDimensions` is to be deprecated.
  27611. */
  27612. /**
  27613. * @param {module:echarts/data/Source|module:echarts/data/List} source or data.
  27614. * @param {Object|Array} [opt]
  27615. * @param {Array.<string|Object>} [opt.coordDimensions=[]]
  27616. * @param {number} [opt.dimensionsCount]
  27617. * @param {string} [opt.generateCoord]
  27618. * @param {string} [opt.generateCoordCount]
  27619. * @param {Array.<string|Object>} [opt.dimensionsDefine=source.dimensionsDefine] Overwrite source define.
  27620. * @param {Object|HashMap} [opt.encodeDefine=source.encodeDefine] Overwrite source define.
  27621. * @return {Array.<Object>} dimensionsInfo
  27622. */
  27623. var createDimensions = function (source, opt) {
  27624. opt = opt || {};
  27625. return completeDimensions(opt.coordDimensions || [], source, {
  27626. dimsDef: opt.dimensionsDefine || source.dimensionsDefine,
  27627. encodeDef: opt.encodeDefine || source.encodeDefine,
  27628. dimCount: opt.dimensionsCount,
  27629. generateCoord: opt.generateCoord,
  27630. generateCoordCount: opt.generateCoordCount
  27631. });
  27632. };
  27633. /*
  27634. * Licensed to the Apache Software Foundation (ASF) under one
  27635. * or more contributor license agreements. See the NOTICE file
  27636. * distributed with this work for additional information
  27637. * regarding copyright ownership. The ASF licenses this file
  27638. * to you under the Apache License, Version 2.0 (the
  27639. * "License"); you may not use this file except in compliance
  27640. * with the License. You may obtain a copy of the License at
  27641. *
  27642. * http://www.apache.org/licenses/LICENSE-2.0
  27643. *
  27644. * Unless required by applicable law or agreed to in writing,
  27645. * software distributed under the License is distributed on an
  27646. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27647. * KIND, either express or implied. See the License for the
  27648. * specific language governing permissions and limitations
  27649. * under the License.
  27650. */
  27651. /**
  27652. * Note that it is too complicated to support 3d stack by value
  27653. * (have to create two-dimension inverted index), so in 3d case
  27654. * we just support that stacked by index.
  27655. *
  27656. * @param {module:echarts/model/Series} seriesModel
  27657. * @param {Array.<string|Object>} dimensionInfoList The same as the input of <module:echarts/data/List>.
  27658. * The input dimensionInfoList will be modified.
  27659. * @param {Object} [opt]
  27660. * @param {boolean} [opt.stackedCoordDimension=''] Specify a coord dimension if needed.
  27661. * @param {boolean} [opt.byIndex=false]
  27662. * @return {Object} calculationInfo
  27663. * {
  27664. * stackedDimension: string
  27665. * stackedByDimension: string
  27666. * isStackedByIndex: boolean
  27667. * stackedOverDimension: string
  27668. * stackResultDimension: string
  27669. * }
  27670. */
  27671. function enableDataStack(seriesModel, dimensionInfoList, opt) {
  27672. opt = opt || {};
  27673. var byIndex = opt.byIndex;
  27674. var stackedCoordDimension = opt.stackedCoordDimension;
  27675. // Compatibal: when `stack` is set as '', do not stack.
  27676. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  27677. var stackedByDimInfo;
  27678. var stackedDimInfo;
  27679. var stackResultDimension;
  27680. var stackedOverDimension;
  27681. each$1(dimensionInfoList, function (dimensionInfo, index) {
  27682. if (isString(dimensionInfo)) {
  27683. dimensionInfoList[index] = dimensionInfo = {name: dimensionInfo};
  27684. }
  27685. if (mayStack && !dimensionInfo.isExtraCoord) {
  27686. // Find the first ordinal dimension as the stackedByDimInfo.
  27687. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  27688. stackedByDimInfo = dimensionInfo;
  27689. }
  27690. // Find the first stackable dimension as the stackedDimInfo.
  27691. if (!stackedDimInfo
  27692. && dimensionInfo.type !== 'ordinal'
  27693. && dimensionInfo.type !== 'time'
  27694. && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)
  27695. ) {
  27696. stackedDimInfo = dimensionInfo;
  27697. }
  27698. }
  27699. });
  27700. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  27701. // Compatible with previous design, value axis (time axis) only stack by index.
  27702. // It may make sense if the user provides elaborately constructed data.
  27703. byIndex = true;
  27704. }
  27705. // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  27706. // That put stack logic in List is for using conveniently in echarts extensions, but it
  27707. // might not be a good way.
  27708. if (stackedDimInfo) {
  27709. // Use a weird name that not duplicated with other names.
  27710. stackResultDimension = '__\0ecstackresult';
  27711. stackedOverDimension = '__\0ecstackedover';
  27712. // Create inverted index to fast query index by value.
  27713. if (stackedByDimInfo) {
  27714. stackedByDimInfo.createInvertedIndices = true;
  27715. }
  27716. var stackedDimCoordDim = stackedDimInfo.coordDim;
  27717. var stackedDimType = stackedDimInfo.type;
  27718. var stackedDimCoordIndex = 0;
  27719. each$1(dimensionInfoList, function (dimensionInfo) {
  27720. if (dimensionInfo.coordDim === stackedDimCoordDim) {
  27721. stackedDimCoordIndex++;
  27722. }
  27723. });
  27724. dimensionInfoList.push({
  27725. name: stackResultDimension,
  27726. coordDim: stackedDimCoordDim,
  27727. coordDimIndex: stackedDimCoordIndex,
  27728. type: stackedDimType,
  27729. isExtraCoord: true,
  27730. isCalculationCoord: true
  27731. });
  27732. stackedDimCoordIndex++;
  27733. dimensionInfoList.push({
  27734. name: stackedOverDimension,
  27735. // This dimension contains stack base (generally, 0), so do not set it as
  27736. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  27737. coordDim: stackedOverDimension,
  27738. coordDimIndex: stackedDimCoordIndex,
  27739. type: stackedDimType,
  27740. isExtraCoord: true,
  27741. isCalculationCoord: true
  27742. });
  27743. }
  27744. return {
  27745. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  27746. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  27747. isStackedByIndex: byIndex,
  27748. stackedOverDimension: stackedOverDimension,
  27749. stackResultDimension: stackResultDimension
  27750. };
  27751. }
  27752. /**
  27753. * @param {module:echarts/data/List} data
  27754. * @param {string} stackedDim
  27755. */
  27756. function isDimensionStacked(data, stackedDim /*, stackedByDim*/) {
  27757. // Each single series only maps to one pair of axis. So we do not need to
  27758. // check stackByDim, whatever stacked by a dimension or stacked by index.
  27759. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
  27760. // && (
  27761. // stackedByDim != null
  27762. // ? stackedByDim === data.getCalculationInfo('stackedByDimension')
  27763. // : data.getCalculationInfo('isStackedByIndex')
  27764. // );
  27765. }
  27766. /**
  27767. * @param {module:echarts/data/List} data
  27768. * @param {string} targetDim
  27769. * @param {string} [stackedByDim] If not input this parameter, check whether
  27770. * stacked by index.
  27771. * @return {string} dimension
  27772. */
  27773. function getStackedDimension(data, targetDim) {
  27774. return isDimensionStacked(data, targetDim)
  27775. ? data.getCalculationInfo('stackResultDimension')
  27776. : targetDim;
  27777. }
  27778. /*
  27779. * Licensed to the Apache Software Foundation (ASF) under one
  27780. * or more contributor license agreements. See the NOTICE file
  27781. * distributed with this work for additional information
  27782. * regarding copyright ownership. The ASF licenses this file
  27783. * to you under the Apache License, Version 2.0 (the
  27784. * "License"); you may not use this file except in compliance
  27785. * with the License. You may obtain a copy of the License at
  27786. *
  27787. * http://www.apache.org/licenses/LICENSE-2.0
  27788. *
  27789. * Unless required by applicable law or agreed to in writing,
  27790. * software distributed under the License is distributed on an
  27791. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27792. * KIND, either express or implied. See the License for the
  27793. * specific language governing permissions and limitations
  27794. * under the License.
  27795. */
  27796. /**
  27797. * @param {module:echarts/data/Source|Array} source Or raw data.
  27798. * @param {module:echarts/model/Series} seriesModel
  27799. * @param {Object} [opt]
  27800. * @param {string} [opt.generateCoord]
  27801. */
  27802. function createListFromArray(source, seriesModel, opt) {
  27803. opt = opt || {};
  27804. if (!Source.isInstance(source)) {
  27805. source = Source.seriesDataToSource(source);
  27806. }
  27807. var coordSysName = seriesModel.get('coordinateSystem');
  27808. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  27809. var coordSysDefine = getCoordSysDefineBySeries(seriesModel);
  27810. var coordSysDimDefs;
  27811. if (coordSysDefine) {
  27812. coordSysDimDefs = map(coordSysDefine.coordSysDims, function (dim) {
  27813. var dimInfo = {name: dim};
  27814. var axisModel = coordSysDefine.axisMap.get(dim);
  27815. if (axisModel) {
  27816. var axisType = axisModel.get('type');
  27817. dimInfo.type = getDimensionTypeByAxis(axisType);
  27818. // dimInfo.stackable = isStackable(axisType);
  27819. }
  27820. return dimInfo;
  27821. });
  27822. }
  27823. if (!coordSysDimDefs) {
  27824. // Get dimensions from registered coordinate system
  27825. coordSysDimDefs = (registeredCoordSys && (
  27826. registeredCoordSys.getDimensionsInfo
  27827. ? registeredCoordSys.getDimensionsInfo()
  27828. : registeredCoordSys.dimensions.slice()
  27829. )) || ['x', 'y'];
  27830. }
  27831. var dimInfoList = createDimensions(source, {
  27832. coordDimensions: coordSysDimDefs,
  27833. generateCoord: opt.generateCoord
  27834. });
  27835. var firstCategoryDimIndex;
  27836. var hasNameEncode;
  27837. coordSysDefine && each$1(dimInfoList, function (dimInfo, dimIndex) {
  27838. var coordDim = dimInfo.coordDim;
  27839. var categoryAxisModel = coordSysDefine.categoryAxisMap.get(coordDim);
  27840. if (categoryAxisModel) {
  27841. if (firstCategoryDimIndex == null) {
  27842. firstCategoryDimIndex = dimIndex;
  27843. }
  27844. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  27845. }
  27846. if (dimInfo.otherDims.itemName != null) {
  27847. hasNameEncode = true;
  27848. }
  27849. });
  27850. if (!hasNameEncode && firstCategoryDimIndex != null) {
  27851. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  27852. }
  27853. var stackCalculationInfo = enableDataStack(seriesModel, dimInfoList);
  27854. var list = new List(dimInfoList, seriesModel);
  27855. list.setCalculationInfo(stackCalculationInfo);
  27856. var dimValueGetter = (firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source))
  27857. ? function (itemOpt, dimName, dataIndex, dimIndex) {
  27858. // Use dataIndex as ordinal value in categoryAxis
  27859. return dimIndex === firstCategoryDimIndex
  27860. ? dataIndex
  27861. : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  27862. }
  27863. : null;
  27864. list.hasItemOption = false;
  27865. list.initData(source, null, dimValueGetter);
  27866. return list;
  27867. }
  27868. function isNeedCompleteOrdinalData(source) {
  27869. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  27870. var sampleItem = firstDataNotNull(source.data || []);
  27871. return sampleItem != null
  27872. && !isArray(getDataItemValue(sampleItem));
  27873. }
  27874. }
  27875. function firstDataNotNull(data) {
  27876. var i = 0;
  27877. while (i < data.length && data[i] == null) {
  27878. i++;
  27879. }
  27880. return data[i];
  27881. }
  27882. /*
  27883. * Licensed to the Apache Software Foundation (ASF) under one
  27884. * or more contributor license agreements. See the NOTICE file
  27885. * distributed with this work for additional information
  27886. * regarding copyright ownership. The ASF licenses this file
  27887. * to you under the Apache License, Version 2.0 (the
  27888. * "License"); you may not use this file except in compliance
  27889. * with the License. You may obtain a copy of the License at
  27890. *
  27891. * http://www.apache.org/licenses/LICENSE-2.0
  27892. *
  27893. * Unless required by applicable law or agreed to in writing,
  27894. * software distributed under the License is distributed on an
  27895. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27896. * KIND, either express or implied. See the License for the
  27897. * specific language governing permissions and limitations
  27898. * under the License.
  27899. */
  27900. /**
  27901. * // Scale class management
  27902. * @module echarts/scale/Scale
  27903. */
  27904. /**
  27905. * @param {Object} [setting]
  27906. */
  27907. function Scale(setting) {
  27908. this._setting = setting || {};
  27909. /**
  27910. * Extent
  27911. * @type {Array.<number>}
  27912. * @protected
  27913. */
  27914. this._extent = [Infinity, -Infinity];
  27915. /**
  27916. * Step is calculated in adjustExtent
  27917. * @type {Array.<number>}
  27918. * @protected
  27919. */
  27920. this._interval = 0;
  27921. this.init && this.init.apply(this, arguments);
  27922. }
  27923. /**
  27924. * Parse input val to valid inner number.
  27925. * @param {*} val
  27926. * @return {number}
  27927. */
  27928. Scale.prototype.parse = function (val) {
  27929. // Notice: This would be a trap here, If the implementation
  27930. // of this method depends on extent, and this method is used
  27931. // before extent set (like in dataZoom), it would be wrong.
  27932. // Nevertheless, parse does not depend on extent generally.
  27933. return val;
  27934. };
  27935. Scale.prototype.getSetting = function (name) {
  27936. return this._setting[name];
  27937. };
  27938. Scale.prototype.contain = function (val) {
  27939. var extent = this._extent;
  27940. return val >= extent[0] && val <= extent[1];
  27941. };
  27942. /**
  27943. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  27944. * @param {number} val
  27945. * @return {number}
  27946. */
  27947. Scale.prototype.normalize = function (val) {
  27948. var extent = this._extent;
  27949. if (extent[1] === extent[0]) {
  27950. return 0.5;
  27951. }
  27952. return (val - extent[0]) / (extent[1] - extent[0]);
  27953. };
  27954. /**
  27955. * Scale normalized value
  27956. * @param {number} val
  27957. * @return {number}
  27958. */
  27959. Scale.prototype.scale = function (val) {
  27960. var extent = this._extent;
  27961. return val * (extent[1] - extent[0]) + extent[0];
  27962. };
  27963. /**
  27964. * Set extent from data
  27965. * @param {Array.<number>} other
  27966. */
  27967. Scale.prototype.unionExtent = function (other) {
  27968. var extent = this._extent;
  27969. other[0] < extent[0] && (extent[0] = other[0]);
  27970. other[1] > extent[1] && (extent[1] = other[1]);
  27971. // not setExtent because in log axis it may transformed to power
  27972. // this.setExtent(extent[0], extent[1]);
  27973. };
  27974. /**
  27975. * Set extent from data
  27976. * @param {module:echarts/data/List} data
  27977. * @param {string} dim
  27978. */
  27979. Scale.prototype.unionExtentFromData = function (data, dim) {
  27980. this.unionExtent(data.getApproximateExtent(dim));
  27981. };
  27982. /**
  27983. * Get extent
  27984. * @return {Array.<number>}
  27985. */
  27986. Scale.prototype.getExtent = function () {
  27987. return this._extent.slice();
  27988. };
  27989. /**
  27990. * Set extent
  27991. * @param {number} start
  27992. * @param {number} end
  27993. */
  27994. Scale.prototype.setExtent = function (start, end) {
  27995. var thisExtent = this._extent;
  27996. if (!isNaN(start)) {
  27997. thisExtent[0] = start;
  27998. }
  27999. if (!isNaN(end)) {
  28000. thisExtent[1] = end;
  28001. }
  28002. };
  28003. /**
  28004. * When axis extent depends on data and no data exists,
  28005. * axis ticks should not be drawn, which is named 'blank'.
  28006. */
  28007. Scale.prototype.isBlank = function () {
  28008. return this._isBlank;
  28009. },
  28010. /**
  28011. * When axis extent depends on data and no data exists,
  28012. * axis ticks should not be drawn, which is named 'blank'.
  28013. */
  28014. Scale.prototype.setBlank = function (isBlank) {
  28015. this._isBlank = isBlank;
  28016. };
  28017. /**
  28018. * @abstract
  28019. * @param {*} tick
  28020. * @return {string} label of the tick.
  28021. */
  28022. Scale.prototype.getLabel = null;
  28023. enableClassExtend(Scale);
  28024. enableClassManagement(Scale, {
  28025. registerWhenExtend: true
  28026. });
  28027. /*
  28028. * Licensed to the Apache Software Foundation (ASF) under one
  28029. * or more contributor license agreements. See the NOTICE file
  28030. * distributed with this work for additional information
  28031. * regarding copyright ownership. The ASF licenses this file
  28032. * to you under the Apache License, Version 2.0 (the
  28033. * "License"); you may not use this file except in compliance
  28034. * with the License. You may obtain a copy of the License at
  28035. *
  28036. * http://www.apache.org/licenses/LICENSE-2.0
  28037. *
  28038. * Unless required by applicable law or agreed to in writing,
  28039. * software distributed under the License is distributed on an
  28040. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28041. * KIND, either express or implied. See the License for the
  28042. * specific language governing permissions and limitations
  28043. * under the License.
  28044. */
  28045. /**
  28046. * @constructor
  28047. * @param {Object} [opt]
  28048. * @param {Object} [opt.categories=[]]
  28049. * @param {Object} [opt.needCollect=false]
  28050. * @param {Object} [opt.deduplication=false]
  28051. */
  28052. function OrdinalMeta(opt) {
  28053. /**
  28054. * @readOnly
  28055. * @type {Array.<string>}
  28056. */
  28057. this.categories = opt.categories || [];
  28058. /**
  28059. * @private
  28060. * @type {boolean}
  28061. */
  28062. this._needCollect = opt.needCollect;
  28063. /**
  28064. * @private
  28065. * @type {boolean}
  28066. */
  28067. this._deduplication = opt.deduplication;
  28068. /**
  28069. * @private
  28070. * @type {boolean}
  28071. */
  28072. this._map;
  28073. }
  28074. /**
  28075. * @param {module:echarts/model/Model} axisModel
  28076. * @return {module:echarts/data/OrdinalMeta}
  28077. */
  28078. OrdinalMeta.createByAxisModel = function (axisModel) {
  28079. var option = axisModel.option;
  28080. var data = option.data;
  28081. var categories = data && map(data, getName);
  28082. return new OrdinalMeta({
  28083. categories: categories,
  28084. needCollect: !categories,
  28085. // deduplication is default in axis.
  28086. deduplication: option.dedplication !== false
  28087. });
  28088. };
  28089. var proto$1 = OrdinalMeta.prototype;
  28090. /**
  28091. * @param {string} category
  28092. * @return {number} ordinal
  28093. */
  28094. proto$1.getOrdinal = function (category) {
  28095. return getOrCreateMap(this).get(category);
  28096. };
  28097. /**
  28098. * @param {*} category
  28099. * @return {number} The ordinal. If not found, return NaN.
  28100. */
  28101. proto$1.parseAndCollect = function (category) {
  28102. var index;
  28103. var needCollect = this._needCollect;
  28104. // The value of category dim can be the index of the given category set.
  28105. // This feature is only supported when !needCollect, because we should
  28106. // consider a common case: a value is 2017, which is a number but is
  28107. // expected to be tread as a category. This case usually happen in dataset,
  28108. // where it happent to be no need of the index feature.
  28109. if (typeof category !== 'string' && !needCollect) {
  28110. return category;
  28111. }
  28112. // Optimize for the scenario:
  28113. // category is ['2012-01-01', '2012-01-02', ...], where the input
  28114. // data has been ensured not duplicate and is large data.
  28115. // Notice, if a dataset dimension provide categroies, usually echarts
  28116. // should remove duplication except user tell echarts dont do that
  28117. // (set axis.deduplication = false), because echarts do not know whether
  28118. // the values in the category dimension has duplication (consider the
  28119. // parallel-aqi example)
  28120. if (needCollect && !this._deduplication) {
  28121. index = this.categories.length;
  28122. this.categories[index] = category;
  28123. return index;
  28124. }
  28125. var map$$1 = getOrCreateMap(this);
  28126. index = map$$1.get(category);
  28127. if (index == null) {
  28128. if (needCollect) {
  28129. index = this.categories.length;
  28130. this.categories[index] = category;
  28131. map$$1.set(category, index);
  28132. }
  28133. else {
  28134. index = NaN;
  28135. }
  28136. }
  28137. return index;
  28138. };
  28139. // Consider big data, do not create map until needed.
  28140. function getOrCreateMap(ordinalMeta) {
  28141. return ordinalMeta._map || (
  28142. ordinalMeta._map = createHashMap(ordinalMeta.categories)
  28143. );
  28144. }
  28145. function getName(obj) {
  28146. if (isObject$1(obj) && obj.value != null) {
  28147. return obj.value;
  28148. }
  28149. else {
  28150. return obj + '';
  28151. }
  28152. }
  28153. /*
  28154. * Licensed to the Apache Software Foundation (ASF) under one
  28155. * or more contributor license agreements. See the NOTICE file
  28156. * distributed with this work for additional information
  28157. * regarding copyright ownership. The ASF licenses this file
  28158. * to you under the Apache License, Version 2.0 (the
  28159. * "License"); you may not use this file except in compliance
  28160. * with the License. You may obtain a copy of the License at
  28161. *
  28162. * http://www.apache.org/licenses/LICENSE-2.0
  28163. *
  28164. * Unless required by applicable law or agreed to in writing,
  28165. * software distributed under the License is distributed on an
  28166. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28167. * KIND, either express or implied. See the License for the
  28168. * specific language governing permissions and limitations
  28169. * under the License.
  28170. */
  28171. /**
  28172. * Linear continuous scale
  28173. * @module echarts/coord/scale/Ordinal
  28174. *
  28175. * http://en.wikipedia.org/wiki/Level_of_measurement
  28176. */
  28177. // FIXME only one data
  28178. var scaleProto = Scale.prototype;
  28179. var OrdinalScale = Scale.extend({
  28180. type: 'ordinal',
  28181. /**
  28182. * @param {module:echarts/data/OrdianlMeta|Array.<string>} ordinalMeta
  28183. */
  28184. init: function (ordinalMeta, extent) {
  28185. // Caution: Should not use instanceof, consider ec-extensions using
  28186. // import approach to get OrdinalMeta class.
  28187. if (!ordinalMeta || isArray(ordinalMeta)) {
  28188. ordinalMeta = new OrdinalMeta({categories: ordinalMeta});
  28189. }
  28190. this._ordinalMeta = ordinalMeta;
  28191. this._extent = extent || [0, ordinalMeta.categories.length - 1];
  28192. },
  28193. parse: function (val) {
  28194. return typeof val === 'string'
  28195. ? this._ordinalMeta.getOrdinal(val)
  28196. // val might be float.
  28197. : Math.round(val);
  28198. },
  28199. contain: function (rank) {
  28200. rank = this.parse(rank);
  28201. return scaleProto.contain.call(this, rank)
  28202. && this._ordinalMeta.categories[rank] != null;
  28203. },
  28204. /**
  28205. * Normalize given rank or name to linear [0, 1]
  28206. * @param {number|string} [val]
  28207. * @return {number}
  28208. */
  28209. normalize: function (val) {
  28210. return scaleProto.normalize.call(this, this.parse(val));
  28211. },
  28212. scale: function (val) {
  28213. return Math.round(scaleProto.scale.call(this, val));
  28214. },
  28215. /**
  28216. * @return {Array}
  28217. */
  28218. getTicks: function () {
  28219. var ticks = [];
  28220. var extent = this._extent;
  28221. var rank = extent[0];
  28222. while (rank <= extent[1]) {
  28223. ticks.push(rank);
  28224. rank++;
  28225. }
  28226. return ticks;
  28227. },
  28228. /**
  28229. * Get item on rank n
  28230. * @param {number} n
  28231. * @return {string}
  28232. */
  28233. getLabel: function (n) {
  28234. if (!this.isBlank()) {
  28235. // Note that if no data, ordinalMeta.categories is an empty array.
  28236. return this._ordinalMeta.categories[n];
  28237. }
  28238. },
  28239. /**
  28240. * @return {number}
  28241. */
  28242. count: function () {
  28243. return this._extent[1] - this._extent[0] + 1;
  28244. },
  28245. /**
  28246. * @override
  28247. */
  28248. unionExtentFromData: function (data, dim) {
  28249. this.unionExtent(data.getApproximateExtent(dim));
  28250. },
  28251. getOrdinalMeta: function () {
  28252. return this._ordinalMeta;
  28253. },
  28254. niceTicks: noop,
  28255. niceExtent: noop
  28256. });
  28257. /**
  28258. * @return {module:echarts/scale/Time}
  28259. */
  28260. OrdinalScale.create = function () {
  28261. return new OrdinalScale();
  28262. };
  28263. /*
  28264. * Licensed to the Apache Software Foundation (ASF) under one
  28265. * or more contributor license agreements. See the NOTICE file
  28266. * distributed with this work for additional information
  28267. * regarding copyright ownership. The ASF licenses this file
  28268. * to you under the Apache License, Version 2.0 (the
  28269. * "License"); you may not use this file except in compliance
  28270. * with the License. You may obtain a copy of the License at
  28271. *
  28272. * http://www.apache.org/licenses/LICENSE-2.0
  28273. *
  28274. * Unless required by applicable law or agreed to in writing,
  28275. * software distributed under the License is distributed on an
  28276. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28277. * KIND, either express or implied. See the License for the
  28278. * specific language governing permissions and limitations
  28279. * under the License.
  28280. */
  28281. /**
  28282. * For testable.
  28283. */
  28284. var roundNumber$1 = round$2;
  28285. /**
  28286. * @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
  28287. * Should be extent[0] < extent[1].
  28288. * @param {number} splitNumber splitNumber should be >= 1.
  28289. * @param {number} [minInterval]
  28290. * @param {number} [maxInterval]
  28291. * @return {Object} {interval, intervalPrecision, niceTickExtent}
  28292. */
  28293. function intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval) {
  28294. var result = {};
  28295. var span = extent[1] - extent[0];
  28296. var interval = result.interval = nice(span / splitNumber, true);
  28297. if (minInterval != null && interval < minInterval) {
  28298. interval = result.interval = minInterval;
  28299. }
  28300. if (maxInterval != null && interval > maxInterval) {
  28301. interval = result.interval = maxInterval;
  28302. }
  28303. // Tow more digital for tick.
  28304. var precision = result.intervalPrecision = getIntervalPrecision(interval);
  28305. // Niced extent inside original extent
  28306. var niceTickExtent = result.niceTickExtent = [
  28307. roundNumber$1(Math.ceil(extent[0] / interval) * interval, precision),
  28308. roundNumber$1(Math.floor(extent[1] / interval) * interval, precision)
  28309. ];
  28310. fixExtent(niceTickExtent, extent);
  28311. return result;
  28312. }
  28313. /**
  28314. * @param {number} interval
  28315. * @return {number} interval precision
  28316. */
  28317. function getIntervalPrecision(interval) {
  28318. // Tow more digital for tick.
  28319. return getPrecisionSafe(interval) + 2;
  28320. }
  28321. function clamp(niceTickExtent, idx, extent) {
  28322. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  28323. }
  28324. // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  28325. function fixExtent(niceTickExtent, extent) {
  28326. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  28327. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  28328. clamp(niceTickExtent, 0, extent);
  28329. clamp(niceTickExtent, 1, extent);
  28330. if (niceTickExtent[0] > niceTickExtent[1]) {
  28331. niceTickExtent[0] = niceTickExtent[1];
  28332. }
  28333. }
  28334. function intervalScaleGetTicks(interval, extent, niceTickExtent, intervalPrecision) {
  28335. var ticks = [];
  28336. // If interval is 0, return [];
  28337. if (!interval) {
  28338. return ticks;
  28339. }
  28340. // Consider this case: using dataZoom toolbox, zoom and zoom.
  28341. var safeLimit = 10000;
  28342. if (extent[0] < niceTickExtent[0]) {
  28343. ticks.push(extent[0]);
  28344. }
  28345. var tick = niceTickExtent[0];
  28346. while (tick <= niceTickExtent[1]) {
  28347. ticks.push(tick);
  28348. // Avoid rounding error
  28349. tick = roundNumber$1(tick + interval, intervalPrecision);
  28350. if (tick === ticks[ticks.length - 1]) {
  28351. // Consider out of safe float point, e.g.,
  28352. // -3711126.9907707 + 2e-10 === -3711126.9907707
  28353. break;
  28354. }
  28355. if (ticks.length > safeLimit) {
  28356. return [];
  28357. }
  28358. }
  28359. // Consider this case: the last item of ticks is smaller
  28360. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  28361. if (extent[1] > (ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1])) {
  28362. ticks.push(extent[1]);
  28363. }
  28364. return ticks;
  28365. }
  28366. /*
  28367. * Licensed to the Apache Software Foundation (ASF) under one
  28368. * or more contributor license agreements. See the NOTICE file
  28369. * distributed with this work for additional information
  28370. * regarding copyright ownership. The ASF licenses this file
  28371. * to you under the Apache License, Version 2.0 (the
  28372. * "License"); you may not use this file except in compliance
  28373. * with the License. You may obtain a copy of the License at
  28374. *
  28375. * http://www.apache.org/licenses/LICENSE-2.0
  28376. *
  28377. * Unless required by applicable law or agreed to in writing,
  28378. * software distributed under the License is distributed on an
  28379. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28380. * KIND, either express or implied. See the License for the
  28381. * specific language governing permissions and limitations
  28382. * under the License.
  28383. */
  28384. /**
  28385. * Interval scale
  28386. * @module echarts/scale/Interval
  28387. */
  28388. var roundNumber = round$2;
  28389. /**
  28390. * @alias module:echarts/coord/scale/Interval
  28391. * @constructor
  28392. */
  28393. var IntervalScale = Scale.extend({
  28394. type: 'interval',
  28395. _interval: 0,
  28396. _intervalPrecision: 2,
  28397. setExtent: function (start, end) {
  28398. var thisExtent = this._extent;
  28399. //start,end may be a Number like '25',so...
  28400. if (!isNaN(start)) {
  28401. thisExtent[0] = parseFloat(start);
  28402. }
  28403. if (!isNaN(end)) {
  28404. thisExtent[1] = parseFloat(end);
  28405. }
  28406. },
  28407. unionExtent: function (other) {
  28408. var extent = this._extent;
  28409. other[0] < extent[0] && (extent[0] = other[0]);
  28410. other[1] > extent[1] && (extent[1] = other[1]);
  28411. // unionExtent may called by it's sub classes
  28412. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  28413. },
  28414. /**
  28415. * Get interval
  28416. */
  28417. getInterval: function () {
  28418. return this._interval;
  28419. },
  28420. /**
  28421. * Set interval
  28422. */
  28423. setInterval: function (interval) {
  28424. this._interval = interval;
  28425. // Dropped auto calculated niceExtent and use user setted extent
  28426. // We assume user wan't to set both interval, min, max to get a better result
  28427. this._niceExtent = this._extent.slice();
  28428. this._intervalPrecision = getIntervalPrecision(interval);
  28429. },
  28430. /**
  28431. * @return {Array.<number>}
  28432. */
  28433. getTicks: function () {
  28434. return intervalScaleGetTicks(
  28435. this._interval, this._extent, this._niceExtent, this._intervalPrecision
  28436. );
  28437. },
  28438. /**
  28439. * @param {number} data
  28440. * @param {Object} [opt]
  28441. * @param {number|string} [opt.precision] If 'auto', use nice presision.
  28442. * @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
  28443. * @return {string}
  28444. */
  28445. getLabel: function (data, opt) {
  28446. if (data == null) {
  28447. return '';
  28448. }
  28449. var precision = opt && opt.precision;
  28450. if (precision == null) {
  28451. precision = getPrecisionSafe(data) || 0;
  28452. }
  28453. else if (precision === 'auto') {
  28454. // Should be more precise then tick.
  28455. precision = this._intervalPrecision;
  28456. }
  28457. // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  28458. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  28459. data = roundNumber(data, precision, true);
  28460. return addCommas(data);
  28461. },
  28462. /**
  28463. * Update interval and extent of intervals for nice ticks
  28464. *
  28465. * @param {number} [splitNumber = 5] Desired number of ticks
  28466. * @param {number} [minInterval]
  28467. * @param {number} [maxInterval]
  28468. */
  28469. niceTicks: function (splitNumber, minInterval, maxInterval) {
  28470. splitNumber = splitNumber || 5;
  28471. var extent = this._extent;
  28472. var span = extent[1] - extent[0];
  28473. if (!isFinite(span)) {
  28474. return;
  28475. }
  28476. // User may set axis min 0 and data are all negative
  28477. // FIXME If it needs to reverse ?
  28478. if (span < 0) {
  28479. span = -span;
  28480. extent.reverse();
  28481. }
  28482. var result = intervalScaleNiceTicks(
  28483. extent, splitNumber, minInterval, maxInterval
  28484. );
  28485. this._intervalPrecision = result.intervalPrecision;
  28486. this._interval = result.interval;
  28487. this._niceExtent = result.niceTickExtent;
  28488. },
  28489. /**
  28490. * Nice extent.
  28491. * @param {Object} opt
  28492. * @param {number} [opt.splitNumber = 5] Given approx tick number
  28493. * @param {boolean} [opt.fixMin=false]
  28494. * @param {boolean} [opt.fixMax=false]
  28495. * @param {boolean} [opt.minInterval]
  28496. * @param {boolean} [opt.maxInterval]
  28497. */
  28498. niceExtent: function (opt) {
  28499. var extent = this._extent;
  28500. // If extent start and end are same, expand them
  28501. if (extent[0] === extent[1]) {
  28502. if (extent[0] !== 0) {
  28503. // Expand extent
  28504. var expandSize = extent[0];
  28505. // In the fowllowing case
  28506. // Axis has been fixed max 100
  28507. // Plus data are all 100 and axis extent are [100, 100].
  28508. // Extend to the both side will cause expanded max is larger than fixed max.
  28509. // So only expand to the smaller side.
  28510. if (!opt.fixMax) {
  28511. extent[1] += expandSize / 2;
  28512. extent[0] -= expandSize / 2;
  28513. }
  28514. else {
  28515. extent[0] -= expandSize / 2;
  28516. }
  28517. }
  28518. else {
  28519. extent[1] = 1;
  28520. }
  28521. }
  28522. var span = extent[1] - extent[0];
  28523. // If there are no data and extent are [Infinity, -Infinity]
  28524. if (!isFinite(span)) {
  28525. extent[0] = 0;
  28526. extent[1] = 1;
  28527. }
  28528. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  28529. // var extent = this._extent;
  28530. var interval = this._interval;
  28531. if (!opt.fixMin) {
  28532. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
  28533. }
  28534. if (!opt.fixMax) {
  28535. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
  28536. }
  28537. }
  28538. });
  28539. /**
  28540. * @return {module:echarts/scale/Time}
  28541. */
  28542. IntervalScale.create = function () {
  28543. return new IntervalScale();
  28544. };
  28545. /*
  28546. * Licensed to the Apache Software Foundation (ASF) under one
  28547. * or more contributor license agreements. See the NOTICE file
  28548. * distributed with this work for additional information
  28549. * regarding copyright ownership. The ASF licenses this file
  28550. * to you under the Apache License, Version 2.0 (the
  28551. * "License"); you may not use this file except in compliance
  28552. * with the License. You may obtain a copy of the License at
  28553. *
  28554. * http://www.apache.org/licenses/LICENSE-2.0
  28555. *
  28556. * Unless required by applicable law or agreed to in writing,
  28557. * software distributed under the License is distributed on an
  28558. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28559. * KIND, either express or implied. See the License for the
  28560. * specific language governing permissions and limitations
  28561. * under the License.
  28562. */
  28563. /* global Float32Array */
  28564. var STACK_PREFIX = '__ec_stack_';
  28565. var LARGE_BAR_MIN_WIDTH = 0.5;
  28566. var LargeArr = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  28567. function getSeriesStackId(seriesModel) {
  28568. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  28569. }
  28570. function getAxisKey(axis) {
  28571. return axis.dim + axis.index;
  28572. }
  28573. /**
  28574. * @param {Object} opt
  28575. * @param {module:echarts/coord/Axis} opt.axis Only support category axis currently.
  28576. * @param {number} opt.count Positive interger.
  28577. * @param {number} [opt.barWidth]
  28578. * @param {number} [opt.barMaxWidth]
  28579. * @param {number} [opt.barGap]
  28580. * @param {number} [opt.barCategoryGap]
  28581. * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
  28582. */
  28583. function getLayoutOnAxis(opt) {
  28584. var params = [];
  28585. var baseAxis = opt.axis;
  28586. var axisKey = 'axis0';
  28587. if (baseAxis.type !== 'category') {
  28588. return;
  28589. }
  28590. var bandWidth = baseAxis.getBandWidth();
  28591. for (var i = 0; i < opt.count || 0; i++) {
  28592. params.push(defaults({
  28593. bandWidth: bandWidth,
  28594. axisKey: axisKey,
  28595. stackId: STACK_PREFIX + i
  28596. }, opt));
  28597. }
  28598. var widthAndOffsets = doCalBarWidthAndOffset(params);
  28599. var result = [];
  28600. for (var i = 0; i < opt.count; i++) {
  28601. var item = widthAndOffsets[axisKey][STACK_PREFIX + i];
  28602. item.offsetCenter = item.offset + item.width / 2;
  28603. result.push(item);
  28604. }
  28605. return result;
  28606. }
  28607. function prepareLayoutBarSeries(seriesType, ecModel) {
  28608. var seriesModels = [];
  28609. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  28610. // Check series coordinate, do layout for cartesian2d only
  28611. if (isOnCartesian(seriesModel) && !isInLargeMode(seriesModel)) {
  28612. seriesModels.push(seriesModel);
  28613. }
  28614. });
  28615. return seriesModels;
  28616. }
  28617. function makeColumnLayout(barSeries) {
  28618. var seriesInfoList = [];
  28619. each$1(barSeries, function (seriesModel) {
  28620. var data = seriesModel.getData();
  28621. var cartesian = seriesModel.coordinateSystem;
  28622. var baseAxis = cartesian.getBaseAxis();
  28623. var axisExtent = baseAxis.getExtent();
  28624. var bandWidth = baseAxis.type === 'category'
  28625. ? baseAxis.getBandWidth()
  28626. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  28627. var barWidth = parsePercent$1(
  28628. seriesModel.get('barWidth'), bandWidth
  28629. );
  28630. var barMaxWidth = parsePercent$1(
  28631. seriesModel.get('barMaxWidth'), bandWidth
  28632. );
  28633. var barGap = seriesModel.get('barGap');
  28634. var barCategoryGap = seriesModel.get('barCategoryGap');
  28635. seriesInfoList.push({
  28636. bandWidth: bandWidth,
  28637. barWidth: barWidth,
  28638. barMaxWidth: barMaxWidth,
  28639. barGap: barGap,
  28640. barCategoryGap: barCategoryGap,
  28641. axisKey: getAxisKey(baseAxis),
  28642. stackId: getSeriesStackId(seriesModel)
  28643. });
  28644. });
  28645. return doCalBarWidthAndOffset(seriesInfoList);
  28646. }
  28647. function doCalBarWidthAndOffset(seriesInfoList) {
  28648. // Columns info on each category axis. Key is cartesian name
  28649. var columnsMap = {};
  28650. each$1(seriesInfoList, function (seriesInfo, idx) {
  28651. var axisKey = seriesInfo.axisKey;
  28652. var bandWidth = seriesInfo.bandWidth;
  28653. var columnsOnAxis = columnsMap[axisKey] || {
  28654. bandWidth: bandWidth,
  28655. remainedWidth: bandWidth,
  28656. autoWidthCount: 0,
  28657. categoryGap: '20%',
  28658. gap: '30%',
  28659. stacks: {}
  28660. };
  28661. var stacks = columnsOnAxis.stacks;
  28662. columnsMap[axisKey] = columnsOnAxis;
  28663. var stackId = seriesInfo.stackId;
  28664. if (!stacks[stackId]) {
  28665. columnsOnAxis.autoWidthCount++;
  28666. }
  28667. stacks[stackId] = stacks[stackId] || {
  28668. width: 0,
  28669. maxWidth: 0
  28670. };
  28671. // Caution: In a single coordinate system, these barGrid attributes
  28672. // will be shared by series. Consider that they have default values,
  28673. // only the attributes set on the last series will work.
  28674. // Do not change this fact unless there will be a break change.
  28675. // TODO
  28676. var barWidth = seriesInfo.barWidth;
  28677. if (barWidth && !stacks[stackId].width) {
  28678. // See #6312, do not restrict width.
  28679. stacks[stackId].width = barWidth;
  28680. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  28681. columnsOnAxis.remainedWidth -= barWidth;
  28682. }
  28683. var barMaxWidth = seriesInfo.barMaxWidth;
  28684. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  28685. var barGap = seriesInfo.barGap;
  28686. (barGap != null) && (columnsOnAxis.gap = barGap);
  28687. var barCategoryGap = seriesInfo.barCategoryGap;
  28688. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  28689. });
  28690. var result = {};
  28691. each$1(columnsMap, function (columnsOnAxis, coordSysName) {
  28692. result[coordSysName] = {};
  28693. var stacks = columnsOnAxis.stacks;
  28694. var bandWidth = columnsOnAxis.bandWidth;
  28695. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  28696. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  28697. var remainedWidth = columnsOnAxis.remainedWidth;
  28698. var autoWidthCount = columnsOnAxis.autoWidthCount;
  28699. var autoWidth = (remainedWidth - categoryGap)
  28700. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  28701. autoWidth = Math.max(autoWidth, 0);
  28702. // Find if any auto calculated bar exceeded maxBarWidth
  28703. each$1(stacks, function (column, stack) {
  28704. var maxWidth = column.maxWidth;
  28705. if (maxWidth && maxWidth < autoWidth) {
  28706. maxWidth = Math.min(maxWidth, remainedWidth);
  28707. if (column.width) {
  28708. maxWidth = Math.min(maxWidth, column.width);
  28709. }
  28710. remainedWidth -= maxWidth;
  28711. column.width = maxWidth;
  28712. autoWidthCount--;
  28713. }
  28714. });
  28715. // Recalculate width again
  28716. autoWidth = (remainedWidth - categoryGap)
  28717. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  28718. autoWidth = Math.max(autoWidth, 0);
  28719. var widthSum = 0;
  28720. var lastColumn;
  28721. each$1(stacks, function (column, idx) {
  28722. if (!column.width) {
  28723. column.width = autoWidth;
  28724. }
  28725. lastColumn = column;
  28726. widthSum += column.width * (1 + barGapPercent);
  28727. });
  28728. if (lastColumn) {
  28729. widthSum -= lastColumn.width * barGapPercent;
  28730. }
  28731. var offset = -widthSum / 2;
  28732. each$1(stacks, function (column, stackId) {
  28733. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  28734. offset: offset,
  28735. width: column.width
  28736. };
  28737. offset += column.width * (1 + barGapPercent);
  28738. });
  28739. });
  28740. return result;
  28741. }
  28742. /**
  28743. * @param {Object} barWidthAndOffset The result of makeColumnLayout
  28744. * @param {module:echarts/coord/Axis} axis
  28745. * @param {module:echarts/model/Series} [seriesModel] If not provided, return all.
  28746. * @return {Object} {stackId: {offset, width}} or {offset, width} if seriesModel provided.
  28747. */
  28748. function retrieveColumnLayout(barWidthAndOffset, axis, seriesModel) {
  28749. if (barWidthAndOffset && axis) {
  28750. var result = barWidthAndOffset[getAxisKey(axis)];
  28751. if (result != null && seriesModel != null) {
  28752. result = result[getSeriesStackId(seriesModel)];
  28753. }
  28754. return result;
  28755. }
  28756. }
  28757. /**
  28758. * @param {string} seriesType
  28759. * @param {module:echarts/model/Global} ecModel
  28760. */
  28761. function layout(seriesType, ecModel) {
  28762. var seriesModels = prepareLayoutBarSeries(seriesType, ecModel);
  28763. var barWidthAndOffset = makeColumnLayout(seriesModels);
  28764. var lastStackCoords = {};
  28765. each$1(seriesModels, function (seriesModel) {
  28766. var data = seriesModel.getData();
  28767. var cartesian = seriesModel.coordinateSystem;
  28768. var baseAxis = cartesian.getBaseAxis();
  28769. var stackId = getSeriesStackId(seriesModel);
  28770. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  28771. var columnOffset = columnLayoutInfo.offset;
  28772. var columnWidth = columnLayoutInfo.width;
  28773. var valueAxis = cartesian.getOtherAxis(baseAxis);
  28774. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  28775. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  28776. data.setLayout({
  28777. offset: columnOffset,
  28778. size: columnWidth
  28779. });
  28780. var valueDim = data.mapDimension(valueAxis.dim);
  28781. var baseDim = data.mapDimension(baseAxis.dim);
  28782. var stacked = isDimensionStacked(data, valueDim /*, baseDim*/);
  28783. var isValueAxisH = valueAxis.isHorizontal();
  28784. var valueAxisStart = getValueAxisStart(baseAxis, valueAxis, stacked);
  28785. for (var idx = 0, len = data.count(); idx < len; idx++) {
  28786. var value = data.get(valueDim, idx);
  28787. var baseValue = data.get(baseDim, idx);
  28788. if (isNaN(value)) {
  28789. continue;
  28790. }
  28791. var sign = value >= 0 ? 'p' : 'n';
  28792. var baseCoord = valueAxisStart;
  28793. // Because of the barMinHeight, we can not use the value in
  28794. // stackResultDimension directly.
  28795. if (stacked) {
  28796. // Only ordinal axis can be stacked.
  28797. if (!lastStackCoords[stackId][baseValue]) {
  28798. lastStackCoords[stackId][baseValue] = {
  28799. p: valueAxisStart, // Positive stack
  28800. n: valueAxisStart // Negative stack
  28801. };
  28802. }
  28803. // Should also consider #4243
  28804. baseCoord = lastStackCoords[stackId][baseValue][sign];
  28805. }
  28806. var x;
  28807. var y;
  28808. var width;
  28809. var height;
  28810. if (isValueAxisH) {
  28811. var coord = cartesian.dataToPoint([value, baseValue]);
  28812. x = baseCoord;
  28813. y = coord[1] + columnOffset;
  28814. width = coord[0] - valueAxisStart;
  28815. height = columnWidth;
  28816. if (Math.abs(width) < barMinHeight) {
  28817. width = (width < 0 ? -1 : 1) * barMinHeight;
  28818. }
  28819. stacked && (lastStackCoords[stackId][baseValue][sign] += width);
  28820. }
  28821. else {
  28822. var coord = cartesian.dataToPoint([baseValue, value]);
  28823. x = coord[0] + columnOffset;
  28824. y = baseCoord;
  28825. width = columnWidth;
  28826. height = coord[1] - valueAxisStart;
  28827. if (Math.abs(height) < barMinHeight) {
  28828. // Include zero to has a positive bar
  28829. height = (height <= 0 ? -1 : 1) * barMinHeight;
  28830. }
  28831. stacked && (lastStackCoords[stackId][baseValue][sign] += height);
  28832. }
  28833. data.setItemLayout(idx, {
  28834. x: x,
  28835. y: y,
  28836. width: width,
  28837. height: height
  28838. });
  28839. }
  28840. }, this);
  28841. }
  28842. // TODO: Do not support stack in large mode yet.
  28843. var largeLayout = {
  28844. seriesType: 'bar',
  28845. plan: createRenderPlanner(),
  28846. reset: function (seriesModel) {
  28847. if (!isOnCartesian(seriesModel) || !isInLargeMode(seriesModel)) {
  28848. return;
  28849. }
  28850. var data = seriesModel.getData();
  28851. var cartesian = seriesModel.coordinateSystem;
  28852. var baseAxis = cartesian.getBaseAxis();
  28853. var valueAxis = cartesian.getOtherAxis(baseAxis);
  28854. var valueDim = data.mapDimension(valueAxis.dim);
  28855. var baseDim = data.mapDimension(baseAxis.dim);
  28856. var valueAxisHorizontal = valueAxis.isHorizontal();
  28857. var valueDimIdx = valueAxisHorizontal ? 0 : 1;
  28858. var barWidth = retrieveColumnLayout(
  28859. makeColumnLayout([seriesModel]), baseAxis, seriesModel
  28860. ).width;
  28861. if (!(barWidth > LARGE_BAR_MIN_WIDTH)) { // jshint ignore:line
  28862. barWidth = LARGE_BAR_MIN_WIDTH;
  28863. }
  28864. return {progress: progress};
  28865. function progress(params, data) {
  28866. var largePoints = new LargeArr(params.count * 2);
  28867. var dataIndex;
  28868. var coord = [];
  28869. var valuePair = [];
  28870. var offset = 0;
  28871. while ((dataIndex = params.next()) != null) {
  28872. valuePair[valueDimIdx] = data.get(valueDim, dataIndex);
  28873. valuePair[1 - valueDimIdx] = data.get(baseDim, dataIndex);
  28874. coord = cartesian.dataToPoint(valuePair, null, coord);
  28875. largePoints[offset++] = coord[0];
  28876. largePoints[offset++] = coord[1];
  28877. }
  28878. data.setLayout({
  28879. largePoints: largePoints,
  28880. barWidth: barWidth,
  28881. valueAxisStart: getValueAxisStart(baseAxis, valueAxis, false),
  28882. valueAxisHorizontal: valueAxisHorizontal
  28883. });
  28884. }
  28885. }
  28886. };
  28887. function isOnCartesian(seriesModel) {
  28888. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  28889. }
  28890. function isInLargeMode(seriesModel) {
  28891. return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
  28892. }
  28893. // See cases in `test/bar-start.html` and `#7412`, `#8747`.
  28894. function getValueAxisStart(baseAxis, valueAxis, stacked) {
  28895. var extent = valueAxis.getGlobalExtent();
  28896. var min;
  28897. var max;
  28898. if (extent[0] > extent[1]) {
  28899. min = extent[1];
  28900. max = extent[0];
  28901. }
  28902. else {
  28903. min = extent[0];
  28904. max = extent[1];
  28905. }
  28906. var valueStart = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
  28907. valueStart < min && (valueStart = min);
  28908. valueStart > max && (valueStart = max);
  28909. return valueStart;
  28910. }
  28911. /*
  28912. * Licensed to the Apache Software Foundation (ASF) under one
  28913. * or more contributor license agreements. See the NOTICE file
  28914. * distributed with this work for additional information
  28915. * regarding copyright ownership. The ASF licenses this file
  28916. * to you under the Apache License, Version 2.0 (the
  28917. * "License"); you may not use this file except in compliance
  28918. * with the License. You may obtain a copy of the License at
  28919. *
  28920. * http://www.apache.org/licenses/LICENSE-2.0
  28921. *
  28922. * Unless required by applicable law or agreed to in writing,
  28923. * software distributed under the License is distributed on an
  28924. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28925. * KIND, either express or implied. See the License for the
  28926. * specific language governing permissions and limitations
  28927. * under the License.
  28928. */
  28929. /*
  28930. * A third-party license is embeded for some of the code in this file:
  28931. * The "scaleLevels" was originally copied from "d3.js" with some
  28932. * modifications made for this project.
  28933. * (See more details in the comment on the definition of "scaleLevels" below.)
  28934. * The use of the source code of this file is also subject to the terms
  28935. * and consitions of the license of "d3.js" (BSD-3Clause, see
  28936. * </licenses/LICENSE-d3>).
  28937. */
  28938. // [About UTC and local time zone]:
  28939. // In most cases, `number.parseDate` will treat input data string as local time
  28940. // (except time zone is specified in time string). And `format.formateTime` returns
  28941. // local time by default. option.useUTC is false by default. This design have
  28942. // concidered these common case:
  28943. // (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
  28944. // in local time by default.
  28945. // (2) By default, the input data string (e.g., '2011-01-02') should be displayed
  28946. // as its original time, without any time difference.
  28947. var intervalScaleProto = IntervalScale.prototype;
  28948. var mathCeil = Math.ceil;
  28949. var mathFloor = Math.floor;
  28950. var ONE_SECOND = 1000;
  28951. var ONE_MINUTE = ONE_SECOND * 60;
  28952. var ONE_HOUR = ONE_MINUTE * 60;
  28953. var ONE_DAY = ONE_HOUR * 24;
  28954. // FIXME 公用?
  28955. var bisect = function (a, x, lo, hi) {
  28956. while (lo < hi) {
  28957. var mid = lo + hi >>> 1;
  28958. if (a[mid][1] < x) {
  28959. lo = mid + 1;
  28960. }
  28961. else {
  28962. hi = mid;
  28963. }
  28964. }
  28965. return lo;
  28966. };
  28967. /**
  28968. * @alias module:echarts/coord/scale/Time
  28969. * @constructor
  28970. */
  28971. var TimeScale = IntervalScale.extend({
  28972. type: 'time',
  28973. /**
  28974. * @override
  28975. */
  28976. getLabel: function (val) {
  28977. var stepLvl = this._stepLvl;
  28978. var date = new Date(val);
  28979. return formatTime(stepLvl[0], date, this.getSetting('useUTC'));
  28980. },
  28981. /**
  28982. * @override
  28983. */
  28984. niceExtent: function (opt) {
  28985. var extent = this._extent;
  28986. // If extent start and end are same, expand them
  28987. if (extent[0] === extent[1]) {
  28988. // Expand extent
  28989. extent[0] -= ONE_DAY;
  28990. extent[1] += ONE_DAY;
  28991. }
  28992. // If there are no data and extent are [Infinity, -Infinity]
  28993. if (extent[1] === -Infinity && extent[0] === Infinity) {
  28994. var d = new Date();
  28995. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  28996. extent[0] = extent[1] - ONE_DAY;
  28997. }
  28998. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  28999. // var extent = this._extent;
  29000. var interval = this._interval;
  29001. if (!opt.fixMin) {
  29002. extent[0] = round$2(mathFloor(extent[0] / interval) * interval);
  29003. }
  29004. if (!opt.fixMax) {
  29005. extent[1] = round$2(mathCeil(extent[1] / interval) * interval);
  29006. }
  29007. },
  29008. /**
  29009. * @override
  29010. */
  29011. niceTicks: function (approxTickNum, minInterval, maxInterval) {
  29012. approxTickNum = approxTickNum || 10;
  29013. var extent = this._extent;
  29014. var span = extent[1] - extent[0];
  29015. var approxInterval = span / approxTickNum;
  29016. if (minInterval != null && approxInterval < minInterval) {
  29017. approxInterval = minInterval;
  29018. }
  29019. if (maxInterval != null && approxInterval > maxInterval) {
  29020. approxInterval = maxInterval;
  29021. }
  29022. var scaleLevelsLen = scaleLevels.length;
  29023. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  29024. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  29025. var interval = level[1];
  29026. // Same with interval scale if span is much larger than 1 year
  29027. if (level[0] === 'year') {
  29028. var yearSpan = span / interval;
  29029. // From "Nice Numbers for Graph Labels" of Graphic Gems
  29030. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  29031. var yearStep = nice(yearSpan / approxTickNum, true);
  29032. interval *= yearStep;
  29033. }
  29034. var timezoneOffset = this.getSetting('useUTC')
  29035. ? 0 : (new Date(+extent[0] || +extent[1])).getTimezoneOffset() * 60 * 1000;
  29036. var niceExtent = [
  29037. Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset),
  29038. Math.round(mathFloor((extent[1] - timezoneOffset) / interval) * interval + timezoneOffset)
  29039. ];
  29040. fixExtent(niceExtent, extent);
  29041. this._stepLvl = level;
  29042. // Interval will be used in getTicks
  29043. this._interval = interval;
  29044. this._niceExtent = niceExtent;
  29045. },
  29046. parse: function (val) {
  29047. // val might be float.
  29048. return +parseDate(val);
  29049. }
  29050. });
  29051. each$1(['contain', 'normalize'], function (methodName) {
  29052. TimeScale.prototype[methodName] = function (val) {
  29053. return intervalScaleProto[methodName].call(this, this.parse(val));
  29054. };
  29055. });
  29056. /**
  29057. * This implementation was originally copied from "d3.js"
  29058. * <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
  29059. * with some modifications made for this program.
  29060. * See the license statement at the head of this file.
  29061. */
  29062. var scaleLevels = [
  29063. // Format interval
  29064. ['hh:mm:ss', ONE_SECOND], // 1s
  29065. ['hh:mm:ss', ONE_SECOND * 5], // 5s
  29066. ['hh:mm:ss', ONE_SECOND * 10], // 10s
  29067. ['hh:mm:ss', ONE_SECOND * 15], // 15s
  29068. ['hh:mm:ss', ONE_SECOND * 30], // 30s
  29069. ['hh:mm\nMM-dd', ONE_MINUTE], // 1m
  29070. ['hh:mm\nMM-dd', ONE_MINUTE * 5], // 5m
  29071. ['hh:mm\nMM-dd', ONE_MINUTE * 10], // 10m
  29072. ['hh:mm\nMM-dd', ONE_MINUTE * 15], // 15m
  29073. ['hh:mm\nMM-dd', ONE_MINUTE * 30], // 30m
  29074. ['hh:mm\nMM-dd', ONE_HOUR], // 1h
  29075. ['hh:mm\nMM-dd', ONE_HOUR * 2], // 2h
  29076. ['hh:mm\nMM-dd', ONE_HOUR * 6], // 6h
  29077. ['hh:mm\nMM-dd', ONE_HOUR * 12], // 12h
  29078. ['MM-dd\nyyyy', ONE_DAY], // 1d
  29079. ['MM-dd\nyyyy', ONE_DAY * 2], // 2d
  29080. ['MM-dd\nyyyy', ONE_DAY * 3], // 3d
  29081. ['MM-dd\nyyyy', ONE_DAY * 4], // 4d
  29082. ['MM-dd\nyyyy', ONE_DAY * 5], // 5d
  29083. ['MM-dd\nyyyy', ONE_DAY * 6], // 6d
  29084. ['week', ONE_DAY * 7], // 7d
  29085. ['MM-dd\nyyyy', ONE_DAY * 10], // 10d
  29086. ['week', ONE_DAY * 14], // 2w
  29087. ['week', ONE_DAY * 21], // 3w
  29088. ['month', ONE_DAY * 31], // 1M
  29089. ['week', ONE_DAY * 42], // 6w
  29090. ['month', ONE_DAY * 62], // 2M
  29091. ['week', ONE_DAY * 70], // 10w
  29092. ['quarter', ONE_DAY * 95], // 3M
  29093. ['month', ONE_DAY * 31 * 4], // 4M
  29094. ['month', ONE_DAY * 31 * 5], // 5M
  29095. ['half-year', ONE_DAY * 380 / 2], // 6M
  29096. ['month', ONE_DAY * 31 * 8], // 8M
  29097. ['month', ONE_DAY * 31 * 10], // 10M
  29098. ['year', ONE_DAY * 380] // 1Y
  29099. ];
  29100. /**
  29101. * @param {module:echarts/model/Model}
  29102. * @return {module:echarts/scale/Time}
  29103. */
  29104. TimeScale.create = function (model) {
  29105. return new TimeScale({useUTC: model.ecModel.get('useUTC')});
  29106. };
  29107. /*
  29108. * Licensed to the Apache Software Foundation (ASF) under one
  29109. * or more contributor license agreements. See the NOTICE file
  29110. * distributed with this work for additional information
  29111. * regarding copyright ownership. The ASF licenses this file
  29112. * to you under the Apache License, Version 2.0 (the
  29113. * "License"); you may not use this file except in compliance
  29114. * with the License. You may obtain a copy of the License at
  29115. *
  29116. * http://www.apache.org/licenses/LICENSE-2.0
  29117. *
  29118. * Unless required by applicable law or agreed to in writing,
  29119. * software distributed under the License is distributed on an
  29120. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29121. * KIND, either express or implied. See the License for the
  29122. * specific language governing permissions and limitations
  29123. * under the License.
  29124. */
  29125. /**
  29126. * Log scale
  29127. * @module echarts/scale/Log
  29128. */
  29129. // Use some method of IntervalScale
  29130. var scaleProto$1 = Scale.prototype;
  29131. var intervalScaleProto$1 = IntervalScale.prototype;
  29132. var getPrecisionSafe$1 = getPrecisionSafe;
  29133. var roundingErrorFix = round$2;
  29134. var mathFloor$1 = Math.floor;
  29135. var mathCeil$1 = Math.ceil;
  29136. var mathPow$1 = Math.pow;
  29137. var mathLog = Math.log;
  29138. var LogScale = Scale.extend({
  29139. type: 'log',
  29140. base: 10,
  29141. $constructor: function () {
  29142. Scale.apply(this, arguments);
  29143. this._originalScale = new IntervalScale();
  29144. },
  29145. /**
  29146. * @return {Array.<number>}
  29147. */
  29148. getTicks: function () {
  29149. var originalScale = this._originalScale;
  29150. var extent = this._extent;
  29151. var originalExtent = originalScale.getExtent();
  29152. return map(intervalScaleProto$1.getTicks.call(this), function (val) {
  29153. var powVal = round$2(mathPow$1(this.base, val));
  29154. // Fix #4158
  29155. powVal = (val === extent[0] && originalScale.__fixMin)
  29156. ? fixRoundingError(powVal, originalExtent[0])
  29157. : powVal;
  29158. powVal = (val === extent[1] && originalScale.__fixMax)
  29159. ? fixRoundingError(powVal, originalExtent[1])
  29160. : powVal;
  29161. return powVal;
  29162. }, this);
  29163. },
  29164. /**
  29165. * @param {number} val
  29166. * @return {string}
  29167. */
  29168. getLabel: intervalScaleProto$1.getLabel,
  29169. /**
  29170. * @param {number} val
  29171. * @return {number}
  29172. */
  29173. scale: function (val) {
  29174. val = scaleProto$1.scale.call(this, val);
  29175. return mathPow$1(this.base, val);
  29176. },
  29177. /**
  29178. * @param {number} start
  29179. * @param {number} end
  29180. */
  29181. setExtent: function (start, end) {
  29182. var base = this.base;
  29183. start = mathLog(start) / mathLog(base);
  29184. end = mathLog(end) / mathLog(base);
  29185. intervalScaleProto$1.setExtent.call(this, start, end);
  29186. },
  29187. /**
  29188. * @return {number} end
  29189. */
  29190. getExtent: function () {
  29191. var base = this.base;
  29192. var extent = scaleProto$1.getExtent.call(this);
  29193. extent[0] = mathPow$1(base, extent[0]);
  29194. extent[1] = mathPow$1(base, extent[1]);
  29195. // Fix #4158
  29196. var originalScale = this._originalScale;
  29197. var originalExtent = originalScale.getExtent();
  29198. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  29199. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  29200. return extent;
  29201. },
  29202. /**
  29203. * @param {Array.<number>} extent
  29204. */
  29205. unionExtent: function (extent) {
  29206. this._originalScale.unionExtent(extent);
  29207. var base = this.base;
  29208. extent[0] = mathLog(extent[0]) / mathLog(base);
  29209. extent[1] = mathLog(extent[1]) / mathLog(base);
  29210. scaleProto$1.unionExtent.call(this, extent);
  29211. },
  29212. /**
  29213. * @override
  29214. */
  29215. unionExtentFromData: function (data, dim) {
  29216. // TODO
  29217. // filter value that <= 0
  29218. this.unionExtent(data.getApproximateExtent(dim));
  29219. },
  29220. /**
  29221. * Update interval and extent of intervals for nice ticks
  29222. * @param {number} [approxTickNum = 10] Given approx tick number
  29223. */
  29224. niceTicks: function (approxTickNum) {
  29225. approxTickNum = approxTickNum || 10;
  29226. var extent = this._extent;
  29227. var span = extent[1] - extent[0];
  29228. if (span === Infinity || span <= 0) {
  29229. return;
  29230. }
  29231. var interval = quantity(span);
  29232. var err = approxTickNum / span * interval;
  29233. // Filter ticks to get closer to the desired count.
  29234. if (err <= 0.5) {
  29235. interval *= 10;
  29236. }
  29237. // Interval should be integer
  29238. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  29239. interval *= 10;
  29240. }
  29241. var niceExtent = [
  29242. round$2(mathCeil$1(extent[0] / interval) * interval),
  29243. round$2(mathFloor$1(extent[1] / interval) * interval)
  29244. ];
  29245. this._interval = interval;
  29246. this._niceExtent = niceExtent;
  29247. },
  29248. /**
  29249. * Nice extent.
  29250. * @override
  29251. */
  29252. niceExtent: function (opt) {
  29253. intervalScaleProto$1.niceExtent.call(this, opt);
  29254. var originalScale = this._originalScale;
  29255. originalScale.__fixMin = opt.fixMin;
  29256. originalScale.__fixMax = opt.fixMax;
  29257. }
  29258. });
  29259. each$1(['contain', 'normalize'], function (methodName) {
  29260. LogScale.prototype[methodName] = function (val) {
  29261. val = mathLog(val) / mathLog(this.base);
  29262. return scaleProto$1[methodName].call(this, val);
  29263. };
  29264. });
  29265. LogScale.create = function () {
  29266. return new LogScale();
  29267. };
  29268. function fixRoundingError(val, originalVal) {
  29269. return roundingErrorFix(val, getPrecisionSafe$1(originalVal));
  29270. }
  29271. /*
  29272. * Licensed to the Apache Software Foundation (ASF) under one
  29273. * or more contributor license agreements. See the NOTICE file
  29274. * distributed with this work for additional information
  29275. * regarding copyright ownership. The ASF licenses this file
  29276. * to you under the Apache License, Version 2.0 (the
  29277. * "License"); you may not use this file except in compliance
  29278. * with the License. You may obtain a copy of the License at
  29279. *
  29280. * http://www.apache.org/licenses/LICENSE-2.0
  29281. *
  29282. * Unless required by applicable law or agreed to in writing,
  29283. * software distributed under the License is distributed on an
  29284. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29285. * KIND, either express or implied. See the License for the
  29286. * specific language governing permissions and limitations
  29287. * under the License.
  29288. */
  29289. /**
  29290. * Get axis scale extent before niced.
  29291. * Item of returned array can only be number (including Infinity and NaN).
  29292. */
  29293. function getScaleExtent(scale, model) {
  29294. var scaleType = scale.type;
  29295. var min = model.getMin();
  29296. var max = model.getMax();
  29297. var fixMin = min != null;
  29298. var fixMax = max != null;
  29299. var originalExtent = scale.getExtent();
  29300. var axisDataLen;
  29301. var boundaryGap;
  29302. var span;
  29303. if (scaleType === 'ordinal') {
  29304. axisDataLen = model.getCategories().length;
  29305. }
  29306. else {
  29307. boundaryGap = model.get('boundaryGap');
  29308. if (!isArray(boundaryGap)) {
  29309. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  29310. }
  29311. if (typeof boundaryGap[0] === 'boolean') {
  29312. if (__DEV__) {
  29313. console.warn('Boolean type for boundaryGap is only '
  29314. + 'allowed for ordinal axis. Please use string in '
  29315. + 'percentage instead, e.g., "20%". Currently, '
  29316. + 'boundaryGap is set to be 0.');
  29317. }
  29318. boundaryGap = [0, 0];
  29319. }
  29320. boundaryGap[0] = parsePercent$1(boundaryGap[0], 1);
  29321. boundaryGap[1] = parsePercent$1(boundaryGap[1], 1);
  29322. span = (originalExtent[1] - originalExtent[0])
  29323. || Math.abs(originalExtent[0]);
  29324. }
  29325. // Notice: When min/max is not set (that is, when there are null/undefined,
  29326. // which is the most common case), these cases should be ensured:
  29327. // (1) For 'ordinal', show all axis.data.
  29328. // (2) For others:
  29329. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  29330. // disabled).
  29331. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  29332. // be the result that originalExtent enlarged by boundaryGap.
  29333. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  29334. // FIXME
  29335. // (1) When min/max is 'dataMin' or 'dataMax', should boundaryGap be able to used?
  29336. // (2) When `needCrossZero` and all data is positive/negative, should it be ensured
  29337. // that the results processed by boundaryGap are positive/negative?
  29338. if (min == null) {
  29339. min = scaleType === 'ordinal'
  29340. ? (axisDataLen ? 0 : NaN)
  29341. : originalExtent[0] - boundaryGap[0] * span;
  29342. }
  29343. if (max == null) {
  29344. max = scaleType === 'ordinal'
  29345. ? (axisDataLen ? axisDataLen - 1 : NaN)
  29346. : originalExtent[1] + boundaryGap[1] * span;
  29347. }
  29348. if (min === 'dataMin') {
  29349. min = originalExtent[0];
  29350. }
  29351. else if (typeof min === 'function') {
  29352. min = min({
  29353. min: originalExtent[0],
  29354. max: originalExtent[1]
  29355. });
  29356. }
  29357. if (max === 'dataMax') {
  29358. max = originalExtent[1];
  29359. }
  29360. else if (typeof max === 'function') {
  29361. max = max({
  29362. min: originalExtent[0],
  29363. max: originalExtent[1]
  29364. });
  29365. }
  29366. (min == null || !isFinite(min)) && (min = NaN);
  29367. (max == null || !isFinite(max)) && (max = NaN);
  29368. scale.setBlank(
  29369. eqNaN(min)
  29370. || eqNaN(max)
  29371. || (scaleType === 'ordinal' && !scale.getOrdinalMeta().categories.length)
  29372. );
  29373. // Evaluate if axis needs cross zero
  29374. if (model.getNeedCrossZero()) {
  29375. // Axis is over zero and min is not set
  29376. if (min > 0 && max > 0 && !fixMin) {
  29377. min = 0;
  29378. }
  29379. // Axis is under zero and max is not set
  29380. if (min < 0 && max < 0 && !fixMax) {
  29381. max = 0;
  29382. }
  29383. }
  29384. // If bars are placed on a base axis of type time or interval account for axis boundary overflow and current axis
  29385. // is base axis
  29386. // FIXME
  29387. // (1) Consider support value axis, where below zero and axis `onZero` should be handled properly.
  29388. // (2) Refactor the logic with `barGrid`. Is it not need to `makeBarWidthAndOffsetInfo` twice with different extent?
  29389. // Should not depend on series type `bar`?
  29390. // (3) Fix that might overlap when using dataZoom.
  29391. // (4) Consider other chart types using `barGrid`?
  29392. // See #6728, #4862, `test/bar-overflow-time-plot.html`
  29393. var ecModel = model.ecModel;
  29394. if (ecModel && (scaleType === 'time' /*|| scaleType === 'interval' */)) {
  29395. var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
  29396. var isBaseAxisAndHasBarSeries;
  29397. each$1(barSeriesModels, function (seriesModel) {
  29398. isBaseAxisAndHasBarSeries |= seriesModel.getBaseAxis() === model.axis;
  29399. });
  29400. if (isBaseAxisAndHasBarSeries) {
  29401. // Calculate placement of bars on axis
  29402. var barWidthAndOffset = makeColumnLayout(barSeriesModels);
  29403. // Adjust axis min and max to account for overflow
  29404. var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
  29405. min = adjustedScale.min;
  29406. max = adjustedScale.max;
  29407. }
  29408. }
  29409. return [min, max];
  29410. }
  29411. function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
  29412. // Get Axis Length
  29413. var axisExtent = model.axis.getExtent();
  29414. var axisLength = axisExtent[1] - axisExtent[0];
  29415. // Get bars on current base axis and calculate min and max overflow
  29416. var barsOnCurrentAxis = retrieveColumnLayout(barWidthAndOffset, model.axis);
  29417. if (barsOnCurrentAxis === undefined) {
  29418. return {min: min, max: max};
  29419. }
  29420. var minOverflow = Infinity;
  29421. each$1(barsOnCurrentAxis, function (item) {
  29422. minOverflow = Math.min(item.offset, minOverflow);
  29423. });
  29424. var maxOverflow = -Infinity;
  29425. each$1(barsOnCurrentAxis, function (item) {
  29426. maxOverflow = Math.max(item.offset + item.width, maxOverflow);
  29427. });
  29428. minOverflow = Math.abs(minOverflow);
  29429. maxOverflow = Math.abs(maxOverflow);
  29430. var totalOverFlow = minOverflow + maxOverflow;
  29431. // Calulate required buffer based on old range and overflow
  29432. var oldRange = max - min;
  29433. var oldRangePercentOfNew = (1 - (minOverflow + maxOverflow) / axisLength);
  29434. var overflowBuffer = ((oldRange / oldRangePercentOfNew) - oldRange);
  29435. max += overflowBuffer * (maxOverflow / totalOverFlow);
  29436. min -= overflowBuffer * (minOverflow / totalOverFlow);
  29437. return {min: min, max: max};
  29438. }
  29439. function niceScaleExtent(scale, model) {
  29440. var extent = getScaleExtent(scale, model);
  29441. var fixMin = model.getMin() != null;
  29442. var fixMax = model.getMax() != null;
  29443. var splitNumber = model.get('splitNumber');
  29444. if (scale.type === 'log') {
  29445. scale.base = model.get('logBase');
  29446. }
  29447. var scaleType = scale.type;
  29448. scale.setExtent(extent[0], extent[1]);
  29449. scale.niceExtent({
  29450. splitNumber: splitNumber,
  29451. fixMin: fixMin,
  29452. fixMax: fixMax,
  29453. minInterval: (scaleType === 'interval' || scaleType === 'time')
  29454. ? model.get('minInterval') : null,
  29455. maxInterval: (scaleType === 'interval' || scaleType === 'time')
  29456. ? model.get('maxInterval') : null
  29457. });
  29458. // If some one specified the min, max. And the default calculated interval
  29459. // is not good enough. He can specify the interval. It is often appeared
  29460. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  29461. // to be 60.
  29462. // FIXME
  29463. var interval = model.get('interval');
  29464. if (interval != null) {
  29465. scale.setInterval && scale.setInterval(interval);
  29466. }
  29467. }
  29468. /**
  29469. * @param {module:echarts/model/Model} model
  29470. * @param {string} [axisType] Default retrieve from model.type
  29471. * @return {module:echarts/scale/*}
  29472. */
  29473. function createScaleByModel(model, axisType) {
  29474. axisType = axisType || model.get('type');
  29475. if (axisType) {
  29476. switch (axisType) {
  29477. // Buildin scale
  29478. case 'category':
  29479. return new OrdinalScale(
  29480. model.getOrdinalMeta
  29481. ? model.getOrdinalMeta()
  29482. : model.getCategories(),
  29483. [Infinity, -Infinity]
  29484. );
  29485. case 'value':
  29486. return new IntervalScale();
  29487. // Extended scale, like time and log
  29488. default:
  29489. return (Scale.getClass(axisType) || IntervalScale).create(model);
  29490. }
  29491. }
  29492. }
  29493. /**
  29494. * Check if the axis corss 0
  29495. */
  29496. function ifAxisCrossZero(axis) {
  29497. var dataExtent = axis.scale.getExtent();
  29498. var min = dataExtent[0];
  29499. var max = dataExtent[1];
  29500. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  29501. }
  29502. /**
  29503. * @param {module:echarts/coord/Axis} axis
  29504. * @return {Function} Label formatter function.
  29505. * param: {number} tickValue,
  29506. * param: {number} idx, the index in all ticks.
  29507. * If category axis, this param is not requied.
  29508. * return: {string} label string.
  29509. */
  29510. function makeLabelFormatter(axis) {
  29511. var labelFormatter = axis.getLabelModel().get('formatter');
  29512. var categoryTickStart = axis.type === 'category' ? axis.scale.getExtent()[0] : null;
  29513. if (typeof labelFormatter === 'string') {
  29514. labelFormatter = (function (tpl) {
  29515. return function (val) {
  29516. // For category axis, get raw value; for numeric axis,
  29517. // get foramtted label like '1,333,444'.
  29518. val = axis.scale.getLabel(val);
  29519. return tpl.replace('{value}', val != null ? val : '');
  29520. };
  29521. })(labelFormatter);
  29522. // Consider empty array
  29523. return labelFormatter;
  29524. }
  29525. else if (typeof labelFormatter === 'function') {
  29526. return function (tickValue, idx) {
  29527. // The original intention of `idx` is "the index of the tick in all ticks".
  29528. // But the previous implementation of category axis do not consider the
  29529. // `axisLabel.interval`, which cause that, for example, the `interval` is
  29530. // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
  29531. // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
  29532. // the definition here for back compatibility.
  29533. if (categoryTickStart != null) {
  29534. idx = tickValue - categoryTickStart;
  29535. }
  29536. return labelFormatter(getAxisRawValue(axis, tickValue), idx);
  29537. };
  29538. }
  29539. else {
  29540. return function (tick) {
  29541. return axis.scale.getLabel(tick);
  29542. };
  29543. }
  29544. }
  29545. function getAxisRawValue(axis, value) {
  29546. // In category axis with data zoom, tick is not the original
  29547. // index of axis.data. So tick should not be exposed to user
  29548. // in category axis.
  29549. return axis.type === 'category' ? axis.scale.getLabel(value) : value;
  29550. }
  29551. /**
  29552. * @param {module:echarts/coord/Axis} axis
  29553. * @return {module:zrender/core/BoundingRect} Be null/undefined if no labels.
  29554. */
  29555. function estimateLabelUnionRect(axis) {
  29556. var axisModel = axis.model;
  29557. var scale = axis.scale;
  29558. if (!axisModel.get('axisLabel.show') || scale.isBlank()) {
  29559. return;
  29560. }
  29561. var isCategory = axis.type === 'category';
  29562. var realNumberScaleTicks;
  29563. var tickCount;
  29564. var categoryScaleExtent = scale.getExtent();
  29565. // Optimize for large category data, avoid call `getTicks()`.
  29566. if (isCategory) {
  29567. tickCount = scale.count();
  29568. }
  29569. else {
  29570. realNumberScaleTicks = scale.getTicks();
  29571. tickCount = realNumberScaleTicks.length;
  29572. }
  29573. var axisLabelModel = axis.getLabelModel();
  29574. var labelFormatter = makeLabelFormatter(axis);
  29575. var rect;
  29576. var step = 1;
  29577. // Simple optimization for large amount of labels
  29578. if (tickCount > 40) {
  29579. step = Math.ceil(tickCount / 40);
  29580. }
  29581. for (var i = 0; i < tickCount; i += step) {
  29582. var tickValue = realNumberScaleTicks ? realNumberScaleTicks[i] : categoryScaleExtent[0] + i;
  29583. var label = labelFormatter(tickValue);
  29584. var unrotatedSingleRect = axisLabelModel.getTextRect(label);
  29585. var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
  29586. rect ? rect.union(singleRect) : (rect = singleRect);
  29587. }
  29588. return rect;
  29589. }
  29590. function rotateTextRect(textRect, rotate) {
  29591. var rotateRadians = rotate * Math.PI / 180;
  29592. var boundingBox = textRect.plain();
  29593. var beforeWidth = boundingBox.width;
  29594. var beforeHeight = boundingBox.height;
  29595. var afterWidth = beforeWidth * Math.cos(rotateRadians) + beforeHeight * Math.sin(rotateRadians);
  29596. var afterHeight = beforeWidth * Math.sin(rotateRadians) + beforeHeight * Math.cos(rotateRadians);
  29597. var rotatedRect = new BoundingRect(boundingBox.x, boundingBox.y, afterWidth, afterHeight);
  29598. return rotatedRect;
  29599. }
  29600. /**
  29601. * @param {module:echarts/src/model/Model} model axisLabelModel or axisTickModel
  29602. * @return {number|String} Can be null|'auto'|number|function
  29603. */
  29604. function getOptionCategoryInterval(model) {
  29605. var interval = model.get('interval');
  29606. return interval == null ? 'auto' : interval;
  29607. }
  29608. /**
  29609. * Set `categoryInterval` as 0 implicitly indicates that
  29610. * show all labels reguardless of overlap.
  29611. * @param {Object} axis axisModel.axis
  29612. * @return {boolean}
  29613. */
  29614. function shouldShowAllLabels(axis) {
  29615. return axis.type === 'category'
  29616. && getOptionCategoryInterval(axis.getLabelModel()) === 0;
  29617. }
  29618. /*
  29619. * Licensed to the Apache Software Foundation (ASF) under one
  29620. * or more contributor license agreements. See the NOTICE file
  29621. * distributed with this work for additional information
  29622. * regarding copyright ownership. The ASF licenses this file
  29623. * to you under the Apache License, Version 2.0 (the
  29624. * "License"); you may not use this file except in compliance
  29625. * with the License. You may obtain a copy of the License at
  29626. *
  29627. * http://www.apache.org/licenses/LICENSE-2.0
  29628. *
  29629. * Unless required by applicable law or agreed to in writing,
  29630. * software distributed under the License is distributed on an
  29631. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29632. * KIND, either express or implied. See the License for the
  29633. * specific language governing permissions and limitations
  29634. * under the License.
  29635. */
  29636. // import * as axisHelper from './axisHelper';
  29637. var axisModelCommonMixin = {
  29638. /**
  29639. * @param {boolean} origin
  29640. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  29641. */
  29642. getMin: function (origin) {
  29643. var option = this.option;
  29644. var min = (!origin && option.rangeStart != null)
  29645. ? option.rangeStart : option.min;
  29646. if (this.axis
  29647. && min != null
  29648. && min !== 'dataMin'
  29649. && typeof min !== 'function'
  29650. && !eqNaN(min)
  29651. ) {
  29652. min = this.axis.scale.parse(min);
  29653. }
  29654. return min;
  29655. },
  29656. /**
  29657. * @param {boolean} origin
  29658. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  29659. */
  29660. getMax: function (origin) {
  29661. var option = this.option;
  29662. var max = (!origin && option.rangeEnd != null)
  29663. ? option.rangeEnd : option.max;
  29664. if (this.axis
  29665. && max != null
  29666. && max !== 'dataMax'
  29667. && typeof max !== 'function'
  29668. && !eqNaN(max)
  29669. ) {
  29670. max = this.axis.scale.parse(max);
  29671. }
  29672. return max;
  29673. },
  29674. /**
  29675. * @return {boolean}
  29676. */
  29677. getNeedCrossZero: function () {
  29678. var option = this.option;
  29679. return (option.rangeStart != null || option.rangeEnd != null)
  29680. ? false : !option.scale;
  29681. },
  29682. /**
  29683. * Should be implemented by each axis model if necessary.
  29684. * @return {module:echarts/model/Component} coordinate system model
  29685. */
  29686. getCoordSysModel: noop,
  29687. /**
  29688. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  29689. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  29690. */
  29691. setRange: function (rangeStart, rangeEnd) {
  29692. this.option.rangeStart = rangeStart;
  29693. this.option.rangeEnd = rangeEnd;
  29694. },
  29695. /**
  29696. * Reset range
  29697. */
  29698. resetRange: function () {
  29699. // rangeStart and rangeEnd is readonly.
  29700. this.option.rangeStart = this.option.rangeEnd = null;
  29701. }
  29702. };
  29703. /*
  29704. * Licensed to the Apache Software Foundation (ASF) under one
  29705. * or more contributor license agreements. See the NOTICE file
  29706. * distributed with this work for additional information
  29707. * regarding copyright ownership. The ASF licenses this file
  29708. * to you under the Apache License, Version 2.0 (the
  29709. * "License"); you may not use this file except in compliance
  29710. * with the License. You may obtain a copy of the License at
  29711. *
  29712. * http://www.apache.org/licenses/LICENSE-2.0
  29713. *
  29714. * Unless required by applicable law or agreed to in writing,
  29715. * software distributed under the License is distributed on an
  29716. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29717. * KIND, either express or implied. See the License for the
  29718. * specific language governing permissions and limitations
  29719. * under the License.
  29720. */
  29721. // Symbol factory
  29722. /**
  29723. * Triangle shape
  29724. * @inner
  29725. */
  29726. var Triangle = extendShape({
  29727. type: 'triangle',
  29728. shape: {
  29729. cx: 0,
  29730. cy: 0,
  29731. width: 0,
  29732. height: 0
  29733. },
  29734. buildPath: function (path, shape) {
  29735. var cx = shape.cx;
  29736. var cy = shape.cy;
  29737. var width = shape.width / 2;
  29738. var height = shape.height / 2;
  29739. path.moveTo(cx, cy - height);
  29740. path.lineTo(cx + width, cy + height);
  29741. path.lineTo(cx - width, cy + height);
  29742. path.closePath();
  29743. }
  29744. });
  29745. /**
  29746. * Diamond shape
  29747. * @inner
  29748. */
  29749. var Diamond = extendShape({
  29750. type: 'diamond',
  29751. shape: {
  29752. cx: 0,
  29753. cy: 0,
  29754. width: 0,
  29755. height: 0
  29756. },
  29757. buildPath: function (path, shape) {
  29758. var cx = shape.cx;
  29759. var cy = shape.cy;
  29760. var width = shape.width / 2;
  29761. var height = shape.height / 2;
  29762. path.moveTo(cx, cy - height);
  29763. path.lineTo(cx + width, cy);
  29764. path.lineTo(cx, cy + height);
  29765. path.lineTo(cx - width, cy);
  29766. path.closePath();
  29767. }
  29768. });
  29769. /**
  29770. * Pin shape
  29771. * @inner
  29772. */
  29773. var Pin = extendShape({
  29774. type: 'pin',
  29775. shape: {
  29776. // x, y on the cusp
  29777. x: 0,
  29778. y: 0,
  29779. width: 0,
  29780. height: 0
  29781. },
  29782. buildPath: function (path, shape) {
  29783. var x = shape.x;
  29784. var y = shape.y;
  29785. var w = shape.width / 5 * 3;
  29786. // Height must be larger than width
  29787. var h = Math.max(w, shape.height);
  29788. var r = w / 2;
  29789. // Dist on y with tangent point and circle center
  29790. var dy = r * r / (h - r);
  29791. var cy = y - h + r + dy;
  29792. var angle = Math.asin(dy / r);
  29793. // Dist on x with tangent point and circle center
  29794. var dx = Math.cos(angle) * r;
  29795. var tanX = Math.sin(angle);
  29796. var tanY = Math.cos(angle);
  29797. var cpLen = r * 0.6;
  29798. var cpLen2 = r * 0.7;
  29799. path.moveTo(x - dx, cy + dy);
  29800. path.arc(
  29801. x, cy, r,
  29802. Math.PI - angle,
  29803. Math.PI * 2 + angle
  29804. );
  29805. path.bezierCurveTo(
  29806. x + dx - tanX * cpLen, cy + dy + tanY * cpLen,
  29807. x, y - cpLen2,
  29808. x, y
  29809. );
  29810. path.bezierCurveTo(
  29811. x, y - cpLen2,
  29812. x - dx + tanX * cpLen, cy + dy + tanY * cpLen,
  29813. x - dx, cy + dy
  29814. );
  29815. path.closePath();
  29816. }
  29817. });
  29818. /**
  29819. * Arrow shape
  29820. * @inner
  29821. */
  29822. var Arrow = extendShape({
  29823. type: 'arrow',
  29824. shape: {
  29825. x: 0,
  29826. y: 0,
  29827. width: 0,
  29828. height: 0
  29829. },
  29830. buildPath: function (ctx, shape) {
  29831. var height = shape.height;
  29832. var width = shape.width;
  29833. var x = shape.x;
  29834. var y = shape.y;
  29835. var dx = width / 3 * 2;
  29836. ctx.moveTo(x, y);
  29837. ctx.lineTo(x + dx, y + height);
  29838. ctx.lineTo(x, y + height / 4 * 3);
  29839. ctx.lineTo(x - dx, y + height);
  29840. ctx.lineTo(x, y);
  29841. ctx.closePath();
  29842. }
  29843. });
  29844. /**
  29845. * Map of path contructors
  29846. * @type {Object.<string, module:zrender/graphic/Path>}
  29847. */
  29848. var symbolCtors = {
  29849. line: Line,
  29850. rect: Rect,
  29851. roundRect: Rect,
  29852. square: Rect,
  29853. circle: Circle,
  29854. diamond: Diamond,
  29855. pin: Pin,
  29856. arrow: Arrow,
  29857. triangle: Triangle
  29858. };
  29859. var symbolShapeMakers = {
  29860. line: function (x, y, w, h, shape) {
  29861. // FIXME
  29862. shape.x1 = x;
  29863. shape.y1 = y + h / 2;
  29864. shape.x2 = x + w;
  29865. shape.y2 = y + h / 2;
  29866. },
  29867. rect: function (x, y, w, h, shape) {
  29868. shape.x = x;
  29869. shape.y = y;
  29870. shape.width = w;
  29871. shape.height = h;
  29872. },
  29873. roundRect: function (x, y, w, h, shape) {
  29874. shape.x = x;
  29875. shape.y = y;
  29876. shape.width = w;
  29877. shape.height = h;
  29878. shape.r = Math.min(w, h) / 4;
  29879. },
  29880. square: function (x, y, w, h, shape) {
  29881. var size = Math.min(w, h);
  29882. shape.x = x;
  29883. shape.y = y;
  29884. shape.width = size;
  29885. shape.height = size;
  29886. },
  29887. circle: function (x, y, w, h, shape) {
  29888. // Put circle in the center of square
  29889. shape.cx = x + w / 2;
  29890. shape.cy = y + h / 2;
  29891. shape.r = Math.min(w, h) / 2;
  29892. },
  29893. diamond: function (x, y, w, h, shape) {
  29894. shape.cx = x + w / 2;
  29895. shape.cy = y + h / 2;
  29896. shape.width = w;
  29897. shape.height = h;
  29898. },
  29899. pin: function (x, y, w, h, shape) {
  29900. shape.x = x + w / 2;
  29901. shape.y = y + h / 2;
  29902. shape.width = w;
  29903. shape.height = h;
  29904. },
  29905. arrow: function (x, y, w, h, shape) {
  29906. shape.x = x + w / 2;
  29907. shape.y = y + h / 2;
  29908. shape.width = w;
  29909. shape.height = h;
  29910. },
  29911. triangle: function (x, y, w, h, shape) {
  29912. shape.cx = x + w / 2;
  29913. shape.cy = y + h / 2;
  29914. shape.width = w;
  29915. shape.height = h;
  29916. }
  29917. };
  29918. var symbolBuildProxies = {};
  29919. each$1(symbolCtors, function (Ctor, name) {
  29920. symbolBuildProxies[name] = new Ctor();
  29921. });
  29922. var SymbolClz = extendShape({
  29923. type: 'symbol',
  29924. shape: {
  29925. symbolType: '',
  29926. x: 0,
  29927. y: 0,
  29928. width: 0,
  29929. height: 0
  29930. },
  29931. beforeBrush: function () {
  29932. var style = this.style;
  29933. var shape = this.shape;
  29934. // FIXME
  29935. if (shape.symbolType === 'pin' && style.textPosition === 'inside') {
  29936. style.textPosition = ['50%', '40%'];
  29937. style.textAlign = 'center';
  29938. style.textVerticalAlign = 'middle';
  29939. }
  29940. },
  29941. buildPath: function (ctx, shape, inBundle) {
  29942. var symbolType = shape.symbolType;
  29943. var proxySymbol = symbolBuildProxies[symbolType];
  29944. if (shape.symbolType !== 'none') {
  29945. if (!proxySymbol) {
  29946. // Default rect
  29947. symbolType = 'rect';
  29948. proxySymbol = symbolBuildProxies[symbolType];
  29949. }
  29950. symbolShapeMakers[symbolType](
  29951. shape.x, shape.y, shape.width, shape.height, proxySymbol.shape
  29952. );
  29953. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  29954. }
  29955. }
  29956. });
  29957. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  29958. function symbolPathSetColor(color, innerColor) {
  29959. if (this.type !== 'image') {
  29960. var symbolStyle = this.style;
  29961. var symbolShape = this.shape;
  29962. if (symbolShape && symbolShape.symbolType === 'line') {
  29963. symbolStyle.stroke = color;
  29964. }
  29965. else if (this.__isEmptyBrush) {
  29966. symbolStyle.stroke = color;
  29967. symbolStyle.fill = innerColor || '#fff';
  29968. }
  29969. else {
  29970. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  29971. symbolStyle.fill && (symbolStyle.fill = color);
  29972. symbolStyle.stroke && (symbolStyle.stroke = color);
  29973. }
  29974. this.dirty(false);
  29975. }
  29976. }
  29977. /**
  29978. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  29979. * @param {string} symbolType
  29980. * @param {number} x
  29981. * @param {number} y
  29982. * @param {number} w
  29983. * @param {number} h
  29984. * @param {string} color
  29985. * @param {boolean} [keepAspect=false] whether to keep the ratio of w/h,
  29986. * for path and image only.
  29987. */
  29988. function createSymbol(symbolType, x, y, w, h, color, keepAspect) {
  29989. // TODO Support image object, DynamicImage.
  29990. var isEmpty = symbolType.indexOf('empty') === 0;
  29991. if (isEmpty) {
  29992. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  29993. }
  29994. var symbolPath;
  29995. if (symbolType.indexOf('image://') === 0) {
  29996. symbolPath = makeImage(
  29997. symbolType.slice(8),
  29998. new BoundingRect(x, y, w, h),
  29999. keepAspect ? 'center' : 'cover'
  30000. );
  30001. }
  30002. else if (symbolType.indexOf('path://') === 0) {
  30003. symbolPath = makePath(
  30004. symbolType.slice(7),
  30005. {},
  30006. new BoundingRect(x, y, w, h),
  30007. keepAspect ? 'center' : 'cover'
  30008. );
  30009. }
  30010. else {
  30011. symbolPath = new SymbolClz({
  30012. shape: {
  30013. symbolType: symbolType,
  30014. x: x,
  30015. y: y,
  30016. width: w,
  30017. height: h
  30018. }
  30019. });
  30020. }
  30021. symbolPath.__isEmptyBrush = isEmpty;
  30022. symbolPath.setColor = symbolPathSetColor;
  30023. symbolPath.setColor(color);
  30024. return symbolPath;
  30025. }
  30026. /*
  30027. * Licensed to the Apache Software Foundation (ASF) under one
  30028. * or more contributor license agreements. See the NOTICE file
  30029. * distributed with this work for additional information
  30030. * regarding copyright ownership. The ASF licenses this file
  30031. * to you under the Apache License, Version 2.0 (the
  30032. * "License"); you may not use this file except in compliance
  30033. * with the License. You may obtain a copy of the License at
  30034. *
  30035. * http://www.apache.org/licenses/LICENSE-2.0
  30036. *
  30037. * Unless required by applicable law or agreed to in writing,
  30038. * software distributed under the License is distributed on an
  30039. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30040. * KIND, either express or implied. See the License for the
  30041. * specific language governing permissions and limitations
  30042. * under the License.
  30043. */
  30044. // import createGraphFromNodeEdge from './chart/helper/createGraphFromNodeEdge';
  30045. /**
  30046. * Create a muti dimension List structure from seriesModel.
  30047. * @param {module:echarts/model/Model} seriesModel
  30048. * @return {module:echarts/data/List} list
  30049. */
  30050. function createList(seriesModel) {
  30051. return createListFromArray(seriesModel.getSource(), seriesModel);
  30052. }
  30053. var dataStack$1 = {
  30054. isDimensionStacked: isDimensionStacked,
  30055. enableDataStack: enableDataStack,
  30056. getStackedDimension: getStackedDimension
  30057. };
  30058. /**
  30059. * Create scale
  30060. * @param {Array.<number>} dataExtent
  30061. * @param {Object|module:echarts/Model} option
  30062. */
  30063. function createScale(dataExtent, option) {
  30064. var axisModel = option;
  30065. if (!Model.isInstance(option)) {
  30066. axisModel = new Model(option);
  30067. mixin(axisModel, axisModelCommonMixin);
  30068. }
  30069. var scale = createScaleByModel(axisModel);
  30070. scale.setExtent(dataExtent[0], dataExtent[1]);
  30071. niceScaleExtent(scale, axisModel);
  30072. return scale;
  30073. }
  30074. /**
  30075. * Mixin common methods to axis model,
  30076. *
  30077. * Inlcude methods
  30078. * `getFormattedLabels() => Array.<string>`
  30079. * `getCategories() => Array.<string>`
  30080. * `getMin(origin: boolean) => number`
  30081. * `getMax(origin: boolean) => number`
  30082. * `getNeedCrossZero() => boolean`
  30083. * `setRange(start: number, end: number)`
  30084. * `resetRange()`
  30085. */
  30086. function mixinAxisModelCommonMethods(Model$$1) {
  30087. mixin(Model$$1, axisModelCommonMixin);
  30088. }
  30089. var helper = (Object.freeze || Object)({
  30090. createList: createList,
  30091. getLayoutRect: getLayoutRect,
  30092. dataStack: dataStack$1,
  30093. createScale: createScale,
  30094. mixinAxisModelCommonMethods: mixinAxisModelCommonMethods,
  30095. completeDimensions: completeDimensions,
  30096. createDimensions: createDimensions,
  30097. createSymbol: createSymbol
  30098. });
  30099. var EPSILON$3 = 1e-8;
  30100. function isAroundEqual$1(a, b) {
  30101. return Math.abs(a - b) < EPSILON$3;
  30102. }
  30103. function contain$1(points, x, y) {
  30104. var w = 0;
  30105. var p = points[0];
  30106. if (!p) {
  30107. return false;
  30108. }
  30109. for (var i = 1; i < points.length; i++) {
  30110. var p2 = points[i];
  30111. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  30112. p = p2;
  30113. }
  30114. // Close polygon
  30115. var p0 = points[0];
  30116. if (!isAroundEqual$1(p[0], p0[0]) || !isAroundEqual$1(p[1], p0[1])) {
  30117. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  30118. }
  30119. return w !== 0;
  30120. }
  30121. /*
  30122. * Licensed to the Apache Software Foundation (ASF) under one
  30123. * or more contributor license agreements. See the NOTICE file
  30124. * distributed with this work for additional information
  30125. * regarding copyright ownership. The ASF licenses this file
  30126. * to you under the Apache License, Version 2.0 (the
  30127. * "License"); you may not use this file except in compliance
  30128. * with the License. You may obtain a copy of the License at
  30129. *
  30130. * http://www.apache.org/licenses/LICENSE-2.0
  30131. *
  30132. * Unless required by applicable law or agreed to in writing,
  30133. * software distributed under the License is distributed on an
  30134. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30135. * KIND, either express or implied. See the License for the
  30136. * specific language governing permissions and limitations
  30137. * under the License.
  30138. */
  30139. /**
  30140. * @module echarts/coord/geo/Region
  30141. */
  30142. /**
  30143. * @param {string|Region} name
  30144. * @param {Array} geometries
  30145. * @param {Array.<number>} cp
  30146. */
  30147. function Region(name, geometries, cp) {
  30148. /**
  30149. * @type {string}
  30150. * @readOnly
  30151. */
  30152. this.name = name;
  30153. /**
  30154. * @type {Array.<Array>}
  30155. * @readOnly
  30156. */
  30157. this.geometries = geometries;
  30158. if (!cp) {
  30159. var rect = this.getBoundingRect();
  30160. cp = [
  30161. rect.x + rect.width / 2,
  30162. rect.y + rect.height / 2
  30163. ];
  30164. }
  30165. else {
  30166. cp = [cp[0], cp[1]];
  30167. }
  30168. /**
  30169. * @type {Array.<number>}
  30170. */
  30171. this.center = cp;
  30172. }
  30173. Region.prototype = {
  30174. constructor: Region,
  30175. properties: null,
  30176. /**
  30177. * @return {module:zrender/core/BoundingRect}
  30178. */
  30179. getBoundingRect: function () {
  30180. var rect = this._rect;
  30181. if (rect) {
  30182. return rect;
  30183. }
  30184. var MAX_NUMBER = Number.MAX_VALUE;
  30185. var min$$1 = [MAX_NUMBER, MAX_NUMBER];
  30186. var max$$1 = [-MAX_NUMBER, -MAX_NUMBER];
  30187. var min2 = [];
  30188. var max2 = [];
  30189. var geometries = this.geometries;
  30190. for (var i = 0; i < geometries.length; i++) {
  30191. // Only support polygon
  30192. if (geometries[i].type !== 'polygon') {
  30193. continue;
  30194. }
  30195. // Doesn't consider hole
  30196. var exterior = geometries[i].exterior;
  30197. fromPoints(exterior, min2, max2);
  30198. min(min$$1, min$$1, min2);
  30199. max(max$$1, max$$1, max2);
  30200. }
  30201. // No data
  30202. if (i === 0) {
  30203. min$$1[0] = min$$1[1] = max$$1[0] = max$$1[1] = 0;
  30204. }
  30205. return (this._rect = new BoundingRect(
  30206. min$$1[0], min$$1[1], max$$1[0] - min$$1[0], max$$1[1] - min$$1[1]
  30207. ));
  30208. },
  30209. /**
  30210. * @param {<Array.<number>} coord
  30211. * @return {boolean}
  30212. */
  30213. contain: function (coord) {
  30214. var rect = this.getBoundingRect();
  30215. var geometries = this.geometries;
  30216. if (!rect.contain(coord[0], coord[1])) {
  30217. return false;
  30218. }
  30219. loopGeo: for (var i = 0, len$$1 = geometries.length; i < len$$1; i++) {
  30220. // Only support polygon.
  30221. if (geometries[i].type !== 'polygon') {
  30222. continue;
  30223. }
  30224. var exterior = geometries[i].exterior;
  30225. var interiors = geometries[i].interiors;
  30226. if (contain$1(exterior, coord[0], coord[1])) {
  30227. // Not in the region if point is in the hole.
  30228. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  30229. if (contain$1(interiors[k])) {
  30230. continue loopGeo;
  30231. }
  30232. }
  30233. return true;
  30234. }
  30235. }
  30236. return false;
  30237. },
  30238. transformTo: function (x, y, width, height) {
  30239. var rect = this.getBoundingRect();
  30240. var aspect = rect.width / rect.height;
  30241. if (!width) {
  30242. width = aspect * height;
  30243. }
  30244. else if (!height) {
  30245. height = width / aspect;
  30246. }
  30247. var target = new BoundingRect(x, y, width, height);
  30248. var transform = rect.calculateTransform(target);
  30249. var geometries = this.geometries;
  30250. for (var i = 0; i < geometries.length; i++) {
  30251. // Only support polygon.
  30252. if (geometries[i].type !== 'polygon') {
  30253. continue;
  30254. }
  30255. var exterior = geometries[i].exterior;
  30256. var interiors = geometries[i].interiors;
  30257. for (var p = 0; p < exterior.length; p++) {
  30258. applyTransform(exterior[p], exterior[p], transform);
  30259. }
  30260. for (var h = 0; h < (interiors ? interiors.length : 0); h++) {
  30261. for (var p = 0; p < interiors[h].length; p++) {
  30262. applyTransform(interiors[h][p], interiors[h][p], transform);
  30263. }
  30264. }
  30265. }
  30266. rect = this._rect;
  30267. rect.copy(target);
  30268. // Update center
  30269. this.center = [
  30270. rect.x + rect.width / 2,
  30271. rect.y + rect.height / 2
  30272. ];
  30273. },
  30274. cloneShallow: function (name) {
  30275. name == null && (name = this.name);
  30276. var newRegion = new Region(name, this.geometries, this.center);
  30277. newRegion._rect = this._rect;
  30278. newRegion.transformTo = null; // Simply avoid to be called.
  30279. return newRegion;
  30280. }
  30281. };
  30282. /*
  30283. * Licensed to the Apache Software Foundation (ASF) under one
  30284. * or more contributor license agreements. See the NOTICE file
  30285. * distributed with this work for additional information
  30286. * regarding copyright ownership. The ASF licenses this file
  30287. * to you under the Apache License, Version 2.0 (the
  30288. * "License"); you may not use this file except in compliance
  30289. * with the License. You may obtain a copy of the License at
  30290. *
  30291. * http://www.apache.org/licenses/LICENSE-2.0
  30292. *
  30293. * Unless required by applicable law or agreed to in writing,
  30294. * software distributed under the License is distributed on an
  30295. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30296. * KIND, either express or implied. See the License for the
  30297. * specific language governing permissions and limitations
  30298. * under the License.
  30299. */
  30300. /**
  30301. * Parse and decode geo json
  30302. * @module echarts/coord/geo/parseGeoJson
  30303. */
  30304. function decode(json) {
  30305. if (!json.UTF8Encoding) {
  30306. return json;
  30307. }
  30308. var encodeScale = json.UTF8Scale;
  30309. if (encodeScale == null) {
  30310. encodeScale = 1024;
  30311. }
  30312. var features = json.features;
  30313. for (var f = 0; f < features.length; f++) {
  30314. var feature = features[f];
  30315. var geometry = feature.geometry;
  30316. var coordinates = geometry.coordinates;
  30317. var encodeOffsets = geometry.encodeOffsets;
  30318. for (var c = 0; c < coordinates.length; c++) {
  30319. var coordinate = coordinates[c];
  30320. if (geometry.type === 'Polygon') {
  30321. coordinates[c] = decodePolygon(
  30322. coordinate,
  30323. encodeOffsets[c],
  30324. encodeScale
  30325. );
  30326. }
  30327. else if (geometry.type === 'MultiPolygon') {
  30328. for (var c2 = 0; c2 < coordinate.length; c2++) {
  30329. var polygon = coordinate[c2];
  30330. coordinate[c2] = decodePolygon(
  30331. polygon,
  30332. encodeOffsets[c][c2],
  30333. encodeScale
  30334. );
  30335. }
  30336. }
  30337. }
  30338. }
  30339. // Has been decoded
  30340. json.UTF8Encoding = false;
  30341. return json;
  30342. }
  30343. function decodePolygon(coordinate, encodeOffsets, encodeScale) {
  30344. var result = [];
  30345. var prevX = encodeOffsets[0];
  30346. var prevY = encodeOffsets[1];
  30347. for (var i = 0; i < coordinate.length; i += 2) {
  30348. var x = coordinate.charCodeAt(i) - 64;
  30349. var y = coordinate.charCodeAt(i + 1) - 64;
  30350. // ZigZag decoding
  30351. x = (x >> 1) ^ (-(x & 1));
  30352. y = (y >> 1) ^ (-(y & 1));
  30353. // Delta deocding
  30354. x += prevX;
  30355. y += prevY;
  30356. prevX = x;
  30357. prevY = y;
  30358. // Dequantize
  30359. result.push([x / encodeScale, y / encodeScale]);
  30360. }
  30361. return result;
  30362. }
  30363. /**
  30364. * @alias module:echarts/coord/geo/parseGeoJson
  30365. * @param {Object} geoJson
  30366. * @return {module:zrender/container/Group}
  30367. */
  30368. var parseGeoJson$1 = function (geoJson) {
  30369. decode(geoJson);
  30370. return map(filter(geoJson.features, function (featureObj) {
  30371. // Output of mapshaper may have geometry null
  30372. return featureObj.geometry
  30373. && featureObj.properties
  30374. && featureObj.geometry.coordinates.length > 0;
  30375. }), function (featureObj) {
  30376. var properties = featureObj.properties;
  30377. var geo = featureObj.geometry;
  30378. var coordinates = geo.coordinates;
  30379. var geometries = [];
  30380. if (geo.type === 'Polygon') {
  30381. geometries.push({
  30382. type: 'polygon',
  30383. // According to the GeoJSON specification.
  30384. // First must be exterior, and the rest are all interior(holes).
  30385. exterior: coordinates[0],
  30386. interiors: coordinates.slice(1)
  30387. });
  30388. }
  30389. if (geo.type === 'MultiPolygon') {
  30390. each$1(coordinates, function (item) {
  30391. if (item[0]) {
  30392. geometries.push({
  30393. type: 'polygon',
  30394. exterior: item[0],
  30395. interiors: item.slice(1)
  30396. });
  30397. }
  30398. });
  30399. }
  30400. var region = new Region(
  30401. properties.name,
  30402. geometries,
  30403. properties.cp
  30404. );
  30405. region.properties = properties;
  30406. return region;
  30407. });
  30408. };
  30409. /*
  30410. * Licensed to the Apache Software Foundation (ASF) under one
  30411. * or more contributor license agreements. See the NOTICE file
  30412. * distributed with this work for additional information
  30413. * regarding copyright ownership. The ASF licenses this file
  30414. * to you under the Apache License, Version 2.0 (the
  30415. * "License"); you may not use this file except in compliance
  30416. * with the License. You may obtain a copy of the License at
  30417. *
  30418. * http://www.apache.org/licenses/LICENSE-2.0
  30419. *
  30420. * Unless required by applicable law or agreed to in writing,
  30421. * software distributed under the License is distributed on an
  30422. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30423. * KIND, either express or implied. See the License for the
  30424. * specific language governing permissions and limitations
  30425. * under the License.
  30426. */
  30427. var inner$6 = makeInner();
  30428. /**
  30429. * @param {module:echats/coord/Axis} axis
  30430. * @return {Object} {
  30431. * labels: [{
  30432. * formattedLabel: string,
  30433. * rawLabel: string,
  30434. * tickValue: number
  30435. * }, ...],
  30436. * labelCategoryInterval: number
  30437. * }
  30438. */
  30439. function createAxisLabels(axis) {
  30440. // Only ordinal scale support tick interval
  30441. return axis.type === 'category'
  30442. ? makeCategoryLabels(axis)
  30443. : makeRealNumberLabels(axis);
  30444. }
  30445. /**
  30446. * @param {module:echats/coord/Axis} axis
  30447. * @param {module:echarts/model/Model} tickModel For example, can be axisTick, splitLine, splitArea.
  30448. * @return {Object} {
  30449. * ticks: Array.<number>
  30450. * tickCategoryInterval: number
  30451. * }
  30452. */
  30453. function createAxisTicks(axis, tickModel) {
  30454. // Only ordinal scale support tick interval
  30455. return axis.type === 'category'
  30456. ? makeCategoryTicks(axis, tickModel)
  30457. : {ticks: axis.scale.getTicks()};
  30458. }
  30459. function makeCategoryLabels(axis) {
  30460. var labelModel = axis.getLabelModel();
  30461. var result = makeCategoryLabelsActually(axis, labelModel);
  30462. return (!labelModel.get('show') || axis.scale.isBlank())
  30463. ? {labels: [], labelCategoryInterval: result.labelCategoryInterval}
  30464. : result;
  30465. }
  30466. function makeCategoryLabelsActually(axis, labelModel) {
  30467. var labelsCache = getListCache(axis, 'labels');
  30468. var optionLabelInterval = getOptionCategoryInterval(labelModel);
  30469. var result = listCacheGet(labelsCache, optionLabelInterval);
  30470. if (result) {
  30471. return result;
  30472. }
  30473. var labels;
  30474. var numericLabelInterval;
  30475. if (isFunction$1(optionLabelInterval)) {
  30476. labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
  30477. }
  30478. else {
  30479. numericLabelInterval = optionLabelInterval === 'auto'
  30480. ? makeAutoCategoryInterval(axis) : optionLabelInterval;
  30481. labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
  30482. }
  30483. // Cache to avoid calling interval function repeatly.
  30484. return listCacheSet(labelsCache, optionLabelInterval, {
  30485. labels: labels, labelCategoryInterval: numericLabelInterval
  30486. });
  30487. }
  30488. function makeCategoryTicks(axis, tickModel) {
  30489. var ticksCache = getListCache(axis, 'ticks');
  30490. var optionTickInterval = getOptionCategoryInterval(tickModel);
  30491. var result = listCacheGet(ticksCache, optionTickInterval);
  30492. if (result) {
  30493. return result;
  30494. }
  30495. var ticks;
  30496. var tickCategoryInterval;
  30497. // Optimize for the case that large category data and no label displayed,
  30498. // we should not return all ticks.
  30499. if (!tickModel.get('show') || axis.scale.isBlank()) {
  30500. ticks = [];
  30501. }
  30502. if (isFunction$1(optionTickInterval)) {
  30503. ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
  30504. }
  30505. // Always use label interval by default despite label show. Consider this
  30506. // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
  30507. // labels. `splitLine` and `axisTick` should be consistent in this case.
  30508. else if (optionTickInterval === 'auto') {
  30509. var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel());
  30510. tickCategoryInterval = labelsResult.labelCategoryInterval;
  30511. ticks = map(labelsResult.labels, function (labelItem) {
  30512. return labelItem.tickValue;
  30513. });
  30514. }
  30515. else {
  30516. tickCategoryInterval = optionTickInterval;
  30517. ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
  30518. }
  30519. // Cache to avoid calling interval function repeatly.
  30520. return listCacheSet(ticksCache, optionTickInterval, {
  30521. ticks: ticks, tickCategoryInterval: tickCategoryInterval
  30522. });
  30523. }
  30524. function makeRealNumberLabels(axis) {
  30525. var ticks = axis.scale.getTicks();
  30526. var labelFormatter = makeLabelFormatter(axis);
  30527. return {
  30528. labels: map(ticks, function (tickValue, idx) {
  30529. return {
  30530. formattedLabel: labelFormatter(tickValue, idx),
  30531. rawLabel: axis.scale.getLabel(tickValue),
  30532. tickValue: tickValue
  30533. };
  30534. })
  30535. };
  30536. }
  30537. // Large category data calculation is performence sensitive, and ticks and label
  30538. // probably be fetched by multiple times. So we cache the result.
  30539. // axis is created each time during a ec process, so we do not need to clear cache.
  30540. function getListCache(axis, prop) {
  30541. // Because key can be funciton, and cache size always be small, we use array cache.
  30542. return inner$6(axis)[prop] || (inner$6(axis)[prop] = []);
  30543. }
  30544. function listCacheGet(cache, key) {
  30545. for (var i = 0; i < cache.length; i++) {
  30546. if (cache[i].key === key) {
  30547. return cache[i].value;
  30548. }
  30549. }
  30550. }
  30551. function listCacheSet(cache, key, value) {
  30552. cache.push({key: key, value: value});
  30553. return value;
  30554. }
  30555. function makeAutoCategoryInterval(axis) {
  30556. var result = inner$6(axis).autoInterval;
  30557. return result != null
  30558. ? result
  30559. : (inner$6(axis).autoInterval = axis.calculateCategoryInterval());
  30560. }
  30561. /**
  30562. * Calculate interval for category axis ticks and labels.
  30563. * To get precise result, at least one of `getRotate` and `isHorizontal`
  30564. * should be implemented in axis.
  30565. */
  30566. function calculateCategoryInterval(axis) {
  30567. var params = fetchAutoCategoryIntervalCalculationParams(axis);
  30568. var labelFormatter = makeLabelFormatter(axis);
  30569. var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
  30570. var ordinalScale = axis.scale;
  30571. var ordinalExtent = ordinalScale.getExtent();
  30572. // Providing this method is for optimization:
  30573. // avoid generating a long array by `getTicks`
  30574. // in large category data case.
  30575. var tickCount = ordinalScale.count();
  30576. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  30577. return 0;
  30578. }
  30579. var step = 1;
  30580. // Simple optimization. Empirical value: tick count should less than 40.
  30581. if (tickCount > 40) {
  30582. step = Math.max(1, Math.floor(tickCount / 40));
  30583. }
  30584. var tickValue = ordinalExtent[0];
  30585. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  30586. var unitW = Math.abs(unitSpan * Math.cos(rotation));
  30587. var unitH = Math.abs(unitSpan * Math.sin(rotation));
  30588. var maxW = 0;
  30589. var maxH = 0;
  30590. // Caution: Performance sensitive for large category data.
  30591. // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
  30592. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  30593. var width = 0;
  30594. var height = 0;
  30595. // Not precise, do not consider align and vertical align
  30596. // and each distance from axis line yet.
  30597. var rect = getBoundingRect(
  30598. labelFormatter(tickValue), params.font, 'center', 'top'
  30599. );
  30600. // Magic number
  30601. width = rect.width * 1.3;
  30602. height = rect.height * 1.3;
  30603. // Min size, void long loop.
  30604. maxW = Math.max(maxW, width, 7);
  30605. maxH = Math.max(maxH, height, 7);
  30606. }
  30607. var dw = maxW / unitW;
  30608. var dh = maxH / unitH;
  30609. // 0/0 is NaN, 1/0 is Infinity.
  30610. isNaN(dw) && (dw = Infinity);
  30611. isNaN(dh) && (dh = Infinity);
  30612. var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
  30613. var cache = inner$6(axis.model);
  30614. var lastAutoInterval = cache.lastAutoInterval;
  30615. var lastTickCount = cache.lastTickCount;
  30616. // Use cache to keep interval stable while moving zoom window,
  30617. // otherwise the calculated interval might jitter when the zoom
  30618. // window size is close to the interval-changing size.
  30619. if (lastAutoInterval != null
  30620. && lastTickCount != null
  30621. && Math.abs(lastAutoInterval - interval) <= 1
  30622. && Math.abs(lastTickCount - tickCount) <= 1
  30623. // Always choose the bigger one, otherwise the critical
  30624. // point is not the same when zooming in or zooming out.
  30625. && lastAutoInterval > interval
  30626. ) {
  30627. interval = lastAutoInterval;
  30628. }
  30629. // Only update cache if cache not used, otherwise the
  30630. // changing of interval is too insensitive.
  30631. else {
  30632. cache.lastTickCount = tickCount;
  30633. cache.lastAutoInterval = interval;
  30634. }
  30635. return interval;
  30636. }
  30637. function fetchAutoCategoryIntervalCalculationParams(axis) {
  30638. var labelModel = axis.getLabelModel();
  30639. return {
  30640. axisRotate: axis.getRotate
  30641. ? axis.getRotate()
  30642. : (axis.isHorizontal && !axis.isHorizontal())
  30643. ? 90
  30644. : 0,
  30645. labelRotate: labelModel.get('rotate') || 0,
  30646. font: labelModel.getFont()
  30647. };
  30648. }
  30649. function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
  30650. var labelFormatter = makeLabelFormatter(axis);
  30651. var ordinalScale = axis.scale;
  30652. var ordinalExtent = ordinalScale.getExtent();
  30653. var labelModel = axis.getLabelModel();
  30654. var result = [];
  30655. // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
  30656. var step = Math.max((categoryInterval || 0) + 1, 1);
  30657. var startTick = ordinalExtent[0];
  30658. var tickCount = ordinalScale.count();
  30659. // Calculate start tick based on zero if possible to keep label consistent
  30660. // while zooming and moving while interval > 0. Otherwise the selection
  30661. // of displayable ticks and symbols probably keep changing.
  30662. // 3 is empirical value.
  30663. if (startTick !== 0 && step > 1 && tickCount / step > 2) {
  30664. startTick = Math.round(Math.ceil(startTick / step) * step);
  30665. }
  30666. // (1) Only add min max label here but leave overlap checking
  30667. // to render stage, which also ensure the returned list
  30668. // suitable for splitLine and splitArea rendering.
  30669. // (2) Scales except category always contain min max label so
  30670. // do not need to perform this process.
  30671. var showAllLabel = shouldShowAllLabels(axis);
  30672. var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
  30673. var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
  30674. if (includeMinLabel && startTick !== ordinalExtent[0]) {
  30675. addItem(ordinalExtent[0]);
  30676. }
  30677. // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
  30678. var tickValue = startTick;
  30679. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  30680. addItem(tickValue);
  30681. }
  30682. if (includeMaxLabel && tickValue !== ordinalExtent[1]) {
  30683. addItem(ordinalExtent[1]);
  30684. }
  30685. function addItem(tVal) {
  30686. result.push(onlyTick
  30687. ? tVal
  30688. : {
  30689. formattedLabel: labelFormatter(tVal),
  30690. rawLabel: ordinalScale.getLabel(tVal),
  30691. tickValue: tVal
  30692. }
  30693. );
  30694. }
  30695. return result;
  30696. }
  30697. // When interval is function, the result `false` means ignore the tick.
  30698. // It is time consuming for large category data.
  30699. function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
  30700. var ordinalScale = axis.scale;
  30701. var labelFormatter = makeLabelFormatter(axis);
  30702. var result = [];
  30703. each$1(ordinalScale.getTicks(), function (tickValue) {
  30704. var rawLabel = ordinalScale.getLabel(tickValue);
  30705. if (categoryInterval(tickValue, rawLabel)) {
  30706. result.push(onlyTick
  30707. ? tickValue
  30708. : {
  30709. formattedLabel: labelFormatter(tickValue),
  30710. rawLabel: rawLabel,
  30711. tickValue: tickValue
  30712. }
  30713. );
  30714. }
  30715. });
  30716. return result;
  30717. }
  30718. /*
  30719. * Licensed to the Apache Software Foundation (ASF) under one
  30720. * or more contributor license agreements. See the NOTICE file
  30721. * distributed with this work for additional information
  30722. * regarding copyright ownership. The ASF licenses this file
  30723. * to you under the Apache License, Version 2.0 (the
  30724. * "License"); you may not use this file except in compliance
  30725. * with the License. You may obtain a copy of the License at
  30726. *
  30727. * http://www.apache.org/licenses/LICENSE-2.0
  30728. *
  30729. * Unless required by applicable law or agreed to in writing,
  30730. * software distributed under the License is distributed on an
  30731. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30732. * KIND, either express or implied. See the License for the
  30733. * specific language governing permissions and limitations
  30734. * under the License.
  30735. */
  30736. var NORMALIZED_EXTENT = [0, 1];
  30737. /**
  30738. * Base class of Axis.
  30739. * @constructor
  30740. */
  30741. var Axis = function (dim, scale, extent) {
  30742. /**
  30743. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'.
  30744. * @type {string}
  30745. */
  30746. this.dim = dim;
  30747. /**
  30748. * Axis scale
  30749. * @type {module:echarts/coord/scale/*}
  30750. */
  30751. this.scale = scale;
  30752. /**
  30753. * @type {Array.<number>}
  30754. * @private
  30755. */
  30756. this._extent = extent || [0, 0];
  30757. /**
  30758. * @type {boolean}
  30759. */
  30760. this.inverse = false;
  30761. /**
  30762. * Usually true when axis has a ordinal scale
  30763. * @type {boolean}
  30764. */
  30765. this.onBand = false;
  30766. };
  30767. Axis.prototype = {
  30768. constructor: Axis,
  30769. /**
  30770. * If axis extent contain given coord
  30771. * @param {number} coord
  30772. * @return {boolean}
  30773. */
  30774. contain: function (coord) {
  30775. var extent = this._extent;
  30776. var min = Math.min(extent[0], extent[1]);
  30777. var max = Math.max(extent[0], extent[1]);
  30778. return coord >= min && coord <= max;
  30779. },
  30780. /**
  30781. * If axis extent contain given data
  30782. * @param {number} data
  30783. * @return {boolean}
  30784. */
  30785. containData: function (data) {
  30786. return this.contain(this.dataToCoord(data));
  30787. },
  30788. /**
  30789. * Get coord extent.
  30790. * @return {Array.<number>}
  30791. */
  30792. getExtent: function () {
  30793. return this._extent.slice();
  30794. },
  30795. /**
  30796. * Get precision used for formatting
  30797. * @param {Array.<number>} [dataExtent]
  30798. * @return {number}
  30799. */
  30800. getPixelPrecision: function (dataExtent) {
  30801. return getPixelPrecision(
  30802. dataExtent || this.scale.getExtent(),
  30803. this._extent
  30804. );
  30805. },
  30806. /**
  30807. * Set coord extent
  30808. * @param {number} start
  30809. * @param {number} end
  30810. */
  30811. setExtent: function (start, end) {
  30812. var extent = this._extent;
  30813. extent[0] = start;
  30814. extent[1] = end;
  30815. },
  30816. /**
  30817. * Convert data to coord. Data is the rank if it has an ordinal scale
  30818. * @param {number} data
  30819. * @param {boolean} clamp
  30820. * @return {number}
  30821. */
  30822. dataToCoord: function (data, clamp) {
  30823. var extent = this._extent;
  30824. var scale = this.scale;
  30825. data = scale.normalize(data);
  30826. if (this.onBand && scale.type === 'ordinal') {
  30827. extent = extent.slice();
  30828. fixExtentWithBands(extent, scale.count());
  30829. }
  30830. return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
  30831. },
  30832. /**
  30833. * Convert coord to data. Data is the rank if it has an ordinal scale
  30834. * @param {number} coord
  30835. * @param {boolean} clamp
  30836. * @return {number}
  30837. */
  30838. coordToData: function (coord, clamp) {
  30839. var extent = this._extent;
  30840. var scale = this.scale;
  30841. if (this.onBand && scale.type === 'ordinal') {
  30842. extent = extent.slice();
  30843. fixExtentWithBands(extent, scale.count());
  30844. }
  30845. var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
  30846. return this.scale.scale(t);
  30847. },
  30848. /**
  30849. * Convert pixel point to data in axis
  30850. * @param {Array.<number>} point
  30851. * @param {boolean} clamp
  30852. * @return {number} data
  30853. */
  30854. pointToData: function (point, clamp) {
  30855. // Should be implemented in derived class if necessary.
  30856. },
  30857. /**
  30858. * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
  30859. * `axis.getTicksCoords` considers `onBand`, which is used by
  30860. * `boundaryGap:true` of category axis and splitLine and splitArea.
  30861. * @param {Object} [opt]
  30862. * @param {number} [opt.tickModel=axis.model.getModel('axisTick')]
  30863. * @param {boolean} [opt.clamp] If `true`, the first and the last
  30864. * tick must be at the axis end points. Otherwise, clip ticks
  30865. * that outside the axis extent.
  30866. * @return {Array.<Object>} [{
  30867. * coord: ...,
  30868. * tickValue: ...
  30869. * }, ...]
  30870. */
  30871. getTicksCoords: function (opt) {
  30872. opt = opt || {};
  30873. var tickModel = opt.tickModel || this.getTickModel();
  30874. var result = createAxisTicks(this, tickModel);
  30875. var ticks = result.ticks;
  30876. var ticksCoords = map(ticks, function (tickValue) {
  30877. return {
  30878. coord: this.dataToCoord(tickValue),
  30879. tickValue: tickValue
  30880. };
  30881. }, this);
  30882. var alignWithLabel = tickModel.get('alignWithLabel');
  30883. fixOnBandTicksCoords(
  30884. this, ticksCoords, result.tickCategoryInterval, alignWithLabel, opt.clamp
  30885. );
  30886. return ticksCoords;
  30887. },
  30888. /**
  30889. * @return {Array.<Object>} [{
  30890. * formattedLabel: string,
  30891. * rawLabel: axis.scale.getLabel(tickValue)
  30892. * tickValue: number
  30893. * }, ...]
  30894. */
  30895. getViewLabels: function () {
  30896. return createAxisLabels(this).labels;
  30897. },
  30898. /**
  30899. * @return {module:echarts/coord/model/Model}
  30900. */
  30901. getLabelModel: function () {
  30902. return this.model.getModel('axisLabel');
  30903. },
  30904. /**
  30905. * Notice here we only get the default tick model. For splitLine
  30906. * or splitArea, we should pass the splitLineModel or splitAreaModel
  30907. * manually when calling `getTicksCoords`.
  30908. * In GL, this method may be overrided to:
  30909. * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
  30910. * @return {module:echarts/coord/model/Model}
  30911. */
  30912. getTickModel: function () {
  30913. return this.model.getModel('axisTick');
  30914. },
  30915. /**
  30916. * Get width of band
  30917. * @return {number}
  30918. */
  30919. getBandWidth: function () {
  30920. var axisExtent = this._extent;
  30921. var dataExtent = this.scale.getExtent();
  30922. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  30923. // Fix #2728, avoid NaN when only one data.
  30924. len === 0 && (len = 1);
  30925. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  30926. return Math.abs(size) / len;
  30927. },
  30928. /**
  30929. * @abstract
  30930. * @return {boolean} Is horizontal
  30931. */
  30932. isHorizontal: null,
  30933. /**
  30934. * @abstract
  30935. * @return {number} Get axis rotate, by degree.
  30936. */
  30937. getRotate: null,
  30938. /**
  30939. * Only be called in category axis.
  30940. * Can be overrided, consider other axes like in 3D.
  30941. * @return {number} Auto interval for cateogry axis tick and label
  30942. */
  30943. calculateCategoryInterval: function () {
  30944. return calculateCategoryInterval(this);
  30945. }
  30946. };
  30947. function fixExtentWithBands(extent, nTick) {
  30948. var size = extent[1] - extent[0];
  30949. var len = nTick;
  30950. var margin = size / len / 2;
  30951. extent[0] += margin;
  30952. extent[1] -= margin;
  30953. }
  30954. // If axis has labels [1, 2, 3, 4]. Bands on the axis are
  30955. // |---1---|---2---|---3---|---4---|.
  30956. // So the displayed ticks and splitLine/splitArea should between
  30957. // each data item, otherwise cause misleading (e.g., split tow bars
  30958. // of a single data item when there are two bar series).
  30959. // Also consider if tickCategoryInterval > 0 and onBand, ticks and
  30960. // splitLine/spliteArea should layout appropriately corresponding
  30961. // to displayed labels. (So we should not use `getBandWidth` in this
  30962. // case).
  30963. function fixOnBandTicksCoords(axis, ticksCoords, tickCategoryInterval, alignWithLabel, clamp) {
  30964. var ticksLen = ticksCoords.length;
  30965. if (!axis.onBand || alignWithLabel || !ticksLen) {
  30966. return;
  30967. }
  30968. var axisExtent = axis.getExtent();
  30969. var last;
  30970. if (ticksLen === 1) {
  30971. ticksCoords[0].coord = axisExtent[0];
  30972. last = ticksCoords[1] = {coord: axisExtent[0]};
  30973. }
  30974. else {
  30975. var shift = (ticksCoords[1].coord - ticksCoords[0].coord);
  30976. each$1(ticksCoords, function (ticksItem) {
  30977. ticksItem.coord -= shift / 2;
  30978. var tickCategoryInterval = tickCategoryInterval || 0;
  30979. // Avoid split a single data item when odd interval.
  30980. if (tickCategoryInterval % 2 > 0) {
  30981. ticksItem.coord -= shift / ((tickCategoryInterval + 1) * 2);
  30982. }
  30983. });
  30984. last = {coord: ticksCoords[ticksLen - 1].coord + shift};
  30985. ticksCoords.push(last);
  30986. }
  30987. var inverse = axisExtent[0] > axisExtent[1];
  30988. if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
  30989. clamp ? (ticksCoords[0].coord = axisExtent[0]) : ticksCoords.shift();
  30990. }
  30991. if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
  30992. ticksCoords.unshift({coord: axisExtent[0]});
  30993. }
  30994. if (littleThan(axisExtent[1], last.coord)) {
  30995. clamp ? (last.coord = axisExtent[1]) : ticksCoords.pop();
  30996. }
  30997. if (clamp && littleThan(last.coord, axisExtent[1])) {
  30998. ticksCoords.push({coord: axisExtent[1]});
  30999. }
  31000. function littleThan(a, b) {
  31001. return inverse ? a > b : a < b;
  31002. }
  31003. }
  31004. /*
  31005. * Licensed to the Apache Software Foundation (ASF) under one
  31006. * or more contributor license agreements. See the NOTICE file
  31007. * distributed with this work for additional information
  31008. * regarding copyright ownership. The ASF licenses this file
  31009. * to you under the Apache License, Version 2.0 (the
  31010. * "License"); you may not use this file except in compliance
  31011. * with the License. You may obtain a copy of the License at
  31012. *
  31013. * http://www.apache.org/licenses/LICENSE-2.0
  31014. *
  31015. * Unless required by applicable law or agreed to in writing,
  31016. * software distributed under the License is distributed on an
  31017. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31018. * KIND, either express or implied. See the License for the
  31019. * specific language governing permissions and limitations
  31020. * under the License.
  31021. */
  31022. /**
  31023. * Do not mount those modules on 'src/echarts' for better tree shaking.
  31024. */
  31025. var parseGeoJson = parseGeoJson$1;
  31026. var ecUtil = {};
  31027. each$1(
  31028. [
  31029. 'map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter',
  31030. 'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction',
  31031. 'extend', 'defaults', 'clone', 'merge'
  31032. ],
  31033. function (name) {
  31034. ecUtil[name] = zrUtil[name];
  31035. }
  31036. );
  31037. var graphic$1 = {};
  31038. each$1(
  31039. [
  31040. 'extendShape', 'extendPath', 'makePath', 'makeImage',
  31041. 'mergePath', 'resizePath', 'createIcon',
  31042. 'setHoverStyle', 'setLabelStyle', 'setTextStyle', 'setText',
  31043. 'getFont', 'updateProps', 'initProps', 'getTransform',
  31044. 'clipPointsByRect', 'clipRectByRect',
  31045. 'Group',
  31046. 'Image',
  31047. 'Text',
  31048. 'Circle',
  31049. 'Sector',
  31050. 'Ring',
  31051. 'Polygon',
  31052. 'Polyline',
  31053. 'Rect',
  31054. 'Line',
  31055. 'BezierCurve',
  31056. 'Arc',
  31057. 'IncrementalDisplayable',
  31058. 'CompoundPath',
  31059. 'LinearGradient',
  31060. 'RadialGradient',
  31061. 'BoundingRect'
  31062. ],
  31063. function (name) {
  31064. graphic$1[name] = graphic[name];
  31065. }
  31066. );
  31067. /*
  31068. * Licensed to the Apache Software Foundation (ASF) under one
  31069. * or more contributor license agreements. See the NOTICE file
  31070. * distributed with this work for additional information
  31071. * regarding copyright ownership. The ASF licenses this file
  31072. * to you under the Apache License, Version 2.0 (the
  31073. * "License"); you may not use this file except in compliance
  31074. * with the License. You may obtain a copy of the License at
  31075. *
  31076. * http://www.apache.org/licenses/LICENSE-2.0
  31077. *
  31078. * Unless required by applicable law or agreed to in writing,
  31079. * software distributed under the License is distributed on an
  31080. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31081. * KIND, either express or implied. See the License for the
  31082. * specific language governing permissions and limitations
  31083. * under the License.
  31084. */
  31085. SeriesModel.extend({
  31086. type: 'series.line',
  31087. dependencies: ['grid', 'polar'],
  31088. getInitialData: function (option, ecModel) {
  31089. if (__DEV__) {
  31090. var coordSys = option.coordinateSystem;
  31091. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  31092. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  31093. }
  31094. }
  31095. return createListFromArray(this.getSource(), this);
  31096. },
  31097. defaultOption: {
  31098. zlevel: 0,
  31099. z: 2,
  31100. coordinateSystem: 'cartesian2d',
  31101. legendHoverLink: true,
  31102. hoverAnimation: true,
  31103. // stack: null
  31104. // xAxisIndex: 0,
  31105. // yAxisIndex: 0,
  31106. // polarIndex: 0,
  31107. // If clip the overflow value
  31108. clipOverflow: true,
  31109. // cursor: null,
  31110. label: {
  31111. position: 'top'
  31112. },
  31113. // itemStyle: {
  31114. // },
  31115. lineStyle: {
  31116. width: 2,
  31117. type: 'solid'
  31118. },
  31119. // areaStyle: {
  31120. // origin of areaStyle. Valid values:
  31121. // `'auto'/null/undefined`: from axisLine to data
  31122. // `'start'`: from min to data
  31123. // `'end'`: from data to max
  31124. // origin: 'auto'
  31125. // },
  31126. // false, 'start', 'end', 'middle'
  31127. step: false,
  31128. // Disabled if step is true
  31129. smooth: false,
  31130. smoothMonotone: null,
  31131. symbol: 'emptyCircle',
  31132. symbolSize: 4,
  31133. symbolRotate: null,
  31134. showSymbol: true,
  31135. // `false`: follow the label interval strategy.
  31136. // `true`: show all symbols.
  31137. // `'auto'`: If possible, show all symbols, otherwise
  31138. // follow the label interval strategy.
  31139. showAllSymbol: 'auto',
  31140. // Whether to connect break point.
  31141. connectNulls: false,
  31142. // Sampling for large data. Can be: 'average', 'max', 'min', 'sum'.
  31143. sampling: 'none',
  31144. animationEasing: 'linear',
  31145. // Disable progressive
  31146. progressive: 0,
  31147. hoverLayerThreshold: Infinity
  31148. }
  31149. });
  31150. /*
  31151. * Licensed to the Apache Software Foundation (ASF) under one
  31152. * or more contributor license agreements. See the NOTICE file
  31153. * distributed with this work for additional information
  31154. * regarding copyright ownership. The ASF licenses this file
  31155. * to you under the Apache License, Version 2.0 (the
  31156. * "License"); you may not use this file except in compliance
  31157. * with the License. You may obtain a copy of the License at
  31158. *
  31159. * http://www.apache.org/licenses/LICENSE-2.0
  31160. *
  31161. * Unless required by applicable law or agreed to in writing,
  31162. * software distributed under the License is distributed on an
  31163. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31164. * KIND, either express or implied. See the License for the
  31165. * specific language governing permissions and limitations
  31166. * under the License.
  31167. */
  31168. /**
  31169. * @param {module:echarts/data/List} data
  31170. * @param {number} dataIndex
  31171. * @return {string} label string. Not null/undefined
  31172. */
  31173. function getDefaultLabel(data, dataIndex) {
  31174. var labelDims = data.mapDimension('defaultedLabel', true);
  31175. var len = labelDims.length;
  31176. // Simple optimization (in lots of cases, label dims length is 1)
  31177. if (len === 1) {
  31178. return retrieveRawValue(data, dataIndex, labelDims[0]);
  31179. }
  31180. else if (len) {
  31181. var vals = [];
  31182. for (var i = 0; i < labelDims.length; i++) {
  31183. var val = retrieveRawValue(data, dataIndex, labelDims[i]);
  31184. vals.push(val);
  31185. }
  31186. return vals.join(' ');
  31187. }
  31188. }
  31189. /*
  31190. * Licensed to the Apache Software Foundation (ASF) under one
  31191. * or more contributor license agreements. See the NOTICE file
  31192. * distributed with this work for additional information
  31193. * regarding copyright ownership. The ASF licenses this file
  31194. * to you under the Apache License, Version 2.0 (the
  31195. * "License"); you may not use this file except in compliance
  31196. * with the License. You may obtain a copy of the License at
  31197. *
  31198. * http://www.apache.org/licenses/LICENSE-2.0
  31199. *
  31200. * Unless required by applicable law or agreed to in writing,
  31201. * software distributed under the License is distributed on an
  31202. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31203. * KIND, either express or implied. See the License for the
  31204. * specific language governing permissions and limitations
  31205. * under the License.
  31206. */
  31207. /**
  31208. * @module echarts/chart/helper/Symbol
  31209. */
  31210. /**
  31211. * @constructor
  31212. * @alias {module:echarts/chart/helper/Symbol}
  31213. * @param {module:echarts/data/List} data
  31214. * @param {number} idx
  31215. * @extends {module:zrender/graphic/Group}
  31216. */
  31217. function SymbolClz$1(data, idx, seriesScope) {
  31218. Group.call(this);
  31219. this.updateData(data, idx, seriesScope);
  31220. }
  31221. var symbolProto = SymbolClz$1.prototype;
  31222. /**
  31223. * @public
  31224. * @static
  31225. * @param {module:echarts/data/List} data
  31226. * @param {number} dataIndex
  31227. * @return {Array.<number>} [width, height]
  31228. */
  31229. var getSymbolSize = SymbolClz$1.getSymbolSize = function (data, idx) {
  31230. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  31231. return symbolSize instanceof Array
  31232. ? symbolSize.slice()
  31233. : [+symbolSize, +symbolSize];
  31234. };
  31235. function getScale(symbolSize) {
  31236. return [symbolSize[0] / 2, symbolSize[1] / 2];
  31237. }
  31238. function driftSymbol(dx, dy) {
  31239. this.parent.drift(dx, dy);
  31240. }
  31241. symbolProto._createSymbol = function (
  31242. symbolType,
  31243. data,
  31244. idx,
  31245. symbolSize,
  31246. keepAspect
  31247. ) {
  31248. // Remove paths created before
  31249. this.removeAll();
  31250. var color = data.getItemVisual(idx, 'color');
  31251. // var symbolPath = createSymbol(
  31252. // symbolType, -0.5, -0.5, 1, 1, color
  31253. // );
  31254. // If width/height are set too small (e.g., set to 1) on ios10
  31255. // and macOS Sierra, a circle stroke become a rect, no matter what
  31256. // the scale is set. So we set width/height as 2. See #4150.
  31257. var symbolPath = createSymbol(
  31258. symbolType, -1, -1, 2, 2, color, keepAspect
  31259. );
  31260. symbolPath.attr({
  31261. z2: 100,
  31262. culling: true,
  31263. scale: getScale(symbolSize)
  31264. });
  31265. // Rewrite drift method
  31266. symbolPath.drift = driftSymbol;
  31267. this._symbolType = symbolType;
  31268. this.add(symbolPath);
  31269. };
  31270. /**
  31271. * Stop animation
  31272. * @param {boolean} toLastFrame
  31273. */
  31274. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  31275. this.childAt(0).stopAnimation(toLastFrame);
  31276. };
  31277. /**
  31278. * FIXME:
  31279. * Caution: This method breaks the encapsulation of this module,
  31280. * but it indeed brings convenience. So do not use the method
  31281. * unless you detailedly know all the implements of `Symbol`,
  31282. * especially animation.
  31283. *
  31284. * Get symbol path element.
  31285. */
  31286. symbolProto.getSymbolPath = function () {
  31287. return this.childAt(0);
  31288. };
  31289. /**
  31290. * Get scale(aka, current symbol size).
  31291. * Including the change caused by animation
  31292. */
  31293. symbolProto.getScale = function () {
  31294. return this.childAt(0).scale;
  31295. };
  31296. /**
  31297. * Highlight symbol
  31298. */
  31299. symbolProto.highlight = function () {
  31300. this.childAt(0).trigger('emphasis');
  31301. };
  31302. /**
  31303. * Downplay symbol
  31304. */
  31305. symbolProto.downplay = function () {
  31306. this.childAt(0).trigger('normal');
  31307. };
  31308. /**
  31309. * @param {number} zlevel
  31310. * @param {number} z
  31311. */
  31312. symbolProto.setZ = function (zlevel, z) {
  31313. var symbolPath = this.childAt(0);
  31314. symbolPath.zlevel = zlevel;
  31315. symbolPath.z = z;
  31316. };
  31317. symbolProto.setDraggable = function (draggable) {
  31318. var symbolPath = this.childAt(0);
  31319. symbolPath.draggable = draggable;
  31320. symbolPath.cursor = draggable ? 'move' : 'pointer';
  31321. };
  31322. /**
  31323. * Update symbol properties
  31324. * @param {module:echarts/data/List} data
  31325. * @param {number} idx
  31326. * @param {Object} [seriesScope]
  31327. * @param {Object} [seriesScope.itemStyle]
  31328. * @param {Object} [seriesScope.hoverItemStyle]
  31329. * @param {Object} [seriesScope.symbolRotate]
  31330. * @param {Object} [seriesScope.symbolOffset]
  31331. * @param {module:echarts/model/Model} [seriesScope.labelModel]
  31332. * @param {module:echarts/model/Model} [seriesScope.hoverLabelModel]
  31333. * @param {boolean} [seriesScope.hoverAnimation]
  31334. * @param {Object} [seriesScope.cursorStyle]
  31335. * @param {module:echarts/model/Model} [seriesScope.itemModel]
  31336. * @param {string} [seriesScope.symbolInnerColor]
  31337. * @param {Object} [seriesScope.fadeIn=false]
  31338. */
  31339. symbolProto.updateData = function (data, idx, seriesScope) {
  31340. this.silent = false;
  31341. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  31342. var seriesModel = data.hostModel;
  31343. var symbolSize = getSymbolSize(data, idx);
  31344. var isInit = symbolType !== this._symbolType;
  31345. if (isInit) {
  31346. var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
  31347. this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
  31348. }
  31349. else {
  31350. var symbolPath = this.childAt(0);
  31351. symbolPath.silent = false;
  31352. updateProps(symbolPath, {
  31353. scale: getScale(symbolSize)
  31354. }, seriesModel, idx);
  31355. }
  31356. this._updateCommon(data, idx, symbolSize, seriesScope);
  31357. if (isInit) {
  31358. var symbolPath = this.childAt(0);
  31359. var fadeIn = seriesScope && seriesScope.fadeIn;
  31360. var target = {scale: symbolPath.scale.slice()};
  31361. fadeIn && (target.style = {opacity: symbolPath.style.opacity});
  31362. symbolPath.scale = [0, 0];
  31363. fadeIn && (symbolPath.style.opacity = 0);
  31364. initProps(symbolPath, target, seriesModel, idx);
  31365. }
  31366. this._seriesModel = seriesModel;
  31367. };
  31368. // Update common properties
  31369. var normalStyleAccessPath = ['itemStyle'];
  31370. var emphasisStyleAccessPath = ['emphasis', 'itemStyle'];
  31371. var normalLabelAccessPath = ['label'];
  31372. var emphasisLabelAccessPath = ['emphasis', 'label'];
  31373. /**
  31374. * @param {module:echarts/data/List} data
  31375. * @param {number} idx
  31376. * @param {Array.<number>} symbolSize
  31377. * @param {Object} [seriesScope]
  31378. */
  31379. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  31380. var symbolPath = this.childAt(0);
  31381. var seriesModel = data.hostModel;
  31382. var color = data.getItemVisual(idx, 'color');
  31383. // Reset style
  31384. if (symbolPath.type !== 'image') {
  31385. symbolPath.useStyle({
  31386. strokeNoScale: true
  31387. });
  31388. }
  31389. var itemStyle = seriesScope && seriesScope.itemStyle;
  31390. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  31391. var symbolRotate = seriesScope && seriesScope.symbolRotate;
  31392. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  31393. var labelModel = seriesScope && seriesScope.labelModel;
  31394. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  31395. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  31396. var cursorStyle = seriesScope && seriesScope.cursorStyle;
  31397. if (!seriesScope || data.hasItemOption) {
  31398. var itemModel = (seriesScope && seriesScope.itemModel)
  31399. ? seriesScope.itemModel : data.getItemModel(idx);
  31400. // Color must be excluded.
  31401. // Because symbol provide setColor individually to set fill and stroke
  31402. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  31403. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  31404. symbolRotate = itemModel.getShallow('symbolRotate');
  31405. symbolOffset = itemModel.getShallow('symbolOffset');
  31406. labelModel = itemModel.getModel(normalLabelAccessPath);
  31407. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  31408. hoverAnimation = itemModel.getShallow('hoverAnimation');
  31409. cursorStyle = itemModel.getShallow('cursor');
  31410. }
  31411. else {
  31412. hoverItemStyle = extend({}, hoverItemStyle);
  31413. }
  31414. var elStyle = symbolPath.style;
  31415. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  31416. if (symbolOffset) {
  31417. symbolPath.attr('position', [
  31418. parsePercent$1(symbolOffset[0], symbolSize[0]),
  31419. parsePercent$1(symbolOffset[1], symbolSize[1])
  31420. ]);
  31421. }
  31422. cursorStyle && symbolPath.attr('cursor', cursorStyle);
  31423. // PENDING setColor before setStyle!!!
  31424. symbolPath.setColor(color, seriesScope && seriesScope.symbolInnerColor);
  31425. symbolPath.setStyle(itemStyle);
  31426. var opacity = data.getItemVisual(idx, 'opacity');
  31427. if (opacity != null) {
  31428. elStyle.opacity = opacity;
  31429. }
  31430. var liftZ = data.getItemVisual(idx, 'liftZ');
  31431. var z2Origin = symbolPath.__z2Origin;
  31432. if (liftZ != null) {
  31433. if (z2Origin == null) {
  31434. symbolPath.__z2Origin = symbolPath.z2;
  31435. symbolPath.z2 += liftZ;
  31436. }
  31437. }
  31438. else if (z2Origin != null) {
  31439. symbolPath.z2 = z2Origin;
  31440. symbolPath.__z2Origin = null;
  31441. }
  31442. var useNameLabel = seriesScope && seriesScope.useNameLabel;
  31443. setLabelStyle(
  31444. elStyle, hoverItemStyle, labelModel, hoverLabelModel,
  31445. {
  31446. labelFetcher: seriesModel,
  31447. labelDataIndex: idx,
  31448. defaultText: getLabelDefaultText,
  31449. isRectText: true,
  31450. autoColor: color
  31451. }
  31452. );
  31453. // Do not execute util needed.
  31454. function getLabelDefaultText(idx, opt) {
  31455. return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
  31456. }
  31457. symbolPath.off('mouseover')
  31458. .off('mouseout')
  31459. .off('emphasis')
  31460. .off('normal');
  31461. symbolPath.hoverStyle = hoverItemStyle;
  31462. // FIXME
  31463. // Do not use symbol.trigger('emphasis'), but use symbol.highlight() instead.
  31464. setHoverStyle(symbolPath);
  31465. symbolPath.__symbolOriginalScale = getScale(symbolSize);
  31466. if (hoverAnimation && seriesModel.isAnimationEnabled()) {
  31467. // Note: consider `off`, should use static function here.
  31468. symbolPath.on('mouseover', onMouseOver)
  31469. .on('mouseout', onMouseOut)
  31470. .on('emphasis', onEmphasis)
  31471. .on('normal', onNormal);
  31472. }
  31473. };
  31474. function onMouseOver() {
  31475. // see comment in `graphic.isInEmphasis`
  31476. !isInEmphasis(this) && onEmphasis.call(this);
  31477. }
  31478. function onMouseOut() {
  31479. // see comment in `graphic.isInEmphasis`
  31480. !isInEmphasis(this) && onNormal.call(this);
  31481. }
  31482. function onEmphasis() {
  31483. // Do not support this hover animation util some scenario required.
  31484. // Animation can only be supported in hover layer when using `el.incremetal`.
  31485. if (this.incremental || this.useHoverLayer) {
  31486. return;
  31487. }
  31488. var scale = this.__symbolOriginalScale;
  31489. var ratio = scale[1] / scale[0];
  31490. this.animateTo({
  31491. scale: [
  31492. Math.max(scale[0] * 1.1, scale[0] + 3),
  31493. Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)
  31494. ]
  31495. }, 400, 'elasticOut');
  31496. }
  31497. function onNormal() {
  31498. if (this.incremental || this.useHoverLayer) {
  31499. return;
  31500. }
  31501. this.animateTo({
  31502. scale: this.__symbolOriginalScale
  31503. }, 400, 'elasticOut');
  31504. }
  31505. /**
  31506. * @param {Function} cb
  31507. * @param {Object} [opt]
  31508. * @param {Object} [opt.keepLabel=true]
  31509. */
  31510. symbolProto.fadeOut = function (cb, opt) {
  31511. var symbolPath = this.childAt(0);
  31512. // Avoid mistaken hover when fading out
  31513. this.silent = symbolPath.silent = true;
  31514. // Not show text when animating
  31515. !(opt && opt.keepLabel) && (symbolPath.style.text = null);
  31516. updateProps(
  31517. symbolPath,
  31518. {
  31519. style: {opacity: 0},
  31520. scale: [0, 0]
  31521. },
  31522. this._seriesModel,
  31523. this.dataIndex,
  31524. cb
  31525. );
  31526. };
  31527. inherits(SymbolClz$1, Group);
  31528. /*
  31529. * Licensed to the Apache Software Foundation (ASF) under one
  31530. * or more contributor license agreements. See the NOTICE file
  31531. * distributed with this work for additional information
  31532. * regarding copyright ownership. The ASF licenses this file
  31533. * to you under the Apache License, Version 2.0 (the
  31534. * "License"); you may not use this file except in compliance
  31535. * with the License. You may obtain a copy of the License at
  31536. *
  31537. * http://www.apache.org/licenses/LICENSE-2.0
  31538. *
  31539. * Unless required by applicable law or agreed to in writing,
  31540. * software distributed under the License is distributed on an
  31541. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31542. * KIND, either express or implied. See the License for the
  31543. * specific language governing permissions and limitations
  31544. * under the License.
  31545. */
  31546. /**
  31547. * @module echarts/chart/helper/SymbolDraw
  31548. */
  31549. /**
  31550. * @constructor
  31551. * @alias module:echarts/chart/helper/SymbolDraw
  31552. * @param {module:zrender/graphic/Group} [symbolCtor]
  31553. */
  31554. function SymbolDraw(symbolCtor) {
  31555. this.group = new Group();
  31556. this._symbolCtor = symbolCtor || SymbolClz$1;
  31557. }
  31558. var symbolDrawProto = SymbolDraw.prototype;
  31559. function symbolNeedsDraw(data, point, idx, opt) {
  31560. return point && !isNaN(point[0]) && !isNaN(point[1])
  31561. && !(opt.isIgnore && opt.isIgnore(idx))
  31562. // We do not set clipShape on group, because it will cut part of
  31563. // the symbol element shape. We use the same clip shape here as
  31564. // the line clip.
  31565. && !(opt.clipShape && !opt.clipShape.contain(point[0], point[1]))
  31566. && data.getItemVisual(idx, 'symbol') !== 'none';
  31567. }
  31568. /**
  31569. * Update symbols draw by new data
  31570. * @param {module:echarts/data/List} data
  31571. * @param {Object} [opt] Or isIgnore
  31572. * @param {Function} [opt.isIgnore]
  31573. * @param {Object} [opt.clipShape]
  31574. */
  31575. symbolDrawProto.updateData = function (data, opt) {
  31576. opt = normalizeUpdateOpt(opt);
  31577. var group = this.group;
  31578. var seriesModel = data.hostModel;
  31579. var oldData = this._data;
  31580. var SymbolCtor = this._symbolCtor;
  31581. var seriesScope = makeSeriesScope(data);
  31582. // There is no oldLineData only when first rendering or switching from
  31583. // stream mode to normal mode, where previous elements should be removed.
  31584. if (!oldData) {
  31585. group.removeAll();
  31586. }
  31587. data.diff(oldData)
  31588. .add(function (newIdx) {
  31589. var point = data.getItemLayout(newIdx);
  31590. if (symbolNeedsDraw(data, point, newIdx, opt)) {
  31591. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  31592. symbolEl.attr('position', point);
  31593. data.setItemGraphicEl(newIdx, symbolEl);
  31594. group.add(symbolEl);
  31595. }
  31596. })
  31597. .update(function (newIdx, oldIdx) {
  31598. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  31599. var point = data.getItemLayout(newIdx);
  31600. if (!symbolNeedsDraw(data, point, newIdx, opt)) {
  31601. group.remove(symbolEl);
  31602. return;
  31603. }
  31604. if (!symbolEl) {
  31605. symbolEl = new SymbolCtor(data, newIdx);
  31606. symbolEl.attr('position', point);
  31607. }
  31608. else {
  31609. symbolEl.updateData(data, newIdx, seriesScope);
  31610. updateProps(symbolEl, {
  31611. position: point
  31612. }, seriesModel);
  31613. }
  31614. // Add back
  31615. group.add(symbolEl);
  31616. data.setItemGraphicEl(newIdx, symbolEl);
  31617. })
  31618. .remove(function (oldIdx) {
  31619. var el = oldData.getItemGraphicEl(oldIdx);
  31620. el && el.fadeOut(function () {
  31621. group.remove(el);
  31622. });
  31623. })
  31624. .execute();
  31625. this._data = data;
  31626. };
  31627. symbolDrawProto.isPersistent = function () {
  31628. return true;
  31629. };
  31630. symbolDrawProto.updateLayout = function () {
  31631. var data = this._data;
  31632. if (data) {
  31633. // Not use animation
  31634. data.eachItemGraphicEl(function (el, idx) {
  31635. var point = data.getItemLayout(idx);
  31636. el.attr('position', point);
  31637. });
  31638. }
  31639. };
  31640. symbolDrawProto.incrementalPrepareUpdate = function (data) {
  31641. this._seriesScope = makeSeriesScope(data);
  31642. this._data = null;
  31643. this.group.removeAll();
  31644. };
  31645. /**
  31646. * Update symbols draw by new data
  31647. * @param {module:echarts/data/List} data
  31648. * @param {Object} [opt] Or isIgnore
  31649. * @param {Function} [opt.isIgnore]
  31650. * @param {Object} [opt.clipShape]
  31651. */
  31652. symbolDrawProto.incrementalUpdate = function (taskParams, data, opt) {
  31653. opt = normalizeUpdateOpt(opt);
  31654. function updateIncrementalAndHover(el) {
  31655. if (!el.isGroup) {
  31656. el.incremental = el.useHoverLayer = true;
  31657. }
  31658. }
  31659. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  31660. var point = data.getItemLayout(idx);
  31661. if (symbolNeedsDraw(data, point, idx, opt)) {
  31662. var el = new this._symbolCtor(data, idx, this._seriesScope);
  31663. el.traverse(updateIncrementalAndHover);
  31664. el.attr('position', point);
  31665. this.group.add(el);
  31666. data.setItemGraphicEl(idx, el);
  31667. }
  31668. }
  31669. };
  31670. function normalizeUpdateOpt(opt) {
  31671. if (opt != null && !isObject$1(opt)) {
  31672. opt = {isIgnore: opt};
  31673. }
  31674. return opt || {};
  31675. }
  31676. symbolDrawProto.remove = function (enableAnimation) {
  31677. var group = this.group;
  31678. var data = this._data;
  31679. // Incremental model do not have this._data.
  31680. if (data && enableAnimation) {
  31681. data.eachItemGraphicEl(function (el) {
  31682. el.fadeOut(function () {
  31683. group.remove(el);
  31684. });
  31685. });
  31686. }
  31687. else {
  31688. group.removeAll();
  31689. }
  31690. };
  31691. function makeSeriesScope(data) {
  31692. var seriesModel = data.hostModel;
  31693. return {
  31694. itemStyle: seriesModel.getModel('itemStyle').getItemStyle(['color']),
  31695. hoverItemStyle: seriesModel.getModel('emphasis.itemStyle').getItemStyle(),
  31696. symbolRotate: seriesModel.get('symbolRotate'),
  31697. symbolOffset: seriesModel.get('symbolOffset'),
  31698. hoverAnimation: seriesModel.get('hoverAnimation'),
  31699. labelModel: seriesModel.getModel('label'),
  31700. hoverLabelModel: seriesModel.getModel('emphasis.label'),
  31701. cursorStyle: seriesModel.get('cursor')
  31702. };
  31703. }
  31704. /*
  31705. * Licensed to the Apache Software Foundation (ASF) under one
  31706. * or more contributor license agreements. See the NOTICE file
  31707. * distributed with this work for additional information
  31708. * regarding copyright ownership. The ASF licenses this file
  31709. * to you under the Apache License, Version 2.0 (the
  31710. * "License"); you may not use this file except in compliance
  31711. * with the License. You may obtain a copy of the License at
  31712. *
  31713. * http://www.apache.org/licenses/LICENSE-2.0
  31714. *
  31715. * Unless required by applicable law or agreed to in writing,
  31716. * software distributed under the License is distributed on an
  31717. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31718. * KIND, either express or implied. See the License for the
  31719. * specific language governing permissions and limitations
  31720. * under the License.
  31721. */
  31722. /**
  31723. * @param {Object} coordSys
  31724. * @param {module:echarts/data/List} data
  31725. * @param {string} valueOrigin lineSeries.option.areaStyle.origin
  31726. */
  31727. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  31728. var baseAxis = coordSys.getBaseAxis();
  31729. var valueAxis = coordSys.getOtherAxis(baseAxis);
  31730. var valueStart = getValueStart(valueAxis, valueOrigin);
  31731. var baseAxisDim = baseAxis.dim;
  31732. var valueAxisDim = valueAxis.dim;
  31733. var valueDim = data.mapDimension(valueAxisDim);
  31734. var baseDim = data.mapDimension(baseAxisDim);
  31735. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  31736. var dims = map(coordSys.dimensions, function (coordDim) {
  31737. return data.mapDimension(coordDim);
  31738. });
  31739. var stacked;
  31740. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  31741. if (stacked |= isDimensionStacked(data, dims[0] /*, dims[1]*/)) { // jshint ignore:line
  31742. dims[0] = stackResultDim;
  31743. }
  31744. if (stacked |= isDimensionStacked(data, dims[1] /*, dims[0]*/)) { // jshint ignore:line
  31745. dims[1] = stackResultDim;
  31746. }
  31747. return {
  31748. dataDimsForPoint: dims,
  31749. valueStart: valueStart,
  31750. valueAxisDim: valueAxisDim,
  31751. baseAxisDim: baseAxisDim,
  31752. stacked: !!stacked,
  31753. valueDim: valueDim,
  31754. baseDim: baseDim,
  31755. baseDataOffset: baseDataOffset,
  31756. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  31757. };
  31758. }
  31759. function getValueStart(valueAxis, valueOrigin) {
  31760. var valueStart = 0;
  31761. var extent = valueAxis.scale.getExtent();
  31762. if (valueOrigin === 'start') {
  31763. valueStart = extent[0];
  31764. }
  31765. else if (valueOrigin === 'end') {
  31766. valueStart = extent[1];
  31767. }
  31768. // auto
  31769. else {
  31770. // Both positive
  31771. if (extent[0] > 0) {
  31772. valueStart = extent[0];
  31773. }
  31774. // Both negative
  31775. else if (extent[1] < 0) {
  31776. valueStart = extent[1];
  31777. }
  31778. // If is one positive, and one negative, onZero shall be true
  31779. }
  31780. return valueStart;
  31781. }
  31782. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  31783. var value = NaN;
  31784. if (dataCoordInfo.stacked) {
  31785. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  31786. }
  31787. if (isNaN(value)) {
  31788. value = dataCoordInfo.valueStart;
  31789. }
  31790. var baseDataOffset = dataCoordInfo.baseDataOffset;
  31791. var stackedData = [];
  31792. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  31793. stackedData[1 - baseDataOffset] = value;
  31794. return coordSys.dataToPoint(stackedData);
  31795. }
  31796. /*
  31797. * Licensed to the Apache Software Foundation (ASF) under one
  31798. * or more contributor license agreements. See the NOTICE file
  31799. * distributed with this work for additional information
  31800. * regarding copyright ownership. The ASF licenses this file
  31801. * to you under the Apache License, Version 2.0 (the
  31802. * "License"); you may not use this file except in compliance
  31803. * with the License. You may obtain a copy of the License at
  31804. *
  31805. * http://www.apache.org/licenses/LICENSE-2.0
  31806. *
  31807. * Unless required by applicable law or agreed to in writing,
  31808. * software distributed under the License is distributed on an
  31809. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31810. * KIND, either express or implied. See the License for the
  31811. * specific language governing permissions and limitations
  31812. * under the License.
  31813. */
  31814. // var arrayDiff = require('zrender/src/core/arrayDiff');
  31815. // 'zrender/src/core/arrayDiff' has been used before, but it did
  31816. // not do well in performance when roam with fixed dataZoom window.
  31817. // function convertToIntId(newIdList, oldIdList) {
  31818. // // Generate int id instead of string id.
  31819. // // Compare string maybe slow in score function of arrDiff
  31820. // // Assume id in idList are all unique
  31821. // var idIndicesMap = {};
  31822. // var idx = 0;
  31823. // for (var i = 0; i < newIdList.length; i++) {
  31824. // idIndicesMap[newIdList[i]] = idx;
  31825. // newIdList[i] = idx++;
  31826. // }
  31827. // for (var i = 0; i < oldIdList.length; i++) {
  31828. // var oldId = oldIdList[i];
  31829. // // Same with newIdList
  31830. // if (idIndicesMap[oldId]) {
  31831. // oldIdList[i] = idIndicesMap[oldId];
  31832. // }
  31833. // else {
  31834. // oldIdList[i] = idx++;
  31835. // }
  31836. // }
  31837. // }
  31838. function diffData(oldData, newData) {
  31839. var diffResult = [];
  31840. newData.diff(oldData)
  31841. .add(function (idx) {
  31842. diffResult.push({cmd: '+', idx: idx});
  31843. })
  31844. .update(function (newIdx, oldIdx) {
  31845. diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
  31846. })
  31847. .remove(function (idx) {
  31848. diffResult.push({cmd: '-', idx: idx});
  31849. })
  31850. .execute();
  31851. return diffResult;
  31852. }
  31853. var lineAnimationDiff = function (
  31854. oldData, newData,
  31855. oldStackedOnPoints, newStackedOnPoints,
  31856. oldCoordSys, newCoordSys,
  31857. oldValueOrigin, newValueOrigin
  31858. ) {
  31859. var diff = diffData(oldData, newData);
  31860. // var newIdList = newData.mapArray(newData.getId);
  31861. // var oldIdList = oldData.mapArray(oldData.getId);
  31862. // convertToIntId(newIdList, oldIdList);
  31863. // // FIXME One data ?
  31864. // diff = arrayDiff(oldIdList, newIdList);
  31865. var currPoints = [];
  31866. var nextPoints = [];
  31867. // Points for stacking base line
  31868. var currStackedPoints = [];
  31869. var nextStackedPoints = [];
  31870. var status = [];
  31871. var sortedIndices = [];
  31872. var rawIndices = [];
  31873. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
  31874. var oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  31875. for (var i = 0; i < diff.length; i++) {
  31876. var diffItem = diff[i];
  31877. var pointAdded = true;
  31878. // FIXME, animation is not so perfect when dataZoom window moves fast
  31879. // Which is in case remvoing or add more than one data in the tail or head
  31880. switch (diffItem.cmd) {
  31881. case '=':
  31882. var currentPt = oldData.getItemLayout(diffItem.idx);
  31883. var nextPt = newData.getItemLayout(diffItem.idx1);
  31884. // If previous data is NaN, use next point directly
  31885. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  31886. currentPt = nextPt.slice();
  31887. }
  31888. currPoints.push(currentPt);
  31889. nextPoints.push(nextPt);
  31890. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  31891. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  31892. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  31893. break;
  31894. case '+':
  31895. var idx = diffItem.idx;
  31896. currPoints.push(
  31897. oldCoordSys.dataToPoint([
  31898. newData.get(newDataOldCoordInfo.dataDimsForPoint[0], idx),
  31899. newData.get(newDataOldCoordInfo.dataDimsForPoint[1], idx)
  31900. ])
  31901. );
  31902. nextPoints.push(newData.getItemLayout(idx).slice());
  31903. currStackedPoints.push(
  31904. getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, idx)
  31905. );
  31906. nextStackedPoints.push(newStackedOnPoints[idx]);
  31907. rawIndices.push(newData.getRawIndex(idx));
  31908. break;
  31909. case '-':
  31910. var idx = diffItem.idx;
  31911. var rawIndex = oldData.getRawIndex(idx);
  31912. // Data is replaced. In the case of dynamic data queue
  31913. // FIXME FIXME FIXME
  31914. if (rawIndex !== idx) {
  31915. currPoints.push(oldData.getItemLayout(idx));
  31916. nextPoints.push(newCoordSys.dataToPoint([
  31917. oldData.get(oldDataNewCoordInfo.dataDimsForPoint[0], idx),
  31918. oldData.get(oldDataNewCoordInfo.dataDimsForPoint[1], idx)
  31919. ]));
  31920. currStackedPoints.push(oldStackedOnPoints[idx]);
  31921. nextStackedPoints.push(
  31922. getStackedOnPoint(oldDataNewCoordInfo, newCoordSys, oldData, idx)
  31923. );
  31924. rawIndices.push(rawIndex);
  31925. }
  31926. else {
  31927. pointAdded = false;
  31928. }
  31929. }
  31930. // Original indices
  31931. if (pointAdded) {
  31932. status.push(diffItem);
  31933. sortedIndices.push(sortedIndices.length);
  31934. }
  31935. }
  31936. // Diff result may be crossed if all items are changed
  31937. // Sort by data index
  31938. sortedIndices.sort(function (a, b) {
  31939. return rawIndices[a] - rawIndices[b];
  31940. });
  31941. var sortedCurrPoints = [];
  31942. var sortedNextPoints = [];
  31943. var sortedCurrStackedPoints = [];
  31944. var sortedNextStackedPoints = [];
  31945. var sortedStatus = [];
  31946. for (var i = 0; i < sortedIndices.length; i++) {
  31947. var idx = sortedIndices[i];
  31948. sortedCurrPoints[i] = currPoints[idx];
  31949. sortedNextPoints[i] = nextPoints[idx];
  31950. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  31951. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  31952. sortedStatus[i] = status[idx];
  31953. }
  31954. return {
  31955. current: sortedCurrPoints,
  31956. next: sortedNextPoints,
  31957. stackedOnCurrent: sortedCurrStackedPoints,
  31958. stackedOnNext: sortedNextStackedPoints,
  31959. status: sortedStatus
  31960. };
  31961. };
  31962. /*
  31963. * Licensed to the Apache Software Foundation (ASF) under one
  31964. * or more contributor license agreements. See the NOTICE file
  31965. * distributed with this work for additional information
  31966. * regarding copyright ownership. The ASF licenses this file
  31967. * to you under the Apache License, Version 2.0 (the
  31968. * "License"); you may not use this file except in compliance
  31969. * with the License. You may obtain a copy of the License at
  31970. *
  31971. * http://www.apache.org/licenses/LICENSE-2.0
  31972. *
  31973. * Unless required by applicable law or agreed to in writing,
  31974. * software distributed under the License is distributed on an
  31975. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31976. * KIND, either express or implied. See the License for the
  31977. * specific language governing permissions and limitations
  31978. * under the License.
  31979. */
  31980. // Poly path support NaN point
  31981. var vec2Min = min;
  31982. var vec2Max = max;
  31983. var scaleAndAdd$1 = scaleAndAdd;
  31984. var v2Copy = copy;
  31985. // Temporary variable
  31986. var v = [];
  31987. var cp0 = [];
  31988. var cp1 = [];
  31989. function isPointNull(p) {
  31990. return isNaN(p[0]) || isNaN(p[1]);
  31991. }
  31992. function drawSegment(
  31993. ctx, points, start, segLen, allLen,
  31994. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  31995. ) {
  31996. // if (smoothMonotone == null) {
  31997. // if (isMono(points, 'x')) {
  31998. // return drawMono(ctx, points, start, segLen, allLen,
  31999. // dir, smoothMin, smoothMax, smooth, 'x', connectNulls);
  32000. // }
  32001. // else if (isMono(points, 'y')) {
  32002. // return drawMono(ctx, points, start, segLen, allLen,
  32003. // dir, smoothMin, smoothMax, smooth, 'y', connectNulls);
  32004. // }
  32005. // else {
  32006. // return drawNonMono.apply(this, arguments);
  32007. // }
  32008. // }
  32009. // else if (smoothMonotone !== 'none' && isMono(points, smoothMonotone)) {
  32010. // return drawMono.apply(this, arguments);
  32011. // }
  32012. // else {
  32013. // return drawNonMono.apply(this, arguments);
  32014. // }
  32015. if (smoothMonotone === 'none' || !smoothMonotone) {
  32016. return drawNonMono.apply(this, arguments);
  32017. }
  32018. else {
  32019. return drawMono.apply(this, arguments);
  32020. }
  32021. }
  32022. /**
  32023. * Check if points is in monotone.
  32024. *
  32025. * @param {number[][]} points Array of points which is in [x, y] form
  32026. * @param {string} smoothMonotone 'x', 'y', or 'none', stating for which
  32027. * dimension that is checking.
  32028. * If is 'none', `drawNonMono` should be
  32029. * called.
  32030. * If is undefined, either being monotone
  32031. * in 'x' or 'y' will call `drawMono`.
  32032. */
  32033. // function isMono(points, smoothMonotone) {
  32034. // if (points.length <= 1) {
  32035. // return true;
  32036. // }
  32037. // var dim = smoothMonotone === 'x' ? 0 : 1;
  32038. // var last = points[0][dim];
  32039. // var lastDiff = 0;
  32040. // for (var i = 1; i < points.length; ++i) {
  32041. // var diff = points[i][dim] - last;
  32042. // if (!isNaN(diff) && !isNaN(lastDiff)
  32043. // && diff !== 0 && lastDiff !== 0
  32044. // && ((diff >= 0) !== (lastDiff >= 0))
  32045. // ) {
  32046. // return false;
  32047. // }
  32048. // if (!isNaN(diff) && diff !== 0) {
  32049. // lastDiff = diff;
  32050. // last = points[i][dim];
  32051. // }
  32052. // }
  32053. // return true;
  32054. // }
  32055. /**
  32056. * Draw smoothed line in monotone, in which only vertical or horizontal bezier
  32057. * control points will be used. This should be used when points are monotone
  32058. * either in x or y dimension.
  32059. */
  32060. function drawMono(
  32061. ctx, points, start, segLen, allLen,
  32062. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  32063. ) {
  32064. var prevIdx = 0;
  32065. var idx = start;
  32066. for (var k = 0; k < segLen; k++) {
  32067. var p = points[idx];
  32068. if (idx >= allLen || idx < 0) {
  32069. break;
  32070. }
  32071. if (isPointNull(p)) {
  32072. if (connectNulls) {
  32073. idx += dir;
  32074. continue;
  32075. }
  32076. break;
  32077. }
  32078. if (idx === start) {
  32079. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  32080. }
  32081. else {
  32082. if (smooth > 0) {
  32083. var prevP = points[prevIdx];
  32084. var dim = smoothMonotone === 'y' ? 1 : 0;
  32085. // Length of control point to p, either in x or y, but not both
  32086. var ctrlLen = (p[dim] - prevP[dim]) * smooth;
  32087. v2Copy(cp0, prevP);
  32088. cp0[dim] = prevP[dim] + ctrlLen;
  32089. v2Copy(cp1, p);
  32090. cp1[dim] = p[dim] - ctrlLen;
  32091. ctx.bezierCurveTo(
  32092. cp0[0], cp0[1],
  32093. cp1[0], cp1[1],
  32094. p[0], p[1]
  32095. );
  32096. }
  32097. else {
  32098. ctx.lineTo(p[0], p[1]);
  32099. }
  32100. }
  32101. prevIdx = idx;
  32102. idx += dir;
  32103. }
  32104. return k;
  32105. }
  32106. /**
  32107. * Draw smoothed line in non-monotone, in may cause undesired curve in extreme
  32108. * situations. This should be used when points are non-monotone neither in x or
  32109. * y dimension.
  32110. */
  32111. function drawNonMono(
  32112. ctx, points, start, segLen, allLen,
  32113. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  32114. ) {
  32115. var prevIdx = 0;
  32116. var idx = start;
  32117. for (var k = 0; k < segLen; k++) {
  32118. var p = points[idx];
  32119. if (idx >= allLen || idx < 0) {
  32120. break;
  32121. }
  32122. if (isPointNull(p)) {
  32123. if (connectNulls) {
  32124. idx += dir;
  32125. continue;
  32126. }
  32127. break;
  32128. }
  32129. if (idx === start) {
  32130. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  32131. v2Copy(cp0, p);
  32132. }
  32133. else {
  32134. if (smooth > 0) {
  32135. var nextIdx = idx + dir;
  32136. var nextP = points[nextIdx];
  32137. if (connectNulls) {
  32138. // Find next point not null
  32139. while (nextP && isPointNull(points[nextIdx])) {
  32140. nextIdx += dir;
  32141. nextP = points[nextIdx];
  32142. }
  32143. }
  32144. var ratioNextSeg = 0.5;
  32145. var prevP = points[prevIdx];
  32146. var nextP = points[nextIdx];
  32147. // Last point
  32148. if (!nextP || isPointNull(nextP)) {
  32149. v2Copy(cp1, p);
  32150. }
  32151. else {
  32152. // If next data is null in not connect case
  32153. if (isPointNull(nextP) && !connectNulls) {
  32154. nextP = p;
  32155. }
  32156. sub(v, nextP, prevP);
  32157. var lenPrevSeg;
  32158. var lenNextSeg;
  32159. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  32160. var dim = smoothMonotone === 'x' ? 0 : 1;
  32161. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  32162. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  32163. }
  32164. else {
  32165. lenPrevSeg = dist(p, prevP);
  32166. lenNextSeg = dist(p, nextP);
  32167. }
  32168. // Use ratio of seg length
  32169. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  32170. scaleAndAdd$1(cp1, p, v, -smooth * (1 - ratioNextSeg));
  32171. }
  32172. // Smooth constraint
  32173. vec2Min(cp0, cp0, smoothMax);
  32174. vec2Max(cp0, cp0, smoothMin);
  32175. vec2Min(cp1, cp1, smoothMax);
  32176. vec2Max(cp1, cp1, smoothMin);
  32177. ctx.bezierCurveTo(
  32178. cp0[0], cp0[1],
  32179. cp1[0], cp1[1],
  32180. p[0], p[1]
  32181. );
  32182. // cp0 of next segment
  32183. scaleAndAdd$1(cp0, p, v, smooth * ratioNextSeg);
  32184. }
  32185. else {
  32186. ctx.lineTo(p[0], p[1]);
  32187. }
  32188. }
  32189. prevIdx = idx;
  32190. idx += dir;
  32191. }
  32192. return k;
  32193. }
  32194. function getBoundingBox(points, smoothConstraint) {
  32195. var ptMin = [Infinity, Infinity];
  32196. var ptMax = [-Infinity, -Infinity];
  32197. if (smoothConstraint) {
  32198. for (var i = 0; i < points.length; i++) {
  32199. var pt = points[i];
  32200. if (pt[0] < ptMin[0]) {
  32201. ptMin[0] = pt[0];
  32202. }
  32203. if (pt[1] < ptMin[1]) {
  32204. ptMin[1] = pt[1];
  32205. }
  32206. if (pt[0] > ptMax[0]) {
  32207. ptMax[0] = pt[0];
  32208. }
  32209. if (pt[1] > ptMax[1]) {
  32210. ptMax[1] = pt[1];
  32211. }
  32212. }
  32213. }
  32214. return {
  32215. min: smoothConstraint ? ptMin : ptMax,
  32216. max: smoothConstraint ? ptMax : ptMin
  32217. };
  32218. }
  32219. var Polyline$1 = Path.extend({
  32220. type: 'ec-polyline',
  32221. shape: {
  32222. points: [],
  32223. smooth: 0,
  32224. smoothConstraint: true,
  32225. smoothMonotone: null,
  32226. connectNulls: false
  32227. },
  32228. style: {
  32229. fill: null,
  32230. stroke: '#000'
  32231. },
  32232. brush: fixClipWithShadow(Path.prototype.brush),
  32233. buildPath: function (ctx, shape) {
  32234. var points = shape.points;
  32235. var i = 0;
  32236. var len$$1 = points.length;
  32237. var result = getBoundingBox(points, shape.smoothConstraint);
  32238. if (shape.connectNulls) {
  32239. // Must remove first and last null values avoid draw error in polygon
  32240. for (; len$$1 > 0; len$$1--) {
  32241. if (!isPointNull(points[len$$1 - 1])) {
  32242. break;
  32243. }
  32244. }
  32245. for (; i < len$$1; i++) {
  32246. if (!isPointNull(points[i])) {
  32247. break;
  32248. }
  32249. }
  32250. }
  32251. while (i < len$$1) {
  32252. i += drawSegment(
  32253. ctx, points, i, len$$1, len$$1,
  32254. 1, result.min, result.max, shape.smooth,
  32255. shape.smoothMonotone, shape.connectNulls
  32256. ) + 1;
  32257. }
  32258. }
  32259. });
  32260. var Polygon$1 = Path.extend({
  32261. type: 'ec-polygon',
  32262. shape: {
  32263. points: [],
  32264. // Offset between stacked base points and points
  32265. stackedOnPoints: [],
  32266. smooth: 0,
  32267. stackedOnSmooth: 0,
  32268. smoothConstraint: true,
  32269. smoothMonotone: null,
  32270. connectNulls: false
  32271. },
  32272. brush: fixClipWithShadow(Path.prototype.brush),
  32273. buildPath: function (ctx, shape) {
  32274. var points = shape.points;
  32275. var stackedOnPoints = shape.stackedOnPoints;
  32276. var i = 0;
  32277. var len$$1 = points.length;
  32278. var smoothMonotone = shape.smoothMonotone;
  32279. var bbox = getBoundingBox(points, shape.smoothConstraint);
  32280. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  32281. if (shape.connectNulls) {
  32282. // Must remove first and last null values avoid draw error in polygon
  32283. for (; len$$1 > 0; len$$1--) {
  32284. if (!isPointNull(points[len$$1 - 1])) {
  32285. break;
  32286. }
  32287. }
  32288. for (; i < len$$1; i++) {
  32289. if (!isPointNull(points[i])) {
  32290. break;
  32291. }
  32292. }
  32293. }
  32294. while (i < len$$1) {
  32295. var k = drawSegment(
  32296. ctx, points, i, len$$1, len$$1,
  32297. 1, bbox.min, bbox.max, shape.smooth,
  32298. smoothMonotone, shape.connectNulls
  32299. );
  32300. drawSegment(
  32301. ctx, stackedOnPoints, i + k - 1, k, len$$1,
  32302. -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth,
  32303. smoothMonotone, shape.connectNulls
  32304. );
  32305. i += k + 1;
  32306. ctx.closePath();
  32307. }
  32308. }
  32309. });
  32310. /*
  32311. * Licensed to the Apache Software Foundation (ASF) under one
  32312. * or more contributor license agreements. See the NOTICE file
  32313. * distributed with this work for additional information
  32314. * regarding copyright ownership. The ASF licenses this file
  32315. * to you under the Apache License, Version 2.0 (the
  32316. * "License"); you may not use this file except in compliance
  32317. * with the License. You may obtain a copy of the License at
  32318. *
  32319. * http://www.apache.org/licenses/LICENSE-2.0
  32320. *
  32321. * Unless required by applicable law or agreed to in writing,
  32322. * software distributed under the License is distributed on an
  32323. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32324. * KIND, either express or implied. See the License for the
  32325. * specific language governing permissions and limitations
  32326. * under the License.
  32327. */
  32328. // FIXME step not support polar
  32329. function isPointsSame(points1, points2) {
  32330. if (points1.length !== points2.length) {
  32331. return;
  32332. }
  32333. for (var i = 0; i < points1.length; i++) {
  32334. var p1 = points1[i];
  32335. var p2 = points2[i];
  32336. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  32337. return;
  32338. }
  32339. }
  32340. return true;
  32341. }
  32342. function getSmooth(smooth) {
  32343. return typeof (smooth) === 'number' ? smooth : (smooth ? 0.5 : 0);
  32344. }
  32345. function getAxisExtentWithGap(axis) {
  32346. var extent = axis.getGlobalExtent();
  32347. if (axis.onBand) {
  32348. // Remove extra 1px to avoid line miter in clipped edge
  32349. var halfBandWidth = axis.getBandWidth() / 2 - 1;
  32350. var dir = extent[1] > extent[0] ? 1 : -1;
  32351. extent[0] += dir * halfBandWidth;
  32352. extent[1] -= dir * halfBandWidth;
  32353. }
  32354. return extent;
  32355. }
  32356. /**
  32357. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  32358. * @param {module:echarts/data/List} data
  32359. * @param {Object} dataCoordInfo
  32360. * @param {Array.<Array.<number>>} points
  32361. */
  32362. function getStackedOnPoints(coordSys, data, dataCoordInfo) {
  32363. if (!dataCoordInfo.valueDim) {
  32364. return [];
  32365. }
  32366. var points = [];
  32367. for (var idx = 0, len = data.count(); idx < len; idx++) {
  32368. points.push(getStackedOnPoint(dataCoordInfo, coordSys, data, idx));
  32369. }
  32370. return points;
  32371. }
  32372. function createGridClipShape(cartesian, hasAnimation, forSymbol, seriesModel) {
  32373. var xExtent = getAxisExtentWithGap(cartesian.getAxis('x'));
  32374. var yExtent = getAxisExtentWithGap(cartesian.getAxis('y'));
  32375. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  32376. var x = Math.min(xExtent[0], xExtent[1]);
  32377. var y = Math.min(yExtent[0], yExtent[1]);
  32378. var width = Math.max(xExtent[0], xExtent[1]) - x;
  32379. var height = Math.max(yExtent[0], yExtent[1]) - y;
  32380. // Avoid float number rounding error for symbol on the edge of axis extent.
  32381. // See #7913 and `test/dataZoom-clip.html`.
  32382. if (forSymbol) {
  32383. x -= 0.5;
  32384. width += 0.5;
  32385. y -= 0.5;
  32386. height += 0.5;
  32387. }
  32388. else {
  32389. var lineWidth = seriesModel.get('lineStyle.width') || 2;
  32390. // Expand clip shape to avoid clipping when line value exceeds axis
  32391. var expandSize = seriesModel.get('clipOverflow') ? lineWidth / 2 : Math.max(width, height);
  32392. if (isHorizontal) {
  32393. y -= expandSize;
  32394. height += expandSize * 2;
  32395. }
  32396. else {
  32397. x -= expandSize;
  32398. width += expandSize * 2;
  32399. }
  32400. }
  32401. var clipPath = new Rect({
  32402. shape: {
  32403. x: x,
  32404. y: y,
  32405. width: width,
  32406. height: height
  32407. }
  32408. });
  32409. if (hasAnimation) {
  32410. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  32411. initProps(clipPath, {
  32412. shape: {
  32413. width: width,
  32414. height: height
  32415. }
  32416. }, seriesModel);
  32417. }
  32418. return clipPath;
  32419. }
  32420. function createPolarClipShape(polar, hasAnimation, forSymbol, seriesModel) {
  32421. var angleAxis = polar.getAngleAxis();
  32422. var radiusAxis = polar.getRadiusAxis();
  32423. var radiusExtent = radiusAxis.getExtent().slice();
  32424. radiusExtent[0] > radiusExtent[1] && radiusExtent.reverse();
  32425. var angleExtent = angleAxis.getExtent();
  32426. var RADIAN = Math.PI / 180;
  32427. // Avoid float number rounding error for symbol on the edge of axis extent.
  32428. if (forSymbol) {
  32429. radiusExtent[0] -= 0.5;
  32430. radiusExtent[1] += 0.5;
  32431. }
  32432. var clipPath = new Sector({
  32433. shape: {
  32434. cx: round$2(polar.cx, 1),
  32435. cy: round$2(polar.cy, 1),
  32436. r0: round$2(radiusExtent[0], 1),
  32437. r: round$2(radiusExtent[1], 1),
  32438. startAngle: -angleExtent[0] * RADIAN,
  32439. endAngle: -angleExtent[1] * RADIAN,
  32440. clockwise: angleAxis.inverse
  32441. }
  32442. });
  32443. if (hasAnimation) {
  32444. clipPath.shape.endAngle = -angleExtent[0] * RADIAN;
  32445. initProps(clipPath, {
  32446. shape: {
  32447. endAngle: -angleExtent[1] * RADIAN
  32448. }
  32449. }, seriesModel);
  32450. }
  32451. return clipPath;
  32452. }
  32453. function createClipShape(coordSys, hasAnimation, forSymbol, seriesModel) {
  32454. return coordSys.type === 'polar'
  32455. ? createPolarClipShape(coordSys, hasAnimation, forSymbol, seriesModel)
  32456. : createGridClipShape(coordSys, hasAnimation, forSymbol, seriesModel);
  32457. }
  32458. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  32459. var baseAxis = coordSys.getBaseAxis();
  32460. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  32461. var stepPoints = [];
  32462. for (var i = 0; i < points.length - 1; i++) {
  32463. var nextPt = points[i + 1];
  32464. var pt = points[i];
  32465. stepPoints.push(pt);
  32466. var stepPt = [];
  32467. switch (stepTurnAt) {
  32468. case 'end':
  32469. stepPt[baseIndex] = nextPt[baseIndex];
  32470. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  32471. // default is start
  32472. stepPoints.push(stepPt);
  32473. break;
  32474. case 'middle':
  32475. // default is start
  32476. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  32477. var stepPt2 = [];
  32478. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  32479. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  32480. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  32481. stepPoints.push(stepPt);
  32482. stepPoints.push(stepPt2);
  32483. break;
  32484. default:
  32485. stepPt[baseIndex] = pt[baseIndex];
  32486. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  32487. // default is start
  32488. stepPoints.push(stepPt);
  32489. }
  32490. }
  32491. // Last points
  32492. points[i] && stepPoints.push(points[i]);
  32493. return stepPoints;
  32494. }
  32495. function getVisualGradient(data, coordSys) {
  32496. var visualMetaList = data.getVisual('visualMeta');
  32497. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  32498. // When data.count() is 0, gradient range can not be calculated.
  32499. return;
  32500. }
  32501. if (coordSys.type !== 'cartesian2d') {
  32502. if (__DEV__) {
  32503. console.warn('Visual map on line style is only supported on cartesian2d.');
  32504. }
  32505. return;
  32506. }
  32507. var coordDim;
  32508. var visualMeta;
  32509. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  32510. var dimIndex = visualMetaList[i].dimension;
  32511. var dimName = data.dimensions[dimIndex];
  32512. var dimInfo = data.getDimensionInfo(dimName);
  32513. coordDim = dimInfo && dimInfo.coordDim;
  32514. // Can only be x or y
  32515. if (coordDim === 'x' || coordDim === 'y') {
  32516. visualMeta = visualMetaList[i];
  32517. break;
  32518. }
  32519. }
  32520. if (!visualMeta) {
  32521. if (__DEV__) {
  32522. console.warn('Visual map on line style only support x or y dimension.');
  32523. }
  32524. return;
  32525. }
  32526. // If the area to be rendered is bigger than area defined by LinearGradient,
  32527. // the canvas spec prescribes that the color of the first stop and the last
  32528. // stop should be used. But if two stops are added at offset 0, in effect
  32529. // browsers use the color of the second stop to render area outside
  32530. // LinearGradient. So we can only infinitesimally extend area defined in
  32531. // LinearGradient to render `outerColors`.
  32532. var axis = coordSys.getAxis(coordDim);
  32533. // dataToCoor mapping may not be linear, but must be monotonic.
  32534. var colorStops = map(visualMeta.stops, function (stop) {
  32535. return {
  32536. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  32537. color: stop.color
  32538. };
  32539. });
  32540. var stopLen = colorStops.length;
  32541. var outerColors = visualMeta.outerColors.slice();
  32542. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  32543. colorStops.reverse();
  32544. outerColors.reverse();
  32545. }
  32546. var tinyExtent = 10; // Arbitrary value: 10px
  32547. var minCoord = colorStops[0].coord - tinyExtent;
  32548. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  32549. var coordSpan = maxCoord - minCoord;
  32550. if (coordSpan < 1e-3) {
  32551. return 'transparent';
  32552. }
  32553. each$1(colorStops, function (stop) {
  32554. stop.offset = (stop.coord - minCoord) / coordSpan;
  32555. });
  32556. colorStops.push({
  32557. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  32558. color: outerColors[1] || 'transparent'
  32559. });
  32560. colorStops.unshift({ // notice colorStops.length have been changed.
  32561. offset: stopLen ? colorStops[0].offset : 0.5,
  32562. color: outerColors[0] || 'transparent'
  32563. });
  32564. // zrUtil.each(colorStops, function (colorStop) {
  32565. // // Make sure each offset has rounded px to avoid not sharp edge
  32566. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  32567. // });
  32568. var gradient = new LinearGradient(0, 0, 0, 0, colorStops, true);
  32569. gradient[coordDim] = minCoord;
  32570. gradient[coordDim + '2'] = maxCoord;
  32571. return gradient;
  32572. }
  32573. function getIsIgnoreFunc(seriesModel, data, coordSys) {
  32574. var showAllSymbol = seriesModel.get('showAllSymbol');
  32575. var isAuto = showAllSymbol === 'auto';
  32576. if (showAllSymbol && !isAuto) {
  32577. return;
  32578. }
  32579. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  32580. if (!categoryAxis) {
  32581. return;
  32582. }
  32583. // Note that category label interval strategy might bring some weird effect
  32584. // in some scenario: users may wonder why some of the symbols are not
  32585. // displayed. So we show all symbols as possible as we can.
  32586. if (isAuto
  32587. // Simplify the logic, do not determine label overlap here.
  32588. && canShowAllSymbolForCategory(categoryAxis, data)
  32589. ) {
  32590. return;
  32591. }
  32592. // Otherwise follow the label interval strategy on category axis.
  32593. var categoryDataDim = data.mapDimension(categoryAxis.dim);
  32594. var labelMap = {};
  32595. each$1(categoryAxis.getViewLabels(), function (labelItem) {
  32596. labelMap[labelItem.tickValue] = 1;
  32597. });
  32598. return function (dataIndex) {
  32599. return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
  32600. };
  32601. }
  32602. function canShowAllSymbolForCategory(categoryAxis, data) {
  32603. // In mose cases, line is monotonous on category axis, and the label size
  32604. // is close with each other. So we check the symbol size and some of the
  32605. // label size alone with the category axis to estimate whether all symbol
  32606. // can be shown without overlap.
  32607. var axisExtent = categoryAxis.getExtent();
  32608. var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
  32609. isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
  32610. // Sampling some points, max 5.
  32611. var dataLen = data.count();
  32612. var step = Math.max(1, Math.round(dataLen / 5));
  32613. for (var dataIndex = 0; dataIndex < dataLen; dataIndex += step) {
  32614. if (SymbolClz$1.getSymbolSize(
  32615. data, dataIndex
  32616. // Only for cartesian, where `isHorizontal` exists.
  32617. )[categoryAxis.isHorizontal() ? 1 : 0]
  32618. // Empirical number
  32619. * 1.5 > availSize
  32620. ) {
  32621. return false;
  32622. }
  32623. }
  32624. return true;
  32625. }
  32626. Chart.extend({
  32627. type: 'line',
  32628. init: function () {
  32629. var lineGroup = new Group();
  32630. var symbolDraw = new SymbolDraw();
  32631. this.group.add(symbolDraw.group);
  32632. this._symbolDraw = symbolDraw;
  32633. this._lineGroup = lineGroup;
  32634. },
  32635. render: function (seriesModel, ecModel, api) {
  32636. var coordSys = seriesModel.coordinateSystem;
  32637. var group = this.group;
  32638. var data = seriesModel.getData();
  32639. var lineStyleModel = seriesModel.getModel('lineStyle');
  32640. var areaStyleModel = seriesModel.getModel('areaStyle');
  32641. var points = data.mapArray(data.getItemLayout);
  32642. var isCoordSysPolar = coordSys.type === 'polar';
  32643. var prevCoordSys = this._coordSys;
  32644. var symbolDraw = this._symbolDraw;
  32645. var polyline = this._polyline;
  32646. var polygon = this._polygon;
  32647. var lineGroup = this._lineGroup;
  32648. var hasAnimation = seriesModel.get('animation');
  32649. var isAreaChart = !areaStyleModel.isEmpty();
  32650. var valueOrigin = areaStyleModel.get('origin');
  32651. var dataCoordInfo = prepareDataCoordInfo(coordSys, data, valueOrigin);
  32652. var stackedOnPoints = getStackedOnPoints(coordSys, data, dataCoordInfo);
  32653. var showSymbol = seriesModel.get('showSymbol');
  32654. var isIgnoreFunc = showSymbol && !isCoordSysPolar
  32655. && getIsIgnoreFunc(seriesModel, data, coordSys);
  32656. // Remove temporary symbols
  32657. var oldData = this._data;
  32658. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  32659. if (el.__temp) {
  32660. group.remove(el);
  32661. oldData.setItemGraphicEl(idx, null);
  32662. }
  32663. });
  32664. // Remove previous created symbols if showSymbol changed to false
  32665. if (!showSymbol) {
  32666. symbolDraw.remove();
  32667. }
  32668. group.add(lineGroup);
  32669. // FIXME step not support polar
  32670. var step = !isCoordSysPolar && seriesModel.get('step');
  32671. // Initialization animation or coordinate system changed
  32672. if (
  32673. !(polyline && prevCoordSys.type === coordSys.type && step === this._step)
  32674. ) {
  32675. showSymbol && symbolDraw.updateData(data, {
  32676. isIgnore: isIgnoreFunc,
  32677. clipShape: createClipShape(coordSys, false, true, seriesModel)
  32678. });
  32679. if (step) {
  32680. // TODO If stacked series is not step
  32681. points = turnPointsIntoStep(points, coordSys, step);
  32682. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  32683. }
  32684. polyline = this._newPolyline(points, coordSys, hasAnimation);
  32685. if (isAreaChart) {
  32686. polygon = this._newPolygon(
  32687. points, stackedOnPoints,
  32688. coordSys, hasAnimation
  32689. );
  32690. }
  32691. lineGroup.setClipPath(createClipShape(coordSys, true, false, seriesModel));
  32692. }
  32693. else {
  32694. if (isAreaChart && !polygon) {
  32695. // If areaStyle is added
  32696. polygon = this._newPolygon(
  32697. points, stackedOnPoints,
  32698. coordSys, hasAnimation
  32699. );
  32700. }
  32701. else if (polygon && !isAreaChart) {
  32702. // If areaStyle is removed
  32703. lineGroup.remove(polygon);
  32704. polygon = this._polygon = null;
  32705. }
  32706. // Update clipPath
  32707. lineGroup.setClipPath(createClipShape(coordSys, false, false, seriesModel));
  32708. // Always update, or it is wrong in the case turning on legend
  32709. // because points are not changed
  32710. showSymbol && symbolDraw.updateData(data, {
  32711. isIgnore: isIgnoreFunc,
  32712. clipShape: createClipShape(coordSys, false, true, seriesModel)
  32713. });
  32714. // Stop symbol animation and sync with line points
  32715. // FIXME performance?
  32716. data.eachItemGraphicEl(function (el) {
  32717. el.stopAnimation(true);
  32718. });
  32719. // In the case data zoom triggerred refreshing frequently
  32720. // Data may not change if line has a category axis. So it should animate nothing
  32721. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints)
  32722. || !isPointsSame(this._points, points)
  32723. ) {
  32724. if (hasAnimation) {
  32725. this._updateAnimation(
  32726. data, stackedOnPoints, coordSys, api, step, valueOrigin
  32727. );
  32728. }
  32729. else {
  32730. // Not do it in update with animation
  32731. if (step) {
  32732. // TODO If stacked series is not step
  32733. points = turnPointsIntoStep(points, coordSys, step);
  32734. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  32735. }
  32736. polyline.setShape({
  32737. points: points
  32738. });
  32739. polygon && polygon.setShape({
  32740. points: points,
  32741. stackedOnPoints: stackedOnPoints
  32742. });
  32743. }
  32744. }
  32745. }
  32746. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  32747. polyline.useStyle(defaults(
  32748. // Use color in lineStyle first
  32749. lineStyleModel.getLineStyle(),
  32750. {
  32751. fill: 'none',
  32752. stroke: visualColor,
  32753. lineJoin: 'bevel'
  32754. }
  32755. ));
  32756. var smooth = seriesModel.get('smooth');
  32757. smooth = getSmooth(seriesModel.get('smooth'));
  32758. polyline.setShape({
  32759. smooth: smooth,
  32760. smoothMonotone: seriesModel.get('smoothMonotone'),
  32761. connectNulls: seriesModel.get('connectNulls')
  32762. });
  32763. if (polygon) {
  32764. var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  32765. var stackedOnSmooth = 0;
  32766. polygon.useStyle(defaults(
  32767. areaStyleModel.getAreaStyle(),
  32768. {
  32769. fill: visualColor,
  32770. opacity: 0.7,
  32771. lineJoin: 'bevel'
  32772. }
  32773. ));
  32774. if (stackedOnSeries) {
  32775. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  32776. }
  32777. polygon.setShape({
  32778. smooth: smooth,
  32779. stackedOnSmooth: stackedOnSmooth,
  32780. smoothMonotone: seriesModel.get('smoothMonotone'),
  32781. connectNulls: seriesModel.get('connectNulls')
  32782. });
  32783. }
  32784. this._data = data;
  32785. // Save the coordinate system for transition animation when data changed
  32786. this._coordSys = coordSys;
  32787. this._stackedOnPoints = stackedOnPoints;
  32788. this._points = points;
  32789. this._step = step;
  32790. this._valueOrigin = valueOrigin;
  32791. },
  32792. dispose: function () {},
  32793. highlight: function (seriesModel, ecModel, api, payload) {
  32794. var data = seriesModel.getData();
  32795. var dataIndex = queryDataIndex(data, payload);
  32796. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  32797. var symbol = data.getItemGraphicEl(dataIndex);
  32798. if (!symbol) {
  32799. // Create a temporary symbol if it is not exists
  32800. var pt = data.getItemLayout(dataIndex);
  32801. if (!pt) {
  32802. // Null data
  32803. return;
  32804. }
  32805. symbol = new SymbolClz$1(data, dataIndex);
  32806. symbol.position = pt;
  32807. symbol.setZ(
  32808. seriesModel.get('zlevel'),
  32809. seriesModel.get('z')
  32810. );
  32811. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  32812. symbol.__temp = true;
  32813. data.setItemGraphicEl(dataIndex, symbol);
  32814. // Stop scale animation
  32815. symbol.stopSymbolAnimation(true);
  32816. this.group.add(symbol);
  32817. }
  32818. symbol.highlight();
  32819. }
  32820. else {
  32821. // Highlight whole series
  32822. Chart.prototype.highlight.call(
  32823. this, seriesModel, ecModel, api, payload
  32824. );
  32825. }
  32826. },
  32827. downplay: function (seriesModel, ecModel, api, payload) {
  32828. var data = seriesModel.getData();
  32829. var dataIndex = queryDataIndex(data, payload);
  32830. if (dataIndex != null && dataIndex >= 0) {
  32831. var symbol = data.getItemGraphicEl(dataIndex);
  32832. if (symbol) {
  32833. if (symbol.__temp) {
  32834. data.setItemGraphicEl(dataIndex, null);
  32835. this.group.remove(symbol);
  32836. }
  32837. else {
  32838. symbol.downplay();
  32839. }
  32840. }
  32841. }
  32842. else {
  32843. // FIXME
  32844. // can not downplay completely.
  32845. // Downplay whole series
  32846. Chart.prototype.downplay.call(
  32847. this, seriesModel, ecModel, api, payload
  32848. );
  32849. }
  32850. },
  32851. /**
  32852. * @param {module:zrender/container/Group} group
  32853. * @param {Array.<Array.<number>>} points
  32854. * @private
  32855. */
  32856. _newPolyline: function (points) {
  32857. var polyline = this._polyline;
  32858. // Remove previous created polyline
  32859. if (polyline) {
  32860. this._lineGroup.remove(polyline);
  32861. }
  32862. polyline = new Polyline$1({
  32863. shape: {
  32864. points: points
  32865. },
  32866. silent: true,
  32867. z2: 10
  32868. });
  32869. this._lineGroup.add(polyline);
  32870. this._polyline = polyline;
  32871. return polyline;
  32872. },
  32873. /**
  32874. * @param {module:zrender/container/Group} group
  32875. * @param {Array.<Array.<number>>} stackedOnPoints
  32876. * @param {Array.<Array.<number>>} points
  32877. * @private
  32878. */
  32879. _newPolygon: function (points, stackedOnPoints) {
  32880. var polygon = this._polygon;
  32881. // Remove previous created polygon
  32882. if (polygon) {
  32883. this._lineGroup.remove(polygon);
  32884. }
  32885. polygon = new Polygon$1({
  32886. shape: {
  32887. points: points,
  32888. stackedOnPoints: stackedOnPoints
  32889. },
  32890. silent: true
  32891. });
  32892. this._lineGroup.add(polygon);
  32893. this._polygon = polygon;
  32894. return polygon;
  32895. },
  32896. /**
  32897. * @private
  32898. */
  32899. // FIXME Two value axis
  32900. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step, valueOrigin) {
  32901. var polyline = this._polyline;
  32902. var polygon = this._polygon;
  32903. var seriesModel = data.hostModel;
  32904. var diff = lineAnimationDiff(
  32905. this._data, data,
  32906. this._stackedOnPoints, stackedOnPoints,
  32907. this._coordSys, coordSys,
  32908. this._valueOrigin, valueOrigin
  32909. );
  32910. var current = diff.current;
  32911. var stackedOnCurrent = diff.stackedOnCurrent;
  32912. var next = diff.next;
  32913. var stackedOnNext = diff.stackedOnNext;
  32914. if (step) {
  32915. // TODO If stacked series is not step
  32916. current = turnPointsIntoStep(diff.current, coordSys, step);
  32917. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  32918. next = turnPointsIntoStep(diff.next, coordSys, step);
  32919. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  32920. }
  32921. // `diff.current` is subset of `current` (which should be ensured by
  32922. // turnPointsIntoStep), so points in `__points` can be updated when
  32923. // points in `current` are update during animation.
  32924. polyline.shape.__points = diff.current;
  32925. polyline.shape.points = current;
  32926. updateProps(polyline, {
  32927. shape: {
  32928. points: next
  32929. }
  32930. }, seriesModel);
  32931. if (polygon) {
  32932. polygon.setShape({
  32933. points: current,
  32934. stackedOnPoints: stackedOnCurrent
  32935. });
  32936. updateProps(polygon, {
  32937. shape: {
  32938. points: next,
  32939. stackedOnPoints: stackedOnNext
  32940. }
  32941. }, seriesModel);
  32942. }
  32943. var updatedDataInfo = [];
  32944. var diffStatus = diff.status;
  32945. for (var i = 0; i < diffStatus.length; i++) {
  32946. var cmd = diffStatus[i].cmd;
  32947. if (cmd === '=') {
  32948. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  32949. if (el) {
  32950. updatedDataInfo.push({
  32951. el: el,
  32952. ptIdx: i // Index of points
  32953. });
  32954. }
  32955. }
  32956. }
  32957. if (polyline.animators && polyline.animators.length) {
  32958. polyline.animators[0].during(function () {
  32959. for (var i = 0; i < updatedDataInfo.length; i++) {
  32960. var el = updatedDataInfo[i].el;
  32961. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  32962. }
  32963. });
  32964. }
  32965. },
  32966. remove: function (ecModel) {
  32967. var group = this.group;
  32968. var oldData = this._data;
  32969. this._lineGroup.removeAll();
  32970. this._symbolDraw.remove(true);
  32971. // Remove temporary created elements when highlighting
  32972. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  32973. if (el.__temp) {
  32974. group.remove(el);
  32975. oldData.setItemGraphicEl(idx, null);
  32976. }
  32977. });
  32978. this._polyline
  32979. = this._polygon
  32980. = this._coordSys
  32981. = this._points
  32982. = this._stackedOnPoints
  32983. = this._data = null;
  32984. }
  32985. });
  32986. /*
  32987. * Licensed to the Apache Software Foundation (ASF) under one
  32988. * or more contributor license agreements. See the NOTICE file
  32989. * distributed with this work for additional information
  32990. * regarding copyright ownership. The ASF licenses this file
  32991. * to you under the Apache License, Version 2.0 (the
  32992. * "License"); you may not use this file except in compliance
  32993. * with the License. You may obtain a copy of the License at
  32994. *
  32995. * http://www.apache.org/licenses/LICENSE-2.0
  32996. *
  32997. * Unless required by applicable law or agreed to in writing,
  32998. * software distributed under the License is distributed on an
  32999. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33000. * KIND, either express or implied. See the License for the
  33001. * specific language governing permissions and limitations
  33002. * under the License.
  33003. */
  33004. var visualSymbol = function (seriesType, defaultSymbolType, legendSymbol) {
  33005. // Encoding visual for all series include which is filtered for legend drawing
  33006. return {
  33007. seriesType: seriesType,
  33008. // For legend.
  33009. performRawSeries: true,
  33010. reset: function (seriesModel, ecModel, api) {
  33011. var data = seriesModel.getData();
  33012. var symbolType = seriesModel.get('symbol') || defaultSymbolType;
  33013. var symbolSize = seriesModel.get('symbolSize');
  33014. var keepAspect = seriesModel.get('symbolKeepAspect');
  33015. data.setVisual({
  33016. legendSymbol: legendSymbol || symbolType,
  33017. symbol: symbolType,
  33018. symbolSize: symbolSize,
  33019. symbolKeepAspect: keepAspect
  33020. });
  33021. // Only visible series has each data be visual encoded
  33022. if (ecModel.isSeriesFiltered(seriesModel)) {
  33023. return;
  33024. }
  33025. var hasCallback = typeof symbolSize === 'function';
  33026. function dataEach(data, idx) {
  33027. if (typeof symbolSize === 'function') {
  33028. var rawValue = seriesModel.getRawValue(idx);
  33029. // FIXME
  33030. var params = seriesModel.getDataParams(idx);
  33031. data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  33032. }
  33033. if (data.hasItemOption) {
  33034. var itemModel = data.getItemModel(idx);
  33035. var itemSymbolType = itemModel.getShallow('symbol', true);
  33036. var itemSymbolSize = itemModel.getShallow('symbolSize',
  33037. true);
  33038. var itemSymbolKeepAspect
  33039. = itemModel.getShallow('symbolKeepAspect', true);
  33040. // If has item symbol
  33041. if (itemSymbolType != null) {
  33042. data.setItemVisual(idx, 'symbol', itemSymbolType);
  33043. }
  33044. if (itemSymbolSize != null) {
  33045. // PENDING Transform symbolSize ?
  33046. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  33047. }
  33048. if (itemSymbolKeepAspect != null) {
  33049. data.setItemVisual(idx, 'symbolKeepAspect',
  33050. itemSymbolKeepAspect);
  33051. }
  33052. }
  33053. }
  33054. return { dataEach: (data.hasItemOption || hasCallback) ? dataEach : null };
  33055. }
  33056. };
  33057. };
  33058. /*
  33059. * Licensed to the Apache Software Foundation (ASF) under one
  33060. * or more contributor license agreements. See the NOTICE file
  33061. * distributed with this work for additional information
  33062. * regarding copyright ownership. The ASF licenses this file
  33063. * to you under the Apache License, Version 2.0 (the
  33064. * "License"); you may not use this file except in compliance
  33065. * with the License. You may obtain a copy of the License at
  33066. *
  33067. * http://www.apache.org/licenses/LICENSE-2.0
  33068. *
  33069. * Unless required by applicable law or agreed to in writing,
  33070. * software distributed under the License is distributed on an
  33071. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33072. * KIND, either express or implied. See the License for the
  33073. * specific language governing permissions and limitations
  33074. * under the License.
  33075. */
  33076. /* global Float32Array */
  33077. var pointsLayout = function (seriesType) {
  33078. return {
  33079. seriesType: seriesType,
  33080. plan: createRenderPlanner(),
  33081. reset: function (seriesModel) {
  33082. var data = seriesModel.getData();
  33083. var coordSys = seriesModel.coordinateSystem;
  33084. var pipelineContext = seriesModel.pipelineContext;
  33085. var isLargeRender = pipelineContext.large;
  33086. if (!coordSys) {
  33087. return;
  33088. }
  33089. var dims = map(coordSys.dimensions, function (dim) {
  33090. return data.mapDimension(dim);
  33091. }).slice(0, 2);
  33092. var dimLen = dims.length;
  33093. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  33094. if (isDimensionStacked(data, dims[0] /*, dims[1]*/)) {
  33095. dims[0] = stackResultDim;
  33096. }
  33097. if (isDimensionStacked(data, dims[1] /*, dims[0]*/)) {
  33098. dims[1] = stackResultDim;
  33099. }
  33100. function progress(params, data) {
  33101. var segCount = params.end - params.start;
  33102. var points = isLargeRender && new Float32Array(segCount * dimLen);
  33103. for (var i = params.start, offset = 0, tmpIn = [], tmpOut = []; i < params.end; i++) {
  33104. var point;
  33105. if (dimLen === 1) {
  33106. var x = data.get(dims[0], i);
  33107. point = !isNaN(x) && coordSys.dataToPoint(x, null, tmpOut);
  33108. }
  33109. else {
  33110. var x = tmpIn[0] = data.get(dims[0], i);
  33111. var y = tmpIn[1] = data.get(dims[1], i);
  33112. // Also {Array.<number>}, not undefined to avoid if...else... statement
  33113. point = !isNaN(x) && !isNaN(y) && coordSys.dataToPoint(tmpIn, null, tmpOut);
  33114. }
  33115. if (isLargeRender) {
  33116. points[offset++] = point ? point[0] : NaN;
  33117. points[offset++] = point ? point[1] : NaN;
  33118. }
  33119. else {
  33120. data.setItemLayout(i, (point && point.slice()) || [NaN, NaN]);
  33121. }
  33122. }
  33123. isLargeRender && data.setLayout('symbolPoints', points);
  33124. }
  33125. return dimLen && {progress: progress};
  33126. }
  33127. };
  33128. };
  33129. /*
  33130. * Licensed to the Apache Software Foundation (ASF) under one
  33131. * or more contributor license agreements. See the NOTICE file
  33132. * distributed with this work for additional information
  33133. * regarding copyright ownership. The ASF licenses this file
  33134. * to you under the Apache License, Version 2.0 (the
  33135. * "License"); you may not use this file except in compliance
  33136. * with the License. You may obtain a copy of the License at
  33137. *
  33138. * http://www.apache.org/licenses/LICENSE-2.0
  33139. *
  33140. * Unless required by applicable law or agreed to in writing,
  33141. * software distributed under the License is distributed on an
  33142. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33143. * KIND, either express or implied. See the License for the
  33144. * specific language governing permissions and limitations
  33145. * under the License.
  33146. */
  33147. var samplers = {
  33148. average: function (frame) {
  33149. var sum = 0;
  33150. var count = 0;
  33151. for (var i = 0; i < frame.length; i++) {
  33152. if (!isNaN(frame[i])) {
  33153. sum += frame[i];
  33154. count++;
  33155. }
  33156. }
  33157. // Return NaN if count is 0
  33158. return count === 0 ? NaN : sum / count;
  33159. },
  33160. sum: function (frame) {
  33161. var sum = 0;
  33162. for (var i = 0; i < frame.length; i++) {
  33163. // Ignore NaN
  33164. sum += frame[i] || 0;
  33165. }
  33166. return sum;
  33167. },
  33168. max: function (frame) {
  33169. var max = -Infinity;
  33170. for (var i = 0; i < frame.length; i++) {
  33171. frame[i] > max && (max = frame[i]);
  33172. }
  33173. // NaN will cause illegal axis extent.
  33174. return isFinite(max) ? max : NaN;
  33175. },
  33176. min: function (frame) {
  33177. var min = Infinity;
  33178. for (var i = 0; i < frame.length; i++) {
  33179. frame[i] < min && (min = frame[i]);
  33180. }
  33181. // NaN will cause illegal axis extent.
  33182. return isFinite(min) ? min : NaN;
  33183. },
  33184. // TODO
  33185. // Median
  33186. nearest: function (frame) {
  33187. return frame[0];
  33188. }
  33189. };
  33190. var indexSampler = function (frame, value) {
  33191. return Math.round(frame.length / 2);
  33192. };
  33193. var dataSample = function (seriesType) {
  33194. return {
  33195. seriesType: seriesType,
  33196. modifyOutputEnd: true,
  33197. reset: function (seriesModel, ecModel, api) {
  33198. var data = seriesModel.getData();
  33199. var sampling = seriesModel.get('sampling');
  33200. var coordSys = seriesModel.coordinateSystem;
  33201. // Only cartesian2d support down sampling
  33202. if (coordSys.type === 'cartesian2d' && sampling) {
  33203. var baseAxis = coordSys.getBaseAxis();
  33204. var valueAxis = coordSys.getOtherAxis(baseAxis);
  33205. var extent = baseAxis.getExtent();
  33206. // Coordinste system has been resized
  33207. var size = extent[1] - extent[0];
  33208. var rate = Math.round(data.count() / size);
  33209. if (rate > 1) {
  33210. var sampler;
  33211. if (typeof sampling === 'string') {
  33212. sampler = samplers[sampling];
  33213. }
  33214. else if (typeof sampling === 'function') {
  33215. sampler = sampling;
  33216. }
  33217. if (sampler) {
  33218. // Only support sample the first dim mapped from value axis.
  33219. seriesModel.setData(data.downSample(
  33220. data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler
  33221. ));
  33222. }
  33223. }
  33224. }
  33225. }
  33226. };
  33227. };
  33228. /*
  33229. * Licensed to the Apache Software Foundation (ASF) under one
  33230. * or more contributor license agreements. See the NOTICE file
  33231. * distributed with this work for additional information
  33232. * regarding copyright ownership. The ASF licenses this file
  33233. * to you under the Apache License, Version 2.0 (the
  33234. * "License"); you may not use this file except in compliance
  33235. * with the License. You may obtain a copy of the License at
  33236. *
  33237. * http://www.apache.org/licenses/LICENSE-2.0
  33238. *
  33239. * Unless required by applicable law or agreed to in writing,
  33240. * software distributed under the License is distributed on an
  33241. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33242. * KIND, either express or implied. See the License for the
  33243. * specific language governing permissions and limitations
  33244. * under the License.
  33245. */
  33246. /**
  33247. * Cartesian coordinate system
  33248. * @module echarts/coord/Cartesian
  33249. *
  33250. */
  33251. function dimAxisMapper(dim) {
  33252. return this._axes[dim];
  33253. }
  33254. /**
  33255. * @alias module:echarts/coord/Cartesian
  33256. * @constructor
  33257. */
  33258. var Cartesian = function (name) {
  33259. this._axes = {};
  33260. this._dimList = [];
  33261. /**
  33262. * @type {string}
  33263. */
  33264. this.name = name || '';
  33265. };
  33266. Cartesian.prototype = {
  33267. constructor: Cartesian,
  33268. type: 'cartesian',
  33269. /**
  33270. * Get axis
  33271. * @param {number|string} dim
  33272. * @return {module:echarts/coord/Cartesian~Axis}
  33273. */
  33274. getAxis: function (dim) {
  33275. return this._axes[dim];
  33276. },
  33277. /**
  33278. * Get axes list
  33279. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  33280. */
  33281. getAxes: function () {
  33282. return map(this._dimList, dimAxisMapper, this);
  33283. },
  33284. /**
  33285. * Get axes list by given scale type
  33286. */
  33287. getAxesByScale: function (scaleType) {
  33288. scaleType = scaleType.toLowerCase();
  33289. return filter(
  33290. this.getAxes(),
  33291. function (axis) {
  33292. return axis.scale.type === scaleType;
  33293. }
  33294. );
  33295. },
  33296. /**
  33297. * Add axis
  33298. * @param {module:echarts/coord/Cartesian.Axis}
  33299. */
  33300. addAxis: function (axis) {
  33301. var dim = axis.dim;
  33302. this._axes[dim] = axis;
  33303. this._dimList.push(dim);
  33304. },
  33305. /**
  33306. * Convert data to coord in nd space
  33307. * @param {Array.<number>|Object.<string, number>} val
  33308. * @return {Array.<number>|Object.<string, number>}
  33309. */
  33310. dataToCoord: function (val) {
  33311. return this._dataCoordConvert(val, 'dataToCoord');
  33312. },
  33313. /**
  33314. * Convert coord in nd space to data
  33315. * @param {Array.<number>|Object.<string, number>} val
  33316. * @return {Array.<number>|Object.<string, number>}
  33317. */
  33318. coordToData: function (val) {
  33319. return this._dataCoordConvert(val, 'coordToData');
  33320. },
  33321. _dataCoordConvert: function (input, method) {
  33322. var dimList = this._dimList;
  33323. var output = input instanceof Array ? [] : {};
  33324. for (var i = 0; i < dimList.length; i++) {
  33325. var dim = dimList[i];
  33326. var axis = this._axes[dim];
  33327. output[dim] = axis[method](input[dim]);
  33328. }
  33329. return output;
  33330. }
  33331. };
  33332. /*
  33333. * Licensed to the Apache Software Foundation (ASF) under one
  33334. * or more contributor license agreements. See the NOTICE file
  33335. * distributed with this work for additional information
  33336. * regarding copyright ownership. The ASF licenses this file
  33337. * to you under the Apache License, Version 2.0 (the
  33338. * "License"); you may not use this file except in compliance
  33339. * with the License. You may obtain a copy of the License at
  33340. *
  33341. * http://www.apache.org/licenses/LICENSE-2.0
  33342. *
  33343. * Unless required by applicable law or agreed to in writing,
  33344. * software distributed under the License is distributed on an
  33345. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33346. * KIND, either express or implied. See the License for the
  33347. * specific language governing permissions and limitations
  33348. * under the License.
  33349. */
  33350. function Cartesian2D(name) {
  33351. Cartesian.call(this, name);
  33352. }
  33353. Cartesian2D.prototype = {
  33354. constructor: Cartesian2D,
  33355. type: 'cartesian2d',
  33356. /**
  33357. * @type {Array.<string>}
  33358. * @readOnly
  33359. */
  33360. dimensions: ['x', 'y'],
  33361. /**
  33362. * Base axis will be used on stacking.
  33363. *
  33364. * @return {module:echarts/coord/cartesian/Axis2D}
  33365. */
  33366. getBaseAxis: function () {
  33367. return this.getAxesByScale('ordinal')[0]
  33368. || this.getAxesByScale('time')[0]
  33369. || this.getAxis('x');
  33370. },
  33371. /**
  33372. * If contain point
  33373. * @param {Array.<number>} point
  33374. * @return {boolean}
  33375. */
  33376. containPoint: function (point) {
  33377. var axisX = this.getAxis('x');
  33378. var axisY = this.getAxis('y');
  33379. return axisX.contain(axisX.toLocalCoord(point[0]))
  33380. && axisY.contain(axisY.toLocalCoord(point[1]));
  33381. },
  33382. /**
  33383. * If contain data
  33384. * @param {Array.<number>} data
  33385. * @return {boolean}
  33386. */
  33387. containData: function (data) {
  33388. return this.getAxis('x').containData(data[0])
  33389. && this.getAxis('y').containData(data[1]);
  33390. },
  33391. /**
  33392. * @param {Array.<number>} data
  33393. * @param {Array.<number>} out
  33394. * @return {Array.<number>}
  33395. */
  33396. dataToPoint: function (data, reserved, out) {
  33397. var xAxis = this.getAxis('x');
  33398. var yAxis = this.getAxis('y');
  33399. out = out || [];
  33400. out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(data[0]));
  33401. out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(data[1]));
  33402. return out;
  33403. },
  33404. /**
  33405. * @param {Array.<number>} data
  33406. * @param {Array.<number>} out
  33407. * @return {Array.<number>}
  33408. */
  33409. clampData: function (data, out) {
  33410. var xScale = this.getAxis('x').scale;
  33411. var yScale = this.getAxis('y').scale;
  33412. var xAxisExtent = xScale.getExtent();
  33413. var yAxisExtent = yScale.getExtent();
  33414. var x = xScale.parse(data[0]);
  33415. var y = yScale.parse(data[1]);
  33416. out = out || [];
  33417. out[0] = Math.min(
  33418. Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x),
  33419. Math.max(xAxisExtent[0], xAxisExtent[1])
  33420. );
  33421. out[1] = Math.min(
  33422. Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y),
  33423. Math.max(yAxisExtent[0], yAxisExtent[1])
  33424. );
  33425. return out;
  33426. },
  33427. /**
  33428. * @param {Array.<number>} point
  33429. * @param {Array.<number>} out
  33430. * @return {Array.<number>}
  33431. */
  33432. pointToData: function (point, out) {
  33433. var xAxis = this.getAxis('x');
  33434. var yAxis = this.getAxis('y');
  33435. out = out || [];
  33436. out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]));
  33437. out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]));
  33438. return out;
  33439. },
  33440. /**
  33441. * Get other axis
  33442. * @param {module:echarts/coord/cartesian/Axis2D} axis
  33443. */
  33444. getOtherAxis: function (axis) {
  33445. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  33446. }
  33447. };
  33448. inherits(Cartesian2D, Cartesian);
  33449. /*
  33450. * Licensed to the Apache Software Foundation (ASF) under one
  33451. * or more contributor license agreements. See the NOTICE file
  33452. * distributed with this work for additional information
  33453. * regarding copyright ownership. The ASF licenses this file
  33454. * to you under the Apache License, Version 2.0 (the
  33455. * "License"); you may not use this file except in compliance
  33456. * with the License. You may obtain a copy of the License at
  33457. *
  33458. * http://www.apache.org/licenses/LICENSE-2.0
  33459. *
  33460. * Unless required by applicable law or agreed to in writing,
  33461. * software distributed under the License is distributed on an
  33462. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33463. * KIND, either express or implied. See the License for the
  33464. * specific language governing permissions and limitations
  33465. * under the License.
  33466. */
  33467. /**
  33468. * Extend axis 2d
  33469. * @constructor module:echarts/coord/cartesian/Axis2D
  33470. * @extends {module:echarts/coord/cartesian/Axis}
  33471. * @param {string} dim
  33472. * @param {*} scale
  33473. * @param {Array.<number>} coordExtent
  33474. * @param {string} axisType
  33475. * @param {string} position
  33476. */
  33477. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  33478. Axis.call(this, dim, scale, coordExtent);
  33479. /**
  33480. * Axis type
  33481. * - 'category'
  33482. * - 'value'
  33483. * - 'time'
  33484. * - 'log'
  33485. * @type {string}
  33486. */
  33487. this.type = axisType || 'value';
  33488. /**
  33489. * Axis position
  33490. * - 'top'
  33491. * - 'bottom'
  33492. * - 'left'
  33493. * - 'right'
  33494. */
  33495. this.position = position || 'bottom';
  33496. };
  33497. Axis2D.prototype = {
  33498. constructor: Axis2D,
  33499. /**
  33500. * Index of axis, can be used as key
  33501. */
  33502. index: 0,
  33503. /**
  33504. * Implemented in <module:echarts/coord/cartesian/Grid>.
  33505. * @return {Array.<module:echarts/coord/cartesian/Axis2D>}
  33506. * If not on zero of other axis, return null/undefined.
  33507. * If no axes, return an empty array.
  33508. */
  33509. getAxesOnZeroOf: null,
  33510. /**
  33511. * Axis model
  33512. * @param {module:echarts/coord/cartesian/AxisModel}
  33513. */
  33514. model: null,
  33515. isHorizontal: function () {
  33516. var position = this.position;
  33517. return position === 'top' || position === 'bottom';
  33518. },
  33519. /**
  33520. * Each item cooresponds to this.getExtent(), which
  33521. * means globalExtent[0] may greater than globalExtent[1],
  33522. * unless `asc` is input.
  33523. *
  33524. * @param {boolean} [asc]
  33525. * @return {Array.<number>}
  33526. */
  33527. getGlobalExtent: function (asc) {
  33528. var ret = this.getExtent();
  33529. ret[0] = this.toGlobalCoord(ret[0]);
  33530. ret[1] = this.toGlobalCoord(ret[1]);
  33531. asc && ret[0] > ret[1] && ret.reverse();
  33532. return ret;
  33533. },
  33534. getOtherAxis: function () {
  33535. this.grid.getOtherAxis();
  33536. },
  33537. /**
  33538. * @override
  33539. */
  33540. pointToData: function (point, clamp) {
  33541. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  33542. },
  33543. /**
  33544. * Transform global coord to local coord,
  33545. * i.e. var localCoord = axis.toLocalCoord(80);
  33546. * designate by module:echarts/coord/cartesian/Grid.
  33547. * @type {Function}
  33548. */
  33549. toLocalCoord: null,
  33550. /**
  33551. * Transform global coord to local coord,
  33552. * i.e. var globalCoord = axis.toLocalCoord(40);
  33553. * designate by module:echarts/coord/cartesian/Grid.
  33554. * @type {Function}
  33555. */
  33556. toGlobalCoord: null
  33557. };
  33558. inherits(Axis2D, Axis);
  33559. /*
  33560. * Licensed to the Apache Software Foundation (ASF) under one
  33561. * or more contributor license agreements. See the NOTICE file
  33562. * distributed with this work for additional information
  33563. * regarding copyright ownership. The ASF licenses this file
  33564. * to you under the Apache License, Version 2.0 (the
  33565. * "License"); you may not use this file except in compliance
  33566. * with the License. You may obtain a copy of the License at
  33567. *
  33568. * http://www.apache.org/licenses/LICENSE-2.0
  33569. *
  33570. * Unless required by applicable law or agreed to in writing,
  33571. * software distributed under the License is distributed on an
  33572. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33573. * KIND, either express or implied. See the License for the
  33574. * specific language governing permissions and limitations
  33575. * under the License.
  33576. */
  33577. var defaultOption = {
  33578. show: true,
  33579. zlevel: 0,
  33580. z: 0,
  33581. // Inverse the axis.
  33582. inverse: false,
  33583. // Axis name displayed.
  33584. name: '',
  33585. // 'start' | 'middle' | 'end'
  33586. nameLocation: 'end',
  33587. // By degree. By defualt auto rotate by nameLocation.
  33588. nameRotate: null,
  33589. nameTruncate: {
  33590. maxWidth: null,
  33591. ellipsis: '...',
  33592. placeholder: '.'
  33593. },
  33594. // Use global text style by default.
  33595. nameTextStyle: {},
  33596. // The gap between axisName and axisLine.
  33597. nameGap: 15,
  33598. // Default `false` to support tooltip.
  33599. silent: false,
  33600. // Default `false` to avoid legacy user event listener fail.
  33601. triggerEvent: false,
  33602. tooltip: {
  33603. show: false
  33604. },
  33605. axisPointer: {},
  33606. axisLine: {
  33607. show: true,
  33608. onZero: true,
  33609. onZeroAxisIndex: null,
  33610. lineStyle: {
  33611. color: '#333',
  33612. width: 1,
  33613. type: 'solid'
  33614. },
  33615. // The arrow at both ends the the axis.
  33616. symbol: ['none', 'none'],
  33617. symbolSize: [10, 15]
  33618. },
  33619. axisTick: {
  33620. show: true,
  33621. // Whether axisTick is inside the grid or outside the grid.
  33622. inside: false,
  33623. // The length of axisTick.
  33624. length: 5,
  33625. lineStyle: {
  33626. width: 1
  33627. }
  33628. },
  33629. axisLabel: {
  33630. show: true,
  33631. // Whether axisLabel is inside the grid or outside the grid.
  33632. inside: false,
  33633. rotate: 0,
  33634. // true | false | null/undefined (auto)
  33635. showMinLabel: null,
  33636. // true | false | null/undefined (auto)
  33637. showMaxLabel: null,
  33638. margin: 8,
  33639. // formatter: null,
  33640. fontSize: 12
  33641. },
  33642. splitLine: {
  33643. show: true,
  33644. lineStyle: {
  33645. color: ['#ccc'],
  33646. width: 1,
  33647. type: 'solid'
  33648. }
  33649. },
  33650. splitArea: {
  33651. show: false,
  33652. areaStyle: {
  33653. color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
  33654. }
  33655. }
  33656. };
  33657. var axisDefault = {};
  33658. axisDefault.categoryAxis = merge({
  33659. // The gap at both ends of the axis. For categoryAxis, boolean.
  33660. boundaryGap: true,
  33661. // Set false to faster category collection.
  33662. // Only usefull in the case like: category is
  33663. // ['2012-01-01', '2012-01-02', ...], where the input
  33664. // data has been ensured not duplicate and is large data.
  33665. // null means "auto":
  33666. // if axis.data provided, do not deduplication,
  33667. // else do deduplication.
  33668. deduplication: null,
  33669. // splitArea: {
  33670. // show: false
  33671. // },
  33672. splitLine: {
  33673. show: false
  33674. },
  33675. axisTick: {
  33676. // If tick is align with label when boundaryGap is true
  33677. alignWithLabel: false,
  33678. interval: 'auto'
  33679. },
  33680. axisLabel: {
  33681. interval: 'auto'
  33682. }
  33683. }, defaultOption);
  33684. axisDefault.valueAxis = merge({
  33685. // The gap at both ends of the axis. For value axis, [GAP, GAP], where
  33686. // `GAP` can be an absolute pixel number (like `35`), or percent (like `'30%'`)
  33687. boundaryGap: [0, 0],
  33688. // TODO
  33689. // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
  33690. // Min value of the axis. can be:
  33691. // + a number
  33692. // + 'dataMin': use the min value in data.
  33693. // + null/undefined: auto decide min value (consider pretty look and boundaryGap).
  33694. // min: null,
  33695. // Max value of the axis. can be:
  33696. // + a number
  33697. // + 'dataMax': use the max value in data.
  33698. // + null/undefined: auto decide max value (consider pretty look and boundaryGap).
  33699. // max: null,
  33700. // Readonly prop, specifies start value of the range when using data zoom.
  33701. // rangeStart: null
  33702. // Readonly prop, specifies end value of the range when using data zoom.
  33703. // rangeEnd: null
  33704. // Optional value can be:
  33705. // + `false`: always include value 0.
  33706. // + `true`: the extent do not consider value 0.
  33707. // scale: false,
  33708. // AxisTick and axisLabel and splitLine are caculated based on splitNumber.
  33709. splitNumber: 5
  33710. // Interval specifies the span of the ticks is mandatorily.
  33711. // interval: null
  33712. // Specify min interval when auto calculate tick interval.
  33713. // minInterval: null
  33714. // Specify max interval when auto calculate tick interval.
  33715. // maxInterval: null
  33716. }, defaultOption);
  33717. axisDefault.timeAxis = defaults({
  33718. scale: true,
  33719. min: 'dataMin',
  33720. max: 'dataMax'
  33721. }, axisDefault.valueAxis);
  33722. axisDefault.logAxis = defaults({
  33723. scale: true,
  33724. logBase: 10
  33725. }, axisDefault.valueAxis);
  33726. /*
  33727. * Licensed to the Apache Software Foundation (ASF) under one
  33728. * or more contributor license agreements. See the NOTICE file
  33729. * distributed with this work for additional information
  33730. * regarding copyright ownership. The ASF licenses this file
  33731. * to you under the Apache License, Version 2.0 (the
  33732. * "License"); you may not use this file except in compliance
  33733. * with the License. You may obtain a copy of the License at
  33734. *
  33735. * http://www.apache.org/licenses/LICENSE-2.0
  33736. *
  33737. * Unless required by applicable law or agreed to in writing,
  33738. * software distributed under the License is distributed on an
  33739. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33740. * KIND, either express or implied. See the License for the
  33741. * specific language governing permissions and limitations
  33742. * under the License.
  33743. */
  33744. // FIXME axisType is fixed ?
  33745. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  33746. /**
  33747. * Generate sub axis model class
  33748. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  33749. * @param {module:echarts/model/Component} BaseAxisModelClass
  33750. * @param {Function} axisTypeDefaulter
  33751. * @param {Object} [extraDefaultOption]
  33752. */
  33753. var axisModelCreator = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  33754. each$1(AXIS_TYPES, function (axisType) {
  33755. BaseAxisModelClass.extend({
  33756. /**
  33757. * @readOnly
  33758. */
  33759. type: axisName + 'Axis.' + axisType,
  33760. mergeDefaultAndTheme: function (option, ecModel) {
  33761. var layoutMode = this.layoutMode;
  33762. var inputPositionParams = layoutMode
  33763. ? getLayoutParams(option) : {};
  33764. var themeModel = ecModel.getTheme();
  33765. merge(option, themeModel.get(axisType + 'Axis'));
  33766. merge(option, this.getDefaultOption());
  33767. option.type = axisTypeDefaulter(axisName, option);
  33768. if (layoutMode) {
  33769. mergeLayoutParam(option, inputPositionParams, layoutMode);
  33770. }
  33771. },
  33772. /**
  33773. * @override
  33774. */
  33775. optionUpdated: function () {
  33776. var thisOption = this.option;
  33777. if (thisOption.type === 'category') {
  33778. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  33779. }
  33780. },
  33781. /**
  33782. * Should not be called before all of 'getInitailData' finished.
  33783. * Because categories are collected during initializing data.
  33784. */
  33785. getCategories: function (rawData) {
  33786. var option = this.option;
  33787. // FIXME
  33788. // warning if called before all of 'getInitailData' finished.
  33789. if (option.type === 'category') {
  33790. if (rawData) {
  33791. return option.data;
  33792. }
  33793. return this.__ordinalMeta.categories;
  33794. }
  33795. },
  33796. getOrdinalMeta: function () {
  33797. return this.__ordinalMeta;
  33798. },
  33799. defaultOption: mergeAll(
  33800. [
  33801. {},
  33802. axisDefault[axisType + 'Axis'],
  33803. extraDefaultOption
  33804. ],
  33805. true
  33806. )
  33807. });
  33808. });
  33809. ComponentModel.registerSubTypeDefaulter(
  33810. axisName + 'Axis',
  33811. curry(axisTypeDefaulter, axisName)
  33812. );
  33813. };
  33814. /*
  33815. * Licensed to the Apache Software Foundation (ASF) under one
  33816. * or more contributor license agreements. See the NOTICE file
  33817. * distributed with this work for additional information
  33818. * regarding copyright ownership. The ASF licenses this file
  33819. * to you under the Apache License, Version 2.0 (the
  33820. * "License"); you may not use this file except in compliance
  33821. * with the License. You may obtain a copy of the License at
  33822. *
  33823. * http://www.apache.org/licenses/LICENSE-2.0
  33824. *
  33825. * Unless required by applicable law or agreed to in writing,
  33826. * software distributed under the License is distributed on an
  33827. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33828. * KIND, either express or implied. See the License for the
  33829. * specific language governing permissions and limitations
  33830. * under the License.
  33831. */
  33832. var AxisModel = ComponentModel.extend({
  33833. type: 'cartesian2dAxis',
  33834. /**
  33835. * @type {module:echarts/coord/cartesian/Axis2D}
  33836. */
  33837. axis: null,
  33838. /**
  33839. * @override
  33840. */
  33841. init: function () {
  33842. AxisModel.superApply(this, 'init', arguments);
  33843. this.resetRange();
  33844. },
  33845. /**
  33846. * @override
  33847. */
  33848. mergeOption: function () {
  33849. AxisModel.superApply(this, 'mergeOption', arguments);
  33850. this.resetRange();
  33851. },
  33852. /**
  33853. * @override
  33854. */
  33855. restoreData: function () {
  33856. AxisModel.superApply(this, 'restoreData', arguments);
  33857. this.resetRange();
  33858. },
  33859. /**
  33860. * @override
  33861. * @return {module:echarts/model/Component}
  33862. */
  33863. getCoordSysModel: function () {
  33864. return this.ecModel.queryComponents({
  33865. mainType: 'grid',
  33866. index: this.option.gridIndex,
  33867. id: this.option.gridId
  33868. })[0];
  33869. }
  33870. });
  33871. function getAxisType(axisDim, option) {
  33872. // Default axis with data is category axis
  33873. return option.type || (option.data ? 'category' : 'value');
  33874. }
  33875. merge(AxisModel.prototype, axisModelCommonMixin);
  33876. var extraOption = {
  33877. // gridIndex: 0,
  33878. // gridId: '',
  33879. // Offset is for multiple axis on the same position
  33880. offset: 0
  33881. };
  33882. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  33883. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  33884. /*
  33885. * Licensed to the Apache Software Foundation (ASF) under one
  33886. * or more contributor license agreements. See the NOTICE file
  33887. * distributed with this work for additional information
  33888. * regarding copyright ownership. The ASF licenses this file
  33889. * to you under the Apache License, Version 2.0 (the
  33890. * "License"); you may not use this file except in compliance
  33891. * with the License. You may obtain a copy of the License at
  33892. *
  33893. * http://www.apache.org/licenses/LICENSE-2.0
  33894. *
  33895. * Unless required by applicable law or agreed to in writing,
  33896. * software distributed under the License is distributed on an
  33897. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33898. * KIND, either express or implied. See the License for the
  33899. * specific language governing permissions and limitations
  33900. * under the License.
  33901. */
  33902. // Grid 是在有直角坐标系的时候必须要存在的
  33903. // 所以这里也要被 Cartesian2D 依赖
  33904. ComponentModel.extend({
  33905. type: 'grid',
  33906. dependencies: ['xAxis', 'yAxis'],
  33907. layoutMode: 'box',
  33908. /**
  33909. * @type {module:echarts/coord/cartesian/Grid}
  33910. */
  33911. coordinateSystem: null,
  33912. defaultOption: {
  33913. show: false,
  33914. zlevel: 0,
  33915. z: 0,
  33916. left: '10%',
  33917. top: 60,
  33918. right: '10%',
  33919. bottom: 60,
  33920. // If grid size contain label
  33921. containLabel: false,
  33922. // width: {totalWidth} - left - right,
  33923. // height: {totalHeight} - top - bottom,
  33924. backgroundColor: 'rgba(0,0,0,0)',
  33925. borderWidth: 1,
  33926. borderColor: '#ccc'
  33927. }
  33928. });
  33929. /*
  33930. * Licensed to the Apache Software Foundation (ASF) under one
  33931. * or more contributor license agreements. See the NOTICE file
  33932. * distributed with this work for additional information
  33933. * regarding copyright ownership. The ASF licenses this file
  33934. * to you under the Apache License, Version 2.0 (the
  33935. * "License"); you may not use this file except in compliance
  33936. * with the License. You may obtain a copy of the License at
  33937. *
  33938. * http://www.apache.org/licenses/LICENSE-2.0
  33939. *
  33940. * Unless required by applicable law or agreed to in writing,
  33941. * software distributed under the License is distributed on an
  33942. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33943. * KIND, either express or implied. See the License for the
  33944. * specific language governing permissions and limitations
  33945. * under the License.
  33946. */
  33947. /**
  33948. * Grid is a region which contains at most 4 cartesian systems
  33949. *
  33950. * TODO Default cartesian
  33951. */
  33952. // Depends on GridModel, AxisModel, which performs preprocess.
  33953. /**
  33954. * Check if the axis is used in the specified grid
  33955. * @inner
  33956. */
  33957. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  33958. return axisModel.getCoordSysModel() === gridModel;
  33959. }
  33960. function Grid(gridModel, ecModel, api) {
  33961. /**
  33962. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  33963. * @private
  33964. */
  33965. this._coordsMap = {};
  33966. /**
  33967. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  33968. * @private
  33969. */
  33970. this._coordsList = [];
  33971. /**
  33972. * @type {Object.<string, module:echarts/coord/cartesian/Axis2D>}
  33973. * @private
  33974. */
  33975. this._axesMap = {};
  33976. /**
  33977. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  33978. * @private
  33979. */
  33980. this._axesList = [];
  33981. this._initCartesian(gridModel, ecModel, api);
  33982. this.model = gridModel;
  33983. }
  33984. var gridProto = Grid.prototype;
  33985. gridProto.type = 'grid';
  33986. gridProto.axisPointerEnabled = true;
  33987. gridProto.getRect = function () {
  33988. return this._rect;
  33989. };
  33990. gridProto.update = function (ecModel, api) {
  33991. var axesMap = this._axesMap;
  33992. this._updateScale(ecModel, this.model);
  33993. each$1(axesMap.x, function (xAxis) {
  33994. niceScaleExtent(xAxis.scale, xAxis.model);
  33995. });
  33996. each$1(axesMap.y, function (yAxis) {
  33997. niceScaleExtent(yAxis.scale, yAxis.model);
  33998. });
  33999. // Key: axisDim_axisIndex, value: boolean, whether onZero target.
  34000. var onZeroRecords = {};
  34001. each$1(axesMap.x, function (xAxis) {
  34002. fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
  34003. });
  34004. each$1(axesMap.y, function (yAxis) {
  34005. fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
  34006. });
  34007. // Resize again if containLabel is enabled
  34008. // FIXME It may cause getting wrong grid size in data processing stage
  34009. this.resize(this.model, api);
  34010. };
  34011. function fixAxisOnZero(axesMap, otherAxisDim, axis, onZeroRecords) {
  34012. axis.getAxesOnZeroOf = function () {
  34013. // TODO: onZero of multiple axes.
  34014. return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
  34015. };
  34016. // onZero can not be enabled in these two situations:
  34017. // 1. When any other axis is a category axis.
  34018. // 2. When no axis is cross 0 point.
  34019. var otherAxes = axesMap[otherAxisDim];
  34020. var otherAxisOnZeroOf;
  34021. var axisModel = axis.model;
  34022. var onZero = axisModel.get('axisLine.onZero');
  34023. var onZeroAxisIndex = axisModel.get('axisLine.onZeroAxisIndex');
  34024. if (!onZero) {
  34025. return;
  34026. }
  34027. // If target axis is specified.
  34028. if (onZeroAxisIndex != null) {
  34029. if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
  34030. otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
  34031. }
  34032. }
  34033. else {
  34034. // Find the first available other axis.
  34035. for (var idx in otherAxes) {
  34036. if (otherAxes.hasOwnProperty(idx)
  34037. && canOnZeroToAxis(otherAxes[idx])
  34038. // Consider that two Y axes on one value axis,
  34039. // if both onZero, the two Y axes overlap.
  34040. && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]
  34041. ) {
  34042. otherAxisOnZeroOf = otherAxes[idx];
  34043. break;
  34044. }
  34045. }
  34046. }
  34047. if (otherAxisOnZeroOf) {
  34048. onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
  34049. }
  34050. function getOnZeroRecordKey(axis) {
  34051. return axis.dim + '_' + axis.index;
  34052. }
  34053. }
  34054. function canOnZeroToAxis(axis) {
  34055. return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
  34056. }
  34057. /**
  34058. * Resize the grid
  34059. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  34060. * @param {module:echarts/ExtensionAPI} api
  34061. */
  34062. gridProto.resize = function (gridModel, api, ignoreContainLabel) {
  34063. var gridRect = getLayoutRect(
  34064. gridModel.getBoxLayoutParams(), {
  34065. width: api.getWidth(),
  34066. height: api.getHeight()
  34067. });
  34068. this._rect = gridRect;
  34069. var axesList = this._axesList;
  34070. adjustAxes();
  34071. // Minus label size
  34072. if (!ignoreContainLabel && gridModel.get('containLabel')) {
  34073. each$1(axesList, function (axis) {
  34074. if (!axis.model.get('axisLabel.inside')) {
  34075. var labelUnionRect = estimateLabelUnionRect(axis);
  34076. if (labelUnionRect) {
  34077. var dim = axis.isHorizontal() ? 'height' : 'width';
  34078. var margin = axis.model.get('axisLabel.margin');
  34079. gridRect[dim] -= labelUnionRect[dim] + margin;
  34080. if (axis.position === 'top') {
  34081. gridRect.y += labelUnionRect.height + margin;
  34082. }
  34083. else if (axis.position === 'left') {
  34084. gridRect.x += labelUnionRect.width + margin;
  34085. }
  34086. }
  34087. }
  34088. });
  34089. adjustAxes();
  34090. }
  34091. function adjustAxes() {
  34092. each$1(axesList, function (axis) {
  34093. var isHorizontal = axis.isHorizontal();
  34094. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  34095. var idx = axis.inverse ? 1 : 0;
  34096. axis.setExtent(extent[idx], extent[1 - idx]);
  34097. updateAxisTransform(axis, isHorizontal ? gridRect.x : gridRect.y);
  34098. });
  34099. }
  34100. };
  34101. /**
  34102. * @param {string} axisType
  34103. * @param {number} [axisIndex]
  34104. */
  34105. gridProto.getAxis = function (axisType, axisIndex) {
  34106. var axesMapOnDim = this._axesMap[axisType];
  34107. if (axesMapOnDim != null) {
  34108. if (axisIndex == null) {
  34109. // Find first axis
  34110. for (var name in axesMapOnDim) {
  34111. if (axesMapOnDim.hasOwnProperty(name)) {
  34112. return axesMapOnDim[name];
  34113. }
  34114. }
  34115. }
  34116. return axesMapOnDim[axisIndex];
  34117. }
  34118. };
  34119. /**
  34120. * @return {Array.<module:echarts/coord/Axis>}
  34121. */
  34122. gridProto.getAxes = function () {
  34123. return this._axesList.slice();
  34124. };
  34125. /**
  34126. * Usage:
  34127. * grid.getCartesian(xAxisIndex, yAxisIndex);
  34128. * grid.getCartesian(xAxisIndex);
  34129. * grid.getCartesian(null, yAxisIndex);
  34130. * grid.getCartesian({xAxisIndex: ..., yAxisIndex: ...});
  34131. *
  34132. * @param {number|Object} [xAxisIndex]
  34133. * @param {number} [yAxisIndex]
  34134. */
  34135. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  34136. if (xAxisIndex != null && yAxisIndex != null) {
  34137. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  34138. return this._coordsMap[key];
  34139. }
  34140. if (isObject$1(xAxisIndex)) {
  34141. yAxisIndex = xAxisIndex.yAxisIndex;
  34142. xAxisIndex = xAxisIndex.xAxisIndex;
  34143. }
  34144. // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  34145. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  34146. if (coordList[i].getAxis('x').index === xAxisIndex
  34147. || coordList[i].getAxis('y').index === yAxisIndex
  34148. ) {
  34149. return coordList[i];
  34150. }
  34151. }
  34152. };
  34153. gridProto.getCartesians = function () {
  34154. return this._coordsList.slice();
  34155. };
  34156. /**
  34157. * @implements
  34158. * see {module:echarts/CoodinateSystem}
  34159. */
  34160. gridProto.convertToPixel = function (ecModel, finder, value) {
  34161. var target = this._findConvertTarget(ecModel, finder);
  34162. return target.cartesian
  34163. ? target.cartesian.dataToPoint(value)
  34164. : target.axis
  34165. ? target.axis.toGlobalCoord(target.axis.dataToCoord(value))
  34166. : null;
  34167. };
  34168. /**
  34169. * @implements
  34170. * see {module:echarts/CoodinateSystem}
  34171. */
  34172. gridProto.convertFromPixel = function (ecModel, finder, value) {
  34173. var target = this._findConvertTarget(ecModel, finder);
  34174. return target.cartesian
  34175. ? target.cartesian.pointToData(value)
  34176. : target.axis
  34177. ? target.axis.coordToData(target.axis.toLocalCoord(value))
  34178. : null;
  34179. };
  34180. /**
  34181. * @inner
  34182. */
  34183. gridProto._findConvertTarget = function (ecModel, finder) {
  34184. var seriesModel = finder.seriesModel;
  34185. var xAxisModel = finder.xAxisModel
  34186. || (seriesModel && seriesModel.getReferringComponents('xAxis')[0]);
  34187. var yAxisModel = finder.yAxisModel
  34188. || (seriesModel && seriesModel.getReferringComponents('yAxis')[0]);
  34189. var gridModel = finder.gridModel;
  34190. var coordsList = this._coordsList;
  34191. var cartesian;
  34192. var axis;
  34193. if (seriesModel) {
  34194. cartesian = seriesModel.coordinateSystem;
  34195. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  34196. }
  34197. else if (xAxisModel && yAxisModel) {
  34198. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  34199. }
  34200. else if (xAxisModel) {
  34201. axis = this.getAxis('x', xAxisModel.componentIndex);
  34202. }
  34203. else if (yAxisModel) {
  34204. axis = this.getAxis('y', yAxisModel.componentIndex);
  34205. }
  34206. // Lowest priority.
  34207. else if (gridModel) {
  34208. var grid = gridModel.coordinateSystem;
  34209. if (grid === this) {
  34210. cartesian = this._coordsList[0];
  34211. }
  34212. }
  34213. return {cartesian: cartesian, axis: axis};
  34214. };
  34215. /**
  34216. * @implements
  34217. * see {module:echarts/CoodinateSystem}
  34218. */
  34219. gridProto.containPoint = function (point) {
  34220. var coord = this._coordsList[0];
  34221. if (coord) {
  34222. return coord.containPoint(point);
  34223. }
  34224. };
  34225. /**
  34226. * Initialize cartesian coordinate systems
  34227. * @private
  34228. */
  34229. gridProto._initCartesian = function (gridModel, ecModel, api) {
  34230. var axisPositionUsed = {
  34231. left: false,
  34232. right: false,
  34233. top: false,
  34234. bottom: false
  34235. };
  34236. var axesMap = {
  34237. x: {},
  34238. y: {}
  34239. };
  34240. var axesCount = {
  34241. x: 0,
  34242. y: 0
  34243. };
  34244. /// Create axis
  34245. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  34246. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  34247. if (!axesCount.x || !axesCount.y) {
  34248. // Roll back when there no either x or y axis
  34249. this._axesMap = {};
  34250. this._axesList = [];
  34251. return;
  34252. }
  34253. this._axesMap = axesMap;
  34254. /// Create cartesian2d
  34255. each$1(axesMap.x, function (xAxis, xAxisIndex) {
  34256. each$1(axesMap.y, function (yAxis, yAxisIndex) {
  34257. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  34258. var cartesian = new Cartesian2D(key);
  34259. cartesian.grid = this;
  34260. cartesian.model = gridModel;
  34261. this._coordsMap[key] = cartesian;
  34262. this._coordsList.push(cartesian);
  34263. cartesian.addAxis(xAxis);
  34264. cartesian.addAxis(yAxis);
  34265. }, this);
  34266. }, this);
  34267. function createAxisCreator(axisType) {
  34268. return function (axisModel, idx) {
  34269. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  34270. return;
  34271. }
  34272. var axisPosition = axisModel.get('position');
  34273. if (axisType === 'x') {
  34274. // Fix position
  34275. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  34276. // Default bottom of X
  34277. axisPosition = 'bottom';
  34278. if (axisPositionUsed[axisPosition]) {
  34279. axisPosition = axisPosition === 'top' ? 'bottom' : 'top';
  34280. }
  34281. }
  34282. }
  34283. else {
  34284. // Fix position
  34285. if (axisPosition !== 'left' && axisPosition !== 'right') {
  34286. // Default left of Y
  34287. axisPosition = 'left';
  34288. if (axisPositionUsed[axisPosition]) {
  34289. axisPosition = axisPosition === 'left' ? 'right' : 'left';
  34290. }
  34291. }
  34292. }
  34293. axisPositionUsed[axisPosition] = true;
  34294. var axis = new Axis2D(
  34295. axisType, createScaleByModel(axisModel),
  34296. [0, 0],
  34297. axisModel.get('type'),
  34298. axisPosition
  34299. );
  34300. var isCategory = axis.type === 'category';
  34301. axis.onBand = isCategory && axisModel.get('boundaryGap');
  34302. axis.inverse = axisModel.get('inverse');
  34303. // Inject axis into axisModel
  34304. axisModel.axis = axis;
  34305. // Inject axisModel into axis
  34306. axis.model = axisModel;
  34307. // Inject grid info axis
  34308. axis.grid = this;
  34309. // Index of axis, can be used as key
  34310. axis.index = idx;
  34311. this._axesList.push(axis);
  34312. axesMap[axisType][idx] = axis;
  34313. axesCount[axisType]++;
  34314. };
  34315. }
  34316. };
  34317. /**
  34318. * Update cartesian properties from series
  34319. * @param {module:echarts/model/Option} option
  34320. * @private
  34321. */
  34322. gridProto._updateScale = function (ecModel, gridModel) {
  34323. // Reset scale
  34324. each$1(this._axesList, function (axis) {
  34325. axis.scale.setExtent(Infinity, -Infinity);
  34326. });
  34327. ecModel.eachSeries(function (seriesModel) {
  34328. if (isCartesian2D(seriesModel)) {
  34329. var axesModels = findAxesModels(seriesModel, ecModel);
  34330. var xAxisModel = axesModels[0];
  34331. var yAxisModel = axesModels[1];
  34332. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel)
  34333. || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)
  34334. ) {
  34335. return;
  34336. }
  34337. var cartesian = this.getCartesian(
  34338. xAxisModel.componentIndex, yAxisModel.componentIndex
  34339. );
  34340. var data = seriesModel.getData();
  34341. var xAxis = cartesian.getAxis('x');
  34342. var yAxis = cartesian.getAxis('y');
  34343. if (data.type === 'list') {
  34344. unionExtent(data, xAxis, seriesModel);
  34345. unionExtent(data, yAxis, seriesModel);
  34346. }
  34347. }
  34348. }, this);
  34349. function unionExtent(data, axis, seriesModel) {
  34350. each$1(data.mapDimension(axis.dim, true), function (dim) {
  34351. axis.scale.unionExtentFromData(
  34352. // For example, the extent of the orginal dimension
  34353. // is [0.1, 0.5], the extent of the `stackResultDimension`
  34354. // is [7, 9], the final extent should not include [0.1, 0.5].
  34355. data, getStackedDimension(data, dim)
  34356. );
  34357. });
  34358. }
  34359. };
  34360. /**
  34361. * @param {string} [dim] 'x' or 'y' or 'auto' or null/undefined
  34362. * @return {Object} {baseAxes: [], otherAxes: []}
  34363. */
  34364. gridProto.getTooltipAxes = function (dim) {
  34365. var baseAxes = [];
  34366. var otherAxes = [];
  34367. each$1(this.getCartesians(), function (cartesian) {
  34368. var baseAxis = (dim != null && dim !== 'auto')
  34369. ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  34370. var otherAxis = cartesian.getOtherAxis(baseAxis);
  34371. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  34372. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  34373. });
  34374. return {baseAxes: baseAxes, otherAxes: otherAxes};
  34375. };
  34376. /**
  34377. * @inner
  34378. */
  34379. function updateAxisTransform(axis, coordBase) {
  34380. var axisExtent = axis.getExtent();
  34381. var axisExtentSum = axisExtent[0] + axisExtent[1];
  34382. // Fast transform
  34383. axis.toGlobalCoord = axis.dim === 'x'
  34384. ? function (coord) {
  34385. return coord + coordBase;
  34386. }
  34387. : function (coord) {
  34388. return axisExtentSum - coord + coordBase;
  34389. };
  34390. axis.toLocalCoord = axis.dim === 'x'
  34391. ? function (coord) {
  34392. return coord - coordBase;
  34393. }
  34394. : function (coord) {
  34395. return axisExtentSum - coord + coordBase;
  34396. };
  34397. }
  34398. var axesTypes = ['xAxis', 'yAxis'];
  34399. /**
  34400. * @inner
  34401. */
  34402. function findAxesModels(seriesModel, ecModel) {
  34403. return map(axesTypes, function (axisType) {
  34404. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  34405. if (__DEV__) {
  34406. if (!axisModel) {
  34407. throw new Error(axisType + ' "' + retrieve(
  34408. seriesModel.get(axisType + 'Index'),
  34409. seriesModel.get(axisType + 'Id'),
  34410. 0
  34411. ) + '" not found');
  34412. }
  34413. }
  34414. return axisModel;
  34415. });
  34416. }
  34417. /**
  34418. * @inner
  34419. */
  34420. function isCartesian2D(seriesModel) {
  34421. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  34422. }
  34423. Grid.create = function (ecModel, api) {
  34424. var grids = [];
  34425. ecModel.eachComponent('grid', function (gridModel, idx) {
  34426. var grid = new Grid(gridModel, ecModel, api);
  34427. grid.name = 'grid_' + idx;
  34428. // dataSampling requires axis extent, so resize
  34429. // should be performed in create stage.
  34430. grid.resize(gridModel, api, true);
  34431. gridModel.coordinateSystem = grid;
  34432. grids.push(grid);
  34433. });
  34434. // Inject the coordinateSystems into seriesModel
  34435. ecModel.eachSeries(function (seriesModel) {
  34436. if (!isCartesian2D(seriesModel)) {
  34437. return;
  34438. }
  34439. var axesModels = findAxesModels(seriesModel, ecModel);
  34440. var xAxisModel = axesModels[0];
  34441. var yAxisModel = axesModels[1];
  34442. var gridModel = xAxisModel.getCoordSysModel();
  34443. if (__DEV__) {
  34444. if (!gridModel) {
  34445. throw new Error(
  34446. 'Grid "' + retrieve(
  34447. xAxisModel.get('gridIndex'),
  34448. xAxisModel.get('gridId'),
  34449. 0
  34450. ) + '" not found'
  34451. );
  34452. }
  34453. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  34454. throw new Error('xAxis and yAxis must use the same grid');
  34455. }
  34456. }
  34457. var grid = gridModel.coordinateSystem;
  34458. seriesModel.coordinateSystem = grid.getCartesian(
  34459. xAxisModel.componentIndex, yAxisModel.componentIndex
  34460. );
  34461. });
  34462. return grids;
  34463. };
  34464. // For deciding which dimensions to use when creating list data
  34465. Grid.dimensions = Grid.prototype.dimensions = Cartesian2D.prototype.dimensions;
  34466. CoordinateSystemManager.register('cartesian2d', Grid);
  34467. /*
  34468. * Licensed to the Apache Software Foundation (ASF) under one
  34469. * or more contributor license agreements. See the NOTICE file
  34470. * distributed with this work for additional information
  34471. * regarding copyright ownership. The ASF licenses this file
  34472. * to you under the Apache License, Version 2.0 (the
  34473. * "License"); you may not use this file except in compliance
  34474. * with the License. You may obtain a copy of the License at
  34475. *
  34476. * http://www.apache.org/licenses/LICENSE-2.0
  34477. *
  34478. * Unless required by applicable law or agreed to in writing,
  34479. * software distributed under the License is distributed on an
  34480. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34481. * KIND, either express or implied. See the License for the
  34482. * specific language governing permissions and limitations
  34483. * under the License.
  34484. */
  34485. var PI$2 = Math.PI;
  34486. function makeAxisEventDataBase(axisModel) {
  34487. var eventData = {
  34488. componentType: axisModel.mainType,
  34489. componentIndex: axisModel.componentIndex
  34490. };
  34491. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  34492. return eventData;
  34493. }
  34494. /**
  34495. * A final axis is translated and rotated from a "standard axis".
  34496. * So opt.position and opt.rotation is required.
  34497. *
  34498. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  34499. * for example: (0, 0) ------------> (0, 50)
  34500. *
  34501. * nameDirection or tickDirection or labelDirection is 1 means tick
  34502. * or label is below the standard axis, whereas is -1 means above
  34503. * the standard axis. labelOffset means offset between label and axis,
  34504. * which is useful when 'onZero', where axisLabel is in the grid and
  34505. * label in outside grid.
  34506. *
  34507. * Tips: like always,
  34508. * positive rotation represents anticlockwise, and negative rotation
  34509. * represents clockwise.
  34510. * The direction of position coordinate is the same as the direction
  34511. * of screen coordinate.
  34512. *
  34513. * Do not need to consider axis 'inverse', which is auto processed by
  34514. * axis extent.
  34515. *
  34516. * @param {module:zrender/container/Group} group
  34517. * @param {Object} axisModel
  34518. * @param {Object} opt Standard axis parameters.
  34519. * @param {Array.<number>} opt.position [x, y]
  34520. * @param {number} opt.rotation by radian
  34521. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle' or 'center'.
  34522. * @param {number} [opt.tickDirection=1] 1 or -1
  34523. * @param {number} [opt.labelDirection=1] 1 or -1
  34524. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  34525. * @param {string} [opt.axisLabelShow] default get from axisModel.
  34526. * @param {string} [opt.axisName] default get from axisModel.
  34527. * @param {number} [opt.axisNameAvailableWidth]
  34528. * @param {number} [opt.labelRotate] by degree, default get from axisModel.
  34529. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  34530. * @param {number} [opt.nameTruncateMaxWidth]
  34531. */
  34532. var AxisBuilder = function (axisModel, opt) {
  34533. /**
  34534. * @readOnly
  34535. */
  34536. this.opt = opt;
  34537. /**
  34538. * @readOnly
  34539. */
  34540. this.axisModel = axisModel;
  34541. // Default value
  34542. defaults(
  34543. opt,
  34544. {
  34545. labelOffset: 0,
  34546. nameDirection: 1,
  34547. tickDirection: 1,
  34548. labelDirection: 1,
  34549. silent: true
  34550. }
  34551. );
  34552. /**
  34553. * @readOnly
  34554. */
  34555. this.group = new Group();
  34556. // FIXME Not use a seperate text group?
  34557. var dumbGroup = new Group({
  34558. position: opt.position.slice(),
  34559. rotation: opt.rotation
  34560. });
  34561. // this.group.add(dumbGroup);
  34562. // this._dumbGroup = dumbGroup;
  34563. dumbGroup.updateTransform();
  34564. this._transform = dumbGroup.transform;
  34565. this._dumbGroup = dumbGroup;
  34566. };
  34567. AxisBuilder.prototype = {
  34568. constructor: AxisBuilder,
  34569. hasBuilder: function (name) {
  34570. return !!builders[name];
  34571. },
  34572. add: function (name) {
  34573. builders[name].call(this);
  34574. },
  34575. getGroup: function () {
  34576. return this.group;
  34577. }
  34578. };
  34579. var builders = {
  34580. /**
  34581. * @private
  34582. */
  34583. axisLine: function () {
  34584. var opt = this.opt;
  34585. var axisModel = this.axisModel;
  34586. if (!axisModel.get('axisLine.show')) {
  34587. return;
  34588. }
  34589. var extent = this.axisModel.axis.getExtent();
  34590. var matrix = this._transform;
  34591. var pt1 = [extent[0], 0];
  34592. var pt2 = [extent[1], 0];
  34593. if (matrix) {
  34594. applyTransform(pt1, pt1, matrix);
  34595. applyTransform(pt2, pt2, matrix);
  34596. }
  34597. var lineStyle = extend(
  34598. {
  34599. lineCap: 'round'
  34600. },
  34601. axisModel.getModel('axisLine.lineStyle').getLineStyle()
  34602. );
  34603. this.group.add(new Line(subPixelOptimizeLine({
  34604. // Id for animation
  34605. anid: 'line',
  34606. shape: {
  34607. x1: pt1[0],
  34608. y1: pt1[1],
  34609. x2: pt2[0],
  34610. y2: pt2[1]
  34611. },
  34612. style: lineStyle,
  34613. strokeContainThreshold: opt.strokeContainThreshold || 5,
  34614. silent: true,
  34615. z2: 1
  34616. })));
  34617. var arrows = axisModel.get('axisLine.symbol');
  34618. var arrowSize = axisModel.get('axisLine.symbolSize');
  34619. var arrowOffset = axisModel.get('axisLine.symbolOffset') || 0;
  34620. if (typeof arrowOffset === 'number') {
  34621. arrowOffset = [arrowOffset, arrowOffset];
  34622. }
  34623. if (arrows != null) {
  34624. if (typeof arrows === 'string') {
  34625. // Use the same arrow for start and end point
  34626. arrows = [arrows, arrows];
  34627. }
  34628. if (typeof arrowSize === 'string'
  34629. || typeof arrowSize === 'number'
  34630. ) {
  34631. // Use the same size for width and height
  34632. arrowSize = [arrowSize, arrowSize];
  34633. }
  34634. var symbolWidth = arrowSize[0];
  34635. var symbolHeight = arrowSize[1];
  34636. each$1([{
  34637. rotate: opt.rotation + Math.PI / 2,
  34638. offset: arrowOffset[0],
  34639. r: 0
  34640. }, {
  34641. rotate: opt.rotation - Math.PI / 2,
  34642. offset: arrowOffset[1],
  34643. r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0])
  34644. + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1]))
  34645. }], function (point, index) {
  34646. if (arrows[index] !== 'none' && arrows[index] != null) {
  34647. var symbol = createSymbol(
  34648. arrows[index],
  34649. -symbolWidth / 2,
  34650. -symbolHeight / 2,
  34651. symbolWidth,
  34652. symbolHeight,
  34653. lineStyle.stroke,
  34654. true
  34655. );
  34656. // Calculate arrow position with offset
  34657. var r = point.r + point.offset;
  34658. var pos = [
  34659. pt1[0] + r * Math.cos(opt.rotation),
  34660. pt1[1] - r * Math.sin(opt.rotation)
  34661. ];
  34662. symbol.attr({
  34663. rotation: point.rotate,
  34664. position: pos,
  34665. silent: true,
  34666. z2: 11
  34667. });
  34668. this.group.add(symbol);
  34669. }
  34670. }, this);
  34671. }
  34672. },
  34673. /**
  34674. * @private
  34675. */
  34676. axisTickLabel: function () {
  34677. var axisModel = this.axisModel;
  34678. var opt = this.opt;
  34679. var tickEls = buildAxisTick(this, axisModel, opt);
  34680. var labelEls = buildAxisLabel(this, axisModel, opt);
  34681. fixMinMaxLabelShow(axisModel, labelEls, tickEls);
  34682. },
  34683. /**
  34684. * @private
  34685. */
  34686. axisName: function () {
  34687. var opt = this.opt;
  34688. var axisModel = this.axisModel;
  34689. var name = retrieve(opt.axisName, axisModel.get('name'));
  34690. if (!name) {
  34691. return;
  34692. }
  34693. var nameLocation = axisModel.get('nameLocation');
  34694. var nameDirection = opt.nameDirection;
  34695. var textStyleModel = axisModel.getModel('nameTextStyle');
  34696. var gap = axisModel.get('nameGap') || 0;
  34697. var extent = this.axisModel.axis.getExtent();
  34698. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  34699. var pos = [
  34700. nameLocation === 'start'
  34701. ? extent[0] - gapSignal * gap
  34702. : nameLocation === 'end'
  34703. ? extent[1] + gapSignal * gap
  34704. : (extent[0] + extent[1]) / 2, // 'middle'
  34705. // Reuse labelOffset.
  34706. isNameLocationCenter(nameLocation) ? opt.labelOffset + nameDirection * gap : 0
  34707. ];
  34708. var labelLayout;
  34709. var nameRotation = axisModel.get('nameRotate');
  34710. if (nameRotation != null) {
  34711. nameRotation = nameRotation * PI$2 / 180; // To radian.
  34712. }
  34713. var axisNameAvailableWidth;
  34714. if (isNameLocationCenter(nameLocation)) {
  34715. labelLayout = innerTextLayout(
  34716. opt.rotation,
  34717. nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  34718. nameDirection
  34719. );
  34720. }
  34721. else {
  34722. labelLayout = endTextLayout(
  34723. opt, nameLocation, nameRotation || 0, extent
  34724. );
  34725. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  34726. if (axisNameAvailableWidth != null) {
  34727. axisNameAvailableWidth = Math.abs(
  34728. axisNameAvailableWidth / Math.sin(labelLayout.rotation)
  34729. );
  34730. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  34731. }
  34732. }
  34733. var textFont = textStyleModel.getFont();
  34734. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  34735. var ellipsis = truncateOpt.ellipsis;
  34736. var maxWidth = retrieve(
  34737. opt.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth
  34738. );
  34739. // FIXME
  34740. // truncate rich text? (consider performance)
  34741. var truncatedText = (ellipsis != null && maxWidth != null)
  34742. ? truncateText$1(
  34743. name, maxWidth, textFont, ellipsis,
  34744. {minChar: 2, placeholder: truncateOpt.placeholder}
  34745. )
  34746. : name;
  34747. var tooltipOpt = axisModel.get('tooltip', true);
  34748. var mainType = axisModel.mainType;
  34749. var formatterParams = {
  34750. componentType: mainType,
  34751. name: name,
  34752. $vars: ['name']
  34753. };
  34754. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  34755. var textEl = new Text({
  34756. // Id for animation
  34757. anid: 'name',
  34758. __fullText: name,
  34759. __truncatedText: truncatedText,
  34760. position: pos,
  34761. rotation: labelLayout.rotation,
  34762. silent: isSilent(axisModel),
  34763. z2: 1,
  34764. tooltip: (tooltipOpt && tooltipOpt.show)
  34765. ? extend({
  34766. content: name,
  34767. formatter: function () {
  34768. return name;
  34769. },
  34770. formatterParams: formatterParams
  34771. }, tooltipOpt)
  34772. : null
  34773. });
  34774. setTextStyle(textEl.style, textStyleModel, {
  34775. text: truncatedText,
  34776. textFont: textFont,
  34777. textFill: textStyleModel.getTextColor()
  34778. || axisModel.get('axisLine.lineStyle.color'),
  34779. textAlign: labelLayout.textAlign,
  34780. textVerticalAlign: labelLayout.textVerticalAlign
  34781. });
  34782. if (axisModel.get('triggerEvent')) {
  34783. textEl.eventData = makeAxisEventDataBase(axisModel);
  34784. textEl.eventData.targetType = 'axisName';
  34785. textEl.eventData.name = name;
  34786. }
  34787. // FIXME
  34788. this._dumbGroup.add(textEl);
  34789. textEl.updateTransform();
  34790. this.group.add(textEl);
  34791. textEl.decomposeTransform();
  34792. }
  34793. };
  34794. /**
  34795. * @public
  34796. * @static
  34797. * @param {Object} opt
  34798. * @param {number} axisRotation in radian
  34799. * @param {number} textRotation in radian
  34800. * @param {number} direction
  34801. * @return {Object} {
  34802. * rotation, // according to axis
  34803. * textAlign,
  34804. * textVerticalAlign
  34805. * }
  34806. */
  34807. var innerTextLayout = AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  34808. var rotationDiff = remRadian(textRotation - axisRotation);
  34809. var textAlign;
  34810. var textVerticalAlign;
  34811. if (isRadianAroundZero(rotationDiff)) { // Label is parallel with axis line.
  34812. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  34813. textAlign = 'center';
  34814. }
  34815. else if (isRadianAroundZero(rotationDiff - PI$2)) { // Label is inverse parallel with axis line.
  34816. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  34817. textAlign = 'center';
  34818. }
  34819. else {
  34820. textVerticalAlign = 'middle';
  34821. if (rotationDiff > 0 && rotationDiff < PI$2) {
  34822. textAlign = direction > 0 ? 'right' : 'left';
  34823. }
  34824. else {
  34825. textAlign = direction > 0 ? 'left' : 'right';
  34826. }
  34827. }
  34828. return {
  34829. rotation: rotationDiff,
  34830. textAlign: textAlign,
  34831. textVerticalAlign: textVerticalAlign
  34832. };
  34833. };
  34834. function endTextLayout(opt, textPosition, textRotate, extent) {
  34835. var rotationDiff = remRadian(textRotate - opt.rotation);
  34836. var textAlign;
  34837. var textVerticalAlign;
  34838. var inverse = extent[0] > extent[1];
  34839. var onLeft = (textPosition === 'start' && !inverse)
  34840. || (textPosition !== 'start' && inverse);
  34841. if (isRadianAroundZero(rotationDiff - PI$2 / 2)) {
  34842. textVerticalAlign = onLeft ? 'bottom' : 'top';
  34843. textAlign = 'center';
  34844. }
  34845. else if (isRadianAroundZero(rotationDiff - PI$2 * 1.5)) {
  34846. textVerticalAlign = onLeft ? 'top' : 'bottom';
  34847. textAlign = 'center';
  34848. }
  34849. else {
  34850. textVerticalAlign = 'middle';
  34851. if (rotationDiff < PI$2 * 1.5 && rotationDiff > PI$2 / 2) {
  34852. textAlign = onLeft ? 'left' : 'right';
  34853. }
  34854. else {
  34855. textAlign = onLeft ? 'right' : 'left';
  34856. }
  34857. }
  34858. return {
  34859. rotation: rotationDiff,
  34860. textAlign: textAlign,
  34861. textVerticalAlign: textVerticalAlign
  34862. };
  34863. }
  34864. function isSilent(axisModel) {
  34865. var tooltipOpt = axisModel.get('tooltip');
  34866. return axisModel.get('silent')
  34867. // Consider mouse cursor, add these restrictions.
  34868. || !(
  34869. axisModel.get('triggerEvent') || (tooltipOpt && tooltipOpt.show)
  34870. );
  34871. }
  34872. function fixMinMaxLabelShow(axisModel, labelEls, tickEls) {
  34873. if (shouldShowAllLabels(axisModel.axis)) {
  34874. return;
  34875. }
  34876. // If min or max are user set, we need to check
  34877. // If the tick on min(max) are overlap on their neighbour tick
  34878. // If they are overlapped, we need to hide the min(max) tick label
  34879. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  34880. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  34881. // FIXME
  34882. // Have not consider onBand yet, where tick els is more than label els.
  34883. labelEls = labelEls || [];
  34884. tickEls = tickEls || [];
  34885. var firstLabel = labelEls[0];
  34886. var nextLabel = labelEls[1];
  34887. var lastLabel = labelEls[labelEls.length - 1];
  34888. var prevLabel = labelEls[labelEls.length - 2];
  34889. var firstTick = tickEls[0];
  34890. var nextTick = tickEls[1];
  34891. var lastTick = tickEls[tickEls.length - 1];
  34892. var prevTick = tickEls[tickEls.length - 2];
  34893. if (showMinLabel === false) {
  34894. ignoreEl(firstLabel);
  34895. ignoreEl(firstTick);
  34896. }
  34897. else if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  34898. if (showMinLabel) {
  34899. ignoreEl(nextLabel);
  34900. ignoreEl(nextTick);
  34901. }
  34902. else {
  34903. ignoreEl(firstLabel);
  34904. ignoreEl(firstTick);
  34905. }
  34906. }
  34907. if (showMaxLabel === false) {
  34908. ignoreEl(lastLabel);
  34909. ignoreEl(lastTick);
  34910. }
  34911. else if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  34912. if (showMaxLabel) {
  34913. ignoreEl(prevLabel);
  34914. ignoreEl(prevTick);
  34915. }
  34916. else {
  34917. ignoreEl(lastLabel);
  34918. ignoreEl(lastTick);
  34919. }
  34920. }
  34921. }
  34922. function ignoreEl(el) {
  34923. el && (el.ignore = true);
  34924. }
  34925. function isTwoLabelOverlapped(current, next, labelLayout) {
  34926. // current and next has the same rotation.
  34927. var firstRect = current && current.getBoundingRect().clone();
  34928. var nextRect = next && next.getBoundingRect().clone();
  34929. if (!firstRect || !nextRect) {
  34930. return;
  34931. }
  34932. // When checking intersect of two rotated labels, we use mRotationBack
  34933. // to avoid that boundingRect is enlarge when using `boundingRect.applyTransform`.
  34934. var mRotationBack = identity([]);
  34935. rotate(mRotationBack, mRotationBack, -current.rotation);
  34936. firstRect.applyTransform(mul$1([], mRotationBack, current.getLocalTransform()));
  34937. nextRect.applyTransform(mul$1([], mRotationBack, next.getLocalTransform()));
  34938. return firstRect.intersect(nextRect);
  34939. }
  34940. function isNameLocationCenter(nameLocation) {
  34941. return nameLocation === 'middle' || nameLocation === 'center';
  34942. }
  34943. function buildAxisTick(axisBuilder, axisModel, opt) {
  34944. var axis = axisModel.axis;
  34945. if (!axisModel.get('axisTick.show') || axis.scale.isBlank()) {
  34946. return;
  34947. }
  34948. var tickModel = axisModel.getModel('axisTick');
  34949. var lineStyleModel = tickModel.getModel('lineStyle');
  34950. var tickLen = tickModel.get('length');
  34951. var ticksCoords = axis.getTicksCoords();
  34952. var pt1 = [];
  34953. var pt2 = [];
  34954. var matrix = axisBuilder._transform;
  34955. var tickEls = [];
  34956. for (var i = 0; i < ticksCoords.length; i++) {
  34957. var tickCoord = ticksCoords[i].coord;
  34958. pt1[0] = tickCoord;
  34959. pt1[1] = 0;
  34960. pt2[0] = tickCoord;
  34961. pt2[1] = opt.tickDirection * tickLen;
  34962. if (matrix) {
  34963. applyTransform(pt1, pt1, matrix);
  34964. applyTransform(pt2, pt2, matrix);
  34965. }
  34966. // Tick line, Not use group transform to have better line draw
  34967. var tickEl = new Line(subPixelOptimizeLine({
  34968. // Id for animation
  34969. anid: 'tick_' + ticksCoords[i].tickValue,
  34970. shape: {
  34971. x1: pt1[0],
  34972. y1: pt1[1],
  34973. x2: pt2[0],
  34974. y2: pt2[1]
  34975. },
  34976. style: defaults(
  34977. lineStyleModel.getLineStyle(),
  34978. {
  34979. stroke: axisModel.get('axisLine.lineStyle.color')
  34980. }
  34981. ),
  34982. z2: 2,
  34983. silent: true
  34984. }));
  34985. axisBuilder.group.add(tickEl);
  34986. tickEls.push(tickEl);
  34987. }
  34988. return tickEls;
  34989. }
  34990. function buildAxisLabel(axisBuilder, axisModel, opt) {
  34991. var axis = axisModel.axis;
  34992. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  34993. if (!show || axis.scale.isBlank()) {
  34994. return;
  34995. }
  34996. var labelModel = axisModel.getModel('axisLabel');
  34997. var labelMargin = labelModel.get('margin');
  34998. var labels = axis.getViewLabels();
  34999. // Special label rotate.
  35000. var labelRotation = (
  35001. retrieve(opt.labelRotate, labelModel.get('rotate')) || 0
  35002. ) * PI$2 / 180;
  35003. var labelLayout = innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
  35004. var rawCategoryData = axisModel.getCategories(true);
  35005. var labelEls = [];
  35006. var silent = isSilent(axisModel);
  35007. var triggerEvent = axisModel.get('triggerEvent');
  35008. each$1(labels, function (labelItem, index) {
  35009. var tickValue = labelItem.tickValue;
  35010. var formattedLabel = labelItem.formattedLabel;
  35011. var rawLabel = labelItem.rawLabel;
  35012. var itemLabelModel = labelModel;
  35013. if (rawCategoryData && rawCategoryData[tickValue] && rawCategoryData[tickValue].textStyle) {
  35014. itemLabelModel = new Model(
  35015. rawCategoryData[tickValue].textStyle, labelModel, axisModel.ecModel
  35016. );
  35017. }
  35018. var textColor = itemLabelModel.getTextColor()
  35019. || axisModel.get('axisLine.lineStyle.color');
  35020. var tickCoord = axis.dataToCoord(tickValue);
  35021. var pos = [
  35022. tickCoord,
  35023. opt.labelOffset + opt.labelDirection * labelMargin
  35024. ];
  35025. var textEl = new Text({
  35026. // Id for animation
  35027. anid: 'label_' + tickValue,
  35028. position: pos,
  35029. rotation: labelLayout.rotation,
  35030. silent: silent,
  35031. z2: 10
  35032. });
  35033. setTextStyle(textEl.style, itemLabelModel, {
  35034. text: formattedLabel,
  35035. textAlign: itemLabelModel.getShallow('align', true)
  35036. || labelLayout.textAlign,
  35037. textVerticalAlign: itemLabelModel.getShallow('verticalAlign', true)
  35038. || itemLabelModel.getShallow('baseline', true)
  35039. || labelLayout.textVerticalAlign,
  35040. textFill: typeof textColor === 'function'
  35041. ? textColor(
  35042. // (1) In category axis with data zoom, tick is not the original
  35043. // index of axis.data. So tick should not be exposed to user
  35044. // in category axis.
  35045. // (2) Compatible with previous version, which always use formatted label as
  35046. // input. But in interval scale the formatted label is like '223,445', which
  35047. // maked user repalce ','. So we modify it to return original val but remain
  35048. // it as 'string' to avoid error in replacing.
  35049. axis.type === 'category'
  35050. ? rawLabel
  35051. : axis.type === 'value'
  35052. ? tickValue + ''
  35053. : tickValue,
  35054. index
  35055. )
  35056. : textColor
  35057. });
  35058. // Pack data for mouse event
  35059. if (triggerEvent) {
  35060. textEl.eventData = makeAxisEventDataBase(axisModel);
  35061. textEl.eventData.targetType = 'axisLabel';
  35062. textEl.eventData.value = rawLabel;
  35063. }
  35064. // FIXME
  35065. axisBuilder._dumbGroup.add(textEl);
  35066. textEl.updateTransform();
  35067. labelEls.push(textEl);
  35068. axisBuilder.group.add(textEl);
  35069. textEl.decomposeTransform();
  35070. });
  35071. return labelEls;
  35072. }
  35073. /*
  35074. * Licensed to the Apache Software Foundation (ASF) under one
  35075. * or more contributor license agreements. See the NOTICE file
  35076. * distributed with this work for additional information
  35077. * regarding copyright ownership. The ASF licenses this file
  35078. * to you under the Apache License, Version 2.0 (the
  35079. * "License"); you may not use this file except in compliance
  35080. * with the License. You may obtain a copy of the License at
  35081. *
  35082. * http://www.apache.org/licenses/LICENSE-2.0
  35083. *
  35084. * Unless required by applicable law or agreed to in writing,
  35085. * software distributed under the License is distributed on an
  35086. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35087. * KIND, either express or implied. See the License for the
  35088. * specific language governing permissions and limitations
  35089. * under the License.
  35090. */
  35091. var each$6 = each$1;
  35092. var curry$1 = curry;
  35093. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  35094. // allAxesInfo should be updated when setOption performed.
  35095. function collect(ecModel, api) {
  35096. var result = {
  35097. /**
  35098. * key: makeKey(axis.model)
  35099. * value: {
  35100. * axis,
  35101. * coordSys,
  35102. * axisPointerModel,
  35103. * triggerTooltip,
  35104. * involveSeries,
  35105. * snap,
  35106. * seriesModels,
  35107. * seriesDataCount
  35108. * }
  35109. */
  35110. axesInfo: {},
  35111. seriesInvolved: false,
  35112. /**
  35113. * key: makeKey(coordSys.model)
  35114. * value: Object: key makeKey(axis.model), value: axisInfo
  35115. */
  35116. coordSysAxesInfo: {},
  35117. coordSysMap: {}
  35118. };
  35119. collectAxesInfo(result, ecModel, api);
  35120. // Check seriesInvolved for performance, in case too many series in some chart.
  35121. result.seriesInvolved && collectSeriesInfo(result, ecModel);
  35122. return result;
  35123. }
  35124. function collectAxesInfo(result, ecModel, api) {
  35125. var globalTooltipModel = ecModel.getComponent('tooltip');
  35126. var globalAxisPointerModel = ecModel.getComponent('axisPointer');
  35127. // links can only be set on global.
  35128. var linksOption = globalAxisPointerModel.get('link', true) || [];
  35129. var linkGroups = [];
  35130. // Collect axes info.
  35131. each$6(api.getCoordinateSystems(), function (coordSys) {
  35132. // Some coordinate system do not support axes, like geo.
  35133. if (!coordSys.axisPointerEnabled) {
  35134. return;
  35135. }
  35136. var coordSysKey = makeKey(coordSys.model);
  35137. var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
  35138. result.coordSysMap[coordSysKey] = coordSys;
  35139. // Set tooltip (like 'cross') is a convienent way to show axisPointer
  35140. // for user. So we enable seting tooltip on coordSys model.
  35141. var coordSysModel = coordSys.model;
  35142. var baseTooltipModel = coordSysModel.getModel('tooltip', globalTooltipModel);
  35143. each$6(coordSys.getAxes(), curry$1(saveTooltipAxisInfo, false, null));
  35144. // If axis tooltip used, choose tooltip axis for each coordSys.
  35145. // Notice this case: coordSys is `grid` but not `cartesian2D` here.
  35146. if (coordSys.getTooltipAxes
  35147. && globalTooltipModel
  35148. // If tooltip.showContent is set as false, tooltip will not
  35149. // show but axisPointer will show as normal.
  35150. && baseTooltipModel.get('show')
  35151. ) {
  35152. // Compatible with previous logic. But series.tooltip.trigger: 'axis'
  35153. // or series.data[n].tooltip.trigger: 'axis' are not support any more.
  35154. var triggerAxis = baseTooltipModel.get('trigger') === 'axis';
  35155. var cross = baseTooltipModel.get('axisPointer.type') === 'cross';
  35156. var tooltipAxes = coordSys.getTooltipAxes(baseTooltipModel.get('axisPointer.axis'));
  35157. if (triggerAxis || cross) {
  35158. each$6(tooltipAxes.baseAxes, curry$1(
  35159. saveTooltipAxisInfo, cross ? 'cross' : true, triggerAxis
  35160. ));
  35161. }
  35162. if (cross) {
  35163. each$6(tooltipAxes.otherAxes, curry$1(saveTooltipAxisInfo, 'cross', false));
  35164. }
  35165. }
  35166. // fromTooltip: true | false | 'cross'
  35167. // triggerTooltip: true | false | null
  35168. function saveTooltipAxisInfo(fromTooltip, triggerTooltip, axis) {
  35169. var axisPointerModel = axis.model.getModel('axisPointer', globalAxisPointerModel);
  35170. var axisPointerShow = axisPointerModel.get('show');
  35171. if (!axisPointerShow || (
  35172. axisPointerShow === 'auto'
  35173. && !fromTooltip
  35174. && !isHandleTrigger(axisPointerModel)
  35175. )) {
  35176. return;
  35177. }
  35178. if (triggerTooltip == null) {
  35179. triggerTooltip = axisPointerModel.get('triggerTooltip');
  35180. }
  35181. axisPointerModel = fromTooltip
  35182. ? makeAxisPointerModel(
  35183. axis, baseTooltipModel, globalAxisPointerModel, ecModel,
  35184. fromTooltip, triggerTooltip
  35185. )
  35186. : axisPointerModel;
  35187. var snap = axisPointerModel.get('snap');
  35188. var key = makeKey(axis.model);
  35189. var involveSeries = triggerTooltip || snap || axis.type === 'category';
  35190. // If result.axesInfo[key] exist, override it (tooltip has higher priority).
  35191. var axisInfo = result.axesInfo[key] = {
  35192. key: key,
  35193. axis: axis,
  35194. coordSys: coordSys,
  35195. axisPointerModel: axisPointerModel,
  35196. triggerTooltip: triggerTooltip,
  35197. involveSeries: involveSeries,
  35198. snap: snap,
  35199. useHandle: isHandleTrigger(axisPointerModel),
  35200. seriesModels: []
  35201. };
  35202. axesInfoInCoordSys[key] = axisInfo;
  35203. result.seriesInvolved |= involveSeries;
  35204. var groupIndex = getLinkGroupIndex(linksOption, axis);
  35205. if (groupIndex != null) {
  35206. var linkGroup = linkGroups[groupIndex] || (linkGroups[groupIndex] = {axesInfo: {}});
  35207. linkGroup.axesInfo[key] = axisInfo;
  35208. linkGroup.mapper = linksOption[groupIndex].mapper;
  35209. axisInfo.linkGroup = linkGroup;
  35210. }
  35211. }
  35212. });
  35213. }
  35214. function makeAxisPointerModel(
  35215. axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip
  35216. ) {
  35217. var tooltipAxisPointerModel = baseTooltipModel.getModel('axisPointer');
  35218. var volatileOption = {};
  35219. each$6(
  35220. [
  35221. 'type', 'snap', 'lineStyle', 'shadowStyle', 'label',
  35222. 'animation', 'animationDurationUpdate', 'animationEasingUpdate', 'z'
  35223. ],
  35224. function (field) {
  35225. volatileOption[field] = clone(tooltipAxisPointerModel.get(field));
  35226. }
  35227. );
  35228. // category axis do not auto snap, otherwise some tick that do not
  35229. // has value can not be hovered. value/time/log axis default snap if
  35230. // triggered from tooltip and trigger tooltip.
  35231. volatileOption.snap = axis.type !== 'category' && !!triggerTooltip;
  35232. // Compatibel with previous behavior, tooltip axis do not show label by default.
  35233. // Only these properties can be overrided from tooltip to axisPointer.
  35234. if (tooltipAxisPointerModel.get('type') === 'cross') {
  35235. volatileOption.type = 'line';
  35236. }
  35237. var labelOption = volatileOption.label || (volatileOption.label = {});
  35238. // Follow the convention, do not show label when triggered by tooltip by default.
  35239. labelOption.show == null && (labelOption.show = false);
  35240. if (fromTooltip === 'cross') {
  35241. // When 'cross', both axes show labels.
  35242. var tooltipAxisPointerLabelShow = tooltipAxisPointerModel.get('label.show');
  35243. labelOption.show = tooltipAxisPointerLabelShow != null ? tooltipAxisPointerLabelShow : true;
  35244. // If triggerTooltip, this is a base axis, which should better not use cross style
  35245. // (cross style is dashed by default)
  35246. if (!triggerTooltip) {
  35247. var crossStyle = volatileOption.lineStyle = tooltipAxisPointerModel.get('crossStyle');
  35248. crossStyle && defaults(labelOption, crossStyle.textStyle);
  35249. }
  35250. }
  35251. return axis.model.getModel(
  35252. 'axisPointer',
  35253. new Model(volatileOption, globalAxisPointerModel, ecModel)
  35254. );
  35255. }
  35256. function collectSeriesInfo(result, ecModel) {
  35257. // Prepare data for axis trigger
  35258. ecModel.eachSeries(function (seriesModel) {
  35259. // Notice this case: this coordSys is `cartesian2D` but not `grid`.
  35260. var coordSys = seriesModel.coordinateSystem;
  35261. var seriesTooltipTrigger = seriesModel.get('tooltip.trigger', true);
  35262. var seriesTooltipShow = seriesModel.get('tooltip.show', true);
  35263. if (!coordSys
  35264. || seriesTooltipTrigger === 'none'
  35265. || seriesTooltipTrigger === false
  35266. || seriesTooltipTrigger === 'item'
  35267. || seriesTooltipShow === false
  35268. || seriesModel.get('axisPointer.show', true) === false
  35269. ) {
  35270. return;
  35271. }
  35272. each$6(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
  35273. var axis = axisInfo.axis;
  35274. if (coordSys.getAxis(axis.dim) === axis) {
  35275. axisInfo.seriesModels.push(seriesModel);
  35276. axisInfo.seriesDataCount == null && (axisInfo.seriesDataCount = 0);
  35277. axisInfo.seriesDataCount += seriesModel.getData().count();
  35278. }
  35279. });
  35280. }, this);
  35281. }
  35282. /**
  35283. * For example:
  35284. * {
  35285. * axisPointer: {
  35286. * links: [{
  35287. * xAxisIndex: [2, 4],
  35288. * yAxisIndex: 'all'
  35289. * }, {
  35290. * xAxisId: ['a5', 'a7'],
  35291. * xAxisName: 'xxx'
  35292. * }]
  35293. * }
  35294. * }
  35295. */
  35296. function getLinkGroupIndex(linksOption, axis) {
  35297. var axisModel = axis.model;
  35298. var dim = axis.dim;
  35299. for (var i = 0; i < linksOption.length; i++) {
  35300. var linkOption = linksOption[i] || {};
  35301. if (checkPropInLink(linkOption[dim + 'AxisId'], axisModel.id)
  35302. || checkPropInLink(linkOption[dim + 'AxisIndex'], axisModel.componentIndex)
  35303. || checkPropInLink(linkOption[dim + 'AxisName'], axisModel.name)
  35304. ) {
  35305. return i;
  35306. }
  35307. }
  35308. }
  35309. function checkPropInLink(linkPropValue, axisPropValue) {
  35310. return linkPropValue === 'all'
  35311. || (isArray(linkPropValue) && indexOf(linkPropValue, axisPropValue) >= 0)
  35312. || linkPropValue === axisPropValue;
  35313. }
  35314. function fixValue(axisModel) {
  35315. var axisInfo = getAxisInfo(axisModel);
  35316. if (!axisInfo) {
  35317. return;
  35318. }
  35319. var axisPointerModel = axisInfo.axisPointerModel;
  35320. var scale = axisInfo.axis.scale;
  35321. var option = axisPointerModel.option;
  35322. var status = axisPointerModel.get('status');
  35323. var value = axisPointerModel.get('value');
  35324. // Parse init value for category and time axis.
  35325. if (value != null) {
  35326. value = scale.parse(value);
  35327. }
  35328. var useHandle = isHandleTrigger(axisPointerModel);
  35329. // If `handle` used, `axisPointer` will always be displayed, so value
  35330. // and status should be initialized.
  35331. if (status == null) {
  35332. option.status = useHandle ? 'show' : 'hide';
  35333. }
  35334. var extent = scale.getExtent().slice();
  35335. extent[0] > extent[1] && extent.reverse();
  35336. if (// Pick a value on axis when initializing.
  35337. value == null
  35338. // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  35339. // where we should re-pick a value to keep `handle` displaying normally.
  35340. || value > extent[1]
  35341. ) {
  35342. // Make handle displayed on the end of the axis when init, which looks better.
  35343. value = extent[1];
  35344. }
  35345. if (value < extent[0]) {
  35346. value = extent[0];
  35347. }
  35348. option.value = value;
  35349. if (useHandle) {
  35350. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  35351. }
  35352. }
  35353. function getAxisInfo(axisModel) {
  35354. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  35355. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  35356. }
  35357. function getAxisPointerModel(axisModel) {
  35358. var axisInfo = getAxisInfo(axisModel);
  35359. return axisInfo && axisInfo.axisPointerModel;
  35360. }
  35361. function isHandleTrigger(axisPointerModel) {
  35362. return !!axisPointerModel.get('handle.show');
  35363. }
  35364. /**
  35365. * @param {module:echarts/model/Model} model
  35366. * @return {string} unique key
  35367. */
  35368. function makeKey(model) {
  35369. return model.type + '||' + model.id;
  35370. }
  35371. /*
  35372. * Licensed to the Apache Software Foundation (ASF) under one
  35373. * or more contributor license agreements. See the NOTICE file
  35374. * distributed with this work for additional information
  35375. * regarding copyright ownership. The ASF licenses this file
  35376. * to you under the Apache License, Version 2.0 (the
  35377. * "License"); you may not use this file except in compliance
  35378. * with the License. You may obtain a copy of the License at
  35379. *
  35380. * http://www.apache.org/licenses/LICENSE-2.0
  35381. *
  35382. * Unless required by applicable law or agreed to in writing,
  35383. * software distributed under the License is distributed on an
  35384. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35385. * KIND, either express or implied. See the License for the
  35386. * specific language governing permissions and limitations
  35387. * under the License.
  35388. */
  35389. /**
  35390. * Base class of AxisView.
  35391. */
  35392. var AxisView = extendComponentView({
  35393. type: 'axis',
  35394. /**
  35395. * @private
  35396. */
  35397. _axisPointer: null,
  35398. /**
  35399. * @protected
  35400. * @type {string}
  35401. */
  35402. axisPointerClass: null,
  35403. /**
  35404. * @override
  35405. */
  35406. render: function (axisModel, ecModel, api, payload) {
  35407. // FIXME
  35408. // This process should proformed after coordinate systems updated
  35409. // (axis scale updated), and should be performed each time update.
  35410. // So put it here temporarily, although it is not appropriate to
  35411. // put a model-writing procedure in `view`.
  35412. this.axisPointerClass && fixValue(axisModel);
  35413. AxisView.superApply(this, 'render', arguments);
  35414. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  35415. },
  35416. /**
  35417. * Action handler.
  35418. * @public
  35419. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  35420. * @param {module:echarts/model/Global} ecModel
  35421. * @param {module:echarts/ExtensionAPI} api
  35422. * @param {Object} payload
  35423. */
  35424. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  35425. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  35426. },
  35427. /**
  35428. * @override
  35429. */
  35430. remove: function (ecModel, api) {
  35431. var axisPointer = this._axisPointer;
  35432. axisPointer && axisPointer.remove(api);
  35433. AxisView.superApply(this, 'remove', arguments);
  35434. },
  35435. /**
  35436. * @override
  35437. */
  35438. dispose: function (ecModel, api) {
  35439. disposeAxisPointer(this, api);
  35440. AxisView.superApply(this, 'dispose', arguments);
  35441. }
  35442. });
  35443. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  35444. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  35445. if (!Clazz) {
  35446. return;
  35447. }
  35448. var axisPointerModel = getAxisPointerModel(axisModel);
  35449. axisPointerModel
  35450. ? (axisView._axisPointer || (axisView._axisPointer = new Clazz()))
  35451. .render(axisModel, axisPointerModel, api, forceRender)
  35452. : disposeAxisPointer(axisView, api);
  35453. }
  35454. function disposeAxisPointer(axisView, ecModel, api) {
  35455. var axisPointer = axisView._axisPointer;
  35456. axisPointer && axisPointer.dispose(ecModel, api);
  35457. axisView._axisPointer = null;
  35458. }
  35459. var axisPointerClazz = [];
  35460. AxisView.registerAxisPointerClass = function (type, clazz) {
  35461. if (__DEV__) {
  35462. if (axisPointerClazz[type]) {
  35463. throw new Error('axisPointer ' + type + ' exists');
  35464. }
  35465. }
  35466. axisPointerClazz[type] = clazz;
  35467. };
  35468. AxisView.getAxisPointerClass = function (type) {
  35469. return type && axisPointerClazz[type];
  35470. };
  35471. /*
  35472. * Licensed to the Apache Software Foundation (ASF) under one
  35473. * or more contributor license agreements. See the NOTICE file
  35474. * distributed with this work for additional information
  35475. * regarding copyright ownership. The ASF licenses this file
  35476. * to you under the Apache License, Version 2.0 (the
  35477. * "License"); you may not use this file except in compliance
  35478. * with the License. You may obtain a copy of the License at
  35479. *
  35480. * http://www.apache.org/licenses/LICENSE-2.0
  35481. *
  35482. * Unless required by applicable law or agreed to in writing,
  35483. * software distributed under the License is distributed on an
  35484. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35485. * KIND, either express or implied. See the License for the
  35486. * specific language governing permissions and limitations
  35487. * under the License.
  35488. */
  35489. /**
  35490. * Can only be called after coordinate system creation stage.
  35491. * (Can be called before coordinate system update stage).
  35492. *
  35493. * @param {Object} opt {labelInside}
  35494. * @return {Object} {
  35495. * position, rotation, labelDirection, labelOffset,
  35496. * tickDirection, labelRotate, z2
  35497. * }
  35498. */
  35499. function layout$1(gridModel, axisModel, opt) {
  35500. opt = opt || {};
  35501. var grid = gridModel.coordinateSystem;
  35502. var axis = axisModel.axis;
  35503. var layout = {};
  35504. var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
  35505. var rawAxisPosition = axis.position;
  35506. var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
  35507. var axisDim = axis.dim;
  35508. var rect = grid.getRect();
  35509. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  35510. var idx = {left: 0, right: 1, top: 0, bottom: 1, onZero: 2};
  35511. var axisOffset = axisModel.get('offset') || 0;
  35512. var posBound = axisDim === 'x'
  35513. ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset]
  35514. : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  35515. if (otherAxisOnZeroOf) {
  35516. var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
  35517. posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  35518. }
  35519. // Axis position
  35520. layout.position = [
  35521. axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0],
  35522. axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]
  35523. ];
  35524. // Axis rotation
  35525. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  35526. // Tick and label direction, x y is axisDim
  35527. var dirMap = {top: -1, bottom: 1, left: -1, right: 1};
  35528. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  35529. layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
  35530. if (axisModel.get('axisTick.inside')) {
  35531. layout.tickDirection = -layout.tickDirection;
  35532. }
  35533. if (retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  35534. layout.labelDirection = -layout.labelDirection;
  35535. }
  35536. // Special label rotation
  35537. var labelRotate = axisModel.get('axisLabel.rotate');
  35538. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
  35539. // Over splitLine and splitArea
  35540. layout.z2 = 1;
  35541. return layout;
  35542. }
  35543. /*
  35544. * Licensed to the Apache Software Foundation (ASF) under one
  35545. * or more contributor license agreements. See the NOTICE file
  35546. * distributed with this work for additional information
  35547. * regarding copyright ownership. The ASF licenses this file
  35548. * to you under the Apache License, Version 2.0 (the
  35549. * "License"); you may not use this file except in compliance
  35550. * with the License. You may obtain a copy of the License at
  35551. *
  35552. * http://www.apache.org/licenses/LICENSE-2.0
  35553. *
  35554. * Unless required by applicable law or agreed to in writing,
  35555. * software distributed under the License is distributed on an
  35556. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35557. * KIND, either express or implied. See the License for the
  35558. * specific language governing permissions and limitations
  35559. * under the License.
  35560. */
  35561. var axisBuilderAttrs = [
  35562. 'axisLine', 'axisTickLabel', 'axisName'
  35563. ];
  35564. var selfBuilderAttrs = [
  35565. 'splitArea', 'splitLine'
  35566. ];
  35567. // function getAlignWithLabel(model, axisModel) {
  35568. // var alignWithLabel = model.get('alignWithLabel');
  35569. // if (alignWithLabel === 'auto') {
  35570. // alignWithLabel = axisModel.get('axisTick.alignWithLabel');
  35571. // }
  35572. // return alignWithLabel;
  35573. // }
  35574. var CartesianAxisView = AxisView.extend({
  35575. type: 'cartesianAxis',
  35576. axisPointerClass: 'CartesianAxisPointer',
  35577. /**
  35578. * @override
  35579. */
  35580. render: function (axisModel, ecModel, api, payload) {
  35581. this.group.removeAll();
  35582. var oldAxisGroup = this._axisGroup;
  35583. this._axisGroup = new Group();
  35584. this.group.add(this._axisGroup);
  35585. if (!axisModel.get('show')) {
  35586. return;
  35587. }
  35588. var gridModel = axisModel.getCoordSysModel();
  35589. var layout = layout$1(gridModel, axisModel);
  35590. var axisBuilder = new AxisBuilder(axisModel, layout);
  35591. each$1(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  35592. this._axisGroup.add(axisBuilder.getGroup());
  35593. each$1(selfBuilderAttrs, function (name) {
  35594. if (axisModel.get(name + '.show')) {
  35595. this['_' + name](axisModel, gridModel);
  35596. }
  35597. }, this);
  35598. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  35599. CartesianAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  35600. },
  35601. remove: function () {
  35602. this._splitAreaColors = null;
  35603. },
  35604. /**
  35605. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  35606. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  35607. * @private
  35608. */
  35609. _splitLine: function (axisModel, gridModel) {
  35610. var axis = axisModel.axis;
  35611. if (axis.scale.isBlank()) {
  35612. return;
  35613. }
  35614. var splitLineModel = axisModel.getModel('splitLine');
  35615. var lineStyleModel = splitLineModel.getModel('lineStyle');
  35616. var lineColors = lineStyleModel.get('color');
  35617. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  35618. var gridRect = gridModel.coordinateSystem.getRect();
  35619. var isHorizontal = axis.isHorizontal();
  35620. var lineCount = 0;
  35621. var ticksCoords = axis.getTicksCoords({
  35622. tickModel: splitLineModel
  35623. });
  35624. var p1 = [];
  35625. var p2 = [];
  35626. // Simple optimization
  35627. // Batching the lines if color are the same
  35628. var lineStyle = lineStyleModel.getLineStyle();
  35629. for (var i = 0; i < ticksCoords.length; i++) {
  35630. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  35631. if (isHorizontal) {
  35632. p1[0] = tickCoord;
  35633. p1[1] = gridRect.y;
  35634. p2[0] = tickCoord;
  35635. p2[1] = gridRect.y + gridRect.height;
  35636. }
  35637. else {
  35638. p1[0] = gridRect.x;
  35639. p1[1] = tickCoord;
  35640. p2[0] = gridRect.x + gridRect.width;
  35641. p2[1] = tickCoord;
  35642. }
  35643. var colorIndex = (lineCount++) % lineColors.length;
  35644. var tickValue = ticksCoords[i].tickValue;
  35645. this._axisGroup.add(new Line(subPixelOptimizeLine({
  35646. anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
  35647. shape: {
  35648. x1: p1[0],
  35649. y1: p1[1],
  35650. x2: p2[0],
  35651. y2: p2[1]
  35652. },
  35653. style: defaults({
  35654. stroke: lineColors[colorIndex]
  35655. }, lineStyle),
  35656. silent: true
  35657. })));
  35658. }
  35659. },
  35660. /**
  35661. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  35662. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  35663. * @private
  35664. */
  35665. _splitArea: function (axisModel, gridModel) {
  35666. var axis = axisModel.axis;
  35667. if (axis.scale.isBlank()) {
  35668. return;
  35669. }
  35670. var splitAreaModel = axisModel.getModel('splitArea');
  35671. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  35672. var areaColors = areaStyleModel.get('color');
  35673. var gridRect = gridModel.coordinateSystem.getRect();
  35674. var ticksCoords = axis.getTicksCoords({
  35675. tickModel: splitAreaModel,
  35676. clamp: true
  35677. });
  35678. if (!ticksCoords.length) {
  35679. return;
  35680. }
  35681. // For Making appropriate splitArea animation, the color and anid
  35682. // should be corresponding to previous one if possible.
  35683. var areaColorsLen = areaColors.length;
  35684. var lastSplitAreaColors = this._splitAreaColors;
  35685. var newSplitAreaColors = createHashMap();
  35686. var colorIndex = 0;
  35687. if (lastSplitAreaColors) {
  35688. for (var i = 0; i < ticksCoords.length; i++) {
  35689. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  35690. if (cIndex != null) {
  35691. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  35692. break;
  35693. }
  35694. }
  35695. }
  35696. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  35697. var areaStyle = areaStyleModel.getAreaStyle();
  35698. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  35699. for (var i = 1; i < ticksCoords.length; i++) {
  35700. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  35701. var x;
  35702. var y;
  35703. var width;
  35704. var height;
  35705. if (axis.isHorizontal()) {
  35706. x = prev;
  35707. y = gridRect.y;
  35708. width = tickCoord - x;
  35709. height = gridRect.height;
  35710. prev = x + width;
  35711. }
  35712. else {
  35713. x = gridRect.x;
  35714. y = prev;
  35715. width = gridRect.width;
  35716. height = tickCoord - y;
  35717. prev = y + height;
  35718. }
  35719. var tickValue = ticksCoords[i - 1].tickValue;
  35720. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  35721. this._axisGroup.add(new Rect({
  35722. anid: tickValue != null ? 'area_' + tickValue : null,
  35723. shape: {
  35724. x: x,
  35725. y: y,
  35726. width: width,
  35727. height: height
  35728. },
  35729. style: defaults({
  35730. fill: areaColors[colorIndex]
  35731. }, areaStyle),
  35732. silent: true
  35733. }));
  35734. colorIndex = (colorIndex + 1) % areaColorsLen;
  35735. }
  35736. this._splitAreaColors = newSplitAreaColors;
  35737. }
  35738. });
  35739. CartesianAxisView.extend({
  35740. type: 'xAxis'
  35741. });
  35742. CartesianAxisView.extend({
  35743. type: 'yAxis'
  35744. });
  35745. /*
  35746. * Licensed to the Apache Software Foundation (ASF) under one
  35747. * or more contributor license agreements. See the NOTICE file
  35748. * distributed with this work for additional information
  35749. * regarding copyright ownership. The ASF licenses this file
  35750. * to you under the Apache License, Version 2.0 (the
  35751. * "License"); you may not use this file except in compliance
  35752. * with the License. You may obtain a copy of the License at
  35753. *
  35754. * http://www.apache.org/licenses/LICENSE-2.0
  35755. *
  35756. * Unless required by applicable law or agreed to in writing,
  35757. * software distributed under the License is distributed on an
  35758. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35759. * KIND, either express or implied. See the License for the
  35760. * specific language governing permissions and limitations
  35761. * under the License.
  35762. */
  35763. /*
  35764. * Licensed to the Apache Software Foundation (ASF) under one
  35765. * or more contributor license agreements. See the NOTICE file
  35766. * distributed with this work for additional information
  35767. * regarding copyright ownership. The ASF licenses this file
  35768. * to you under the Apache License, Version 2.0 (the
  35769. * "License"); you may not use this file except in compliance
  35770. * with the License. You may obtain a copy of the License at
  35771. *
  35772. * http://www.apache.org/licenses/LICENSE-2.0
  35773. *
  35774. * Unless required by applicable law or agreed to in writing,
  35775. * software distributed under the License is distributed on an
  35776. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35777. * KIND, either express or implied. See the License for the
  35778. * specific language governing permissions and limitations
  35779. * under the License.
  35780. */
  35781. // Grid view
  35782. extendComponentView({
  35783. type: 'grid',
  35784. render: function (gridModel, ecModel) {
  35785. this.group.removeAll();
  35786. if (gridModel.get('show')) {
  35787. this.group.add(new Rect({
  35788. shape: gridModel.coordinateSystem.getRect(),
  35789. style: defaults({
  35790. fill: gridModel.get('backgroundColor')
  35791. }, gridModel.getItemStyle()),
  35792. silent: true,
  35793. z2: -1
  35794. }));
  35795. }
  35796. }
  35797. });
  35798. registerPreprocessor(function (option) {
  35799. // Only create grid when need
  35800. if (option.xAxis && option.yAxis && !option.grid) {
  35801. option.grid = {};
  35802. }
  35803. });
  35804. /*
  35805. * Licensed to the Apache Software Foundation (ASF) under one
  35806. * or more contributor license agreements. See the NOTICE file
  35807. * distributed with this work for additional information
  35808. * regarding copyright ownership. The ASF licenses this file
  35809. * to you under the Apache License, Version 2.0 (the
  35810. * "License"); you may not use this file except in compliance
  35811. * with the License. You may obtain a copy of the License at
  35812. *
  35813. * http://www.apache.org/licenses/LICENSE-2.0
  35814. *
  35815. * Unless required by applicable law or agreed to in writing,
  35816. * software distributed under the License is distributed on an
  35817. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35818. * KIND, either express or implied. See the License for the
  35819. * specific language governing permissions and limitations
  35820. * under the License.
  35821. */
  35822. // In case developer forget to include grid component
  35823. registerVisual(visualSymbol('line', 'circle', 'line'));
  35824. registerLayout(pointsLayout('line'));
  35825. // Down sample after filter
  35826. registerProcessor(
  35827. PRIORITY.PROCESSOR.STATISTIC,
  35828. dataSample('line')
  35829. );
  35830. /*
  35831. * Licensed to the Apache Software Foundation (ASF) under one
  35832. * or more contributor license agreements. See the NOTICE file
  35833. * distributed with this work for additional information
  35834. * regarding copyright ownership. The ASF licenses this file
  35835. * to you under the Apache License, Version 2.0 (the
  35836. * "License"); you may not use this file except in compliance
  35837. * with the License. You may obtain a copy of the License at
  35838. *
  35839. * http://www.apache.org/licenses/LICENSE-2.0
  35840. *
  35841. * Unless required by applicable law or agreed to in writing,
  35842. * software distributed under the License is distributed on an
  35843. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35844. * KIND, either express or implied. See the License for the
  35845. * specific language governing permissions and limitations
  35846. * under the License.
  35847. */
  35848. var BaseBarSeries = SeriesModel.extend({
  35849. type: 'series.__base_bar__',
  35850. getInitialData: function (option, ecModel) {
  35851. return createListFromArray(this.getSource(), this);
  35852. },
  35853. getMarkerPosition: function (value) {
  35854. var coordSys = this.coordinateSystem;
  35855. if (coordSys) {
  35856. // PENDING if clamp ?
  35857. var pt = coordSys.dataToPoint(coordSys.clampData(value));
  35858. var data = this.getData();
  35859. var offset = data.getLayout('offset');
  35860. var size = data.getLayout('size');
  35861. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  35862. pt[offsetIndex] += offset + size / 2;
  35863. return pt;
  35864. }
  35865. return [NaN, NaN];
  35866. },
  35867. defaultOption: {
  35868. zlevel: 0, // 一级层叠
  35869. z: 2, // 二级层叠
  35870. coordinateSystem: 'cartesian2d',
  35871. legendHoverLink: true,
  35872. // stack: null
  35873. // Cartesian coordinate system
  35874. // xAxisIndex: 0,
  35875. // yAxisIndex: 0,
  35876. // 最小高度改为0
  35877. barMinHeight: 0,
  35878. // 最小角度为0,仅对极坐标系下的柱状图有效
  35879. barMinAngle: 0,
  35880. // cursor: null,
  35881. large: false,
  35882. largeThreshold: 400,
  35883. progressive: 3e3,
  35884. progressiveChunkMode: 'mod',
  35885. // barMaxWidth: null,
  35886. // 默认自适应
  35887. // barWidth: null,
  35888. // 柱间距离,默认为柱形宽度的30%,可设固定值
  35889. // barGap: '30%',
  35890. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  35891. // barCategoryGap: '20%',
  35892. // label: {
  35893. // show: false
  35894. // },
  35895. itemStyle: {},
  35896. emphasis: {}
  35897. }
  35898. });
  35899. /*
  35900. * Licensed to the Apache Software Foundation (ASF) under one
  35901. * or more contributor license agreements. See the NOTICE file
  35902. * distributed with this work for additional information
  35903. * regarding copyright ownership. The ASF licenses this file
  35904. * to you under the Apache License, Version 2.0 (the
  35905. * "License"); you may not use this file except in compliance
  35906. * with the License. You may obtain a copy of the License at
  35907. *
  35908. * http://www.apache.org/licenses/LICENSE-2.0
  35909. *
  35910. * Unless required by applicable law or agreed to in writing,
  35911. * software distributed under the License is distributed on an
  35912. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35913. * KIND, either express or implied. See the License for the
  35914. * specific language governing permissions and limitations
  35915. * under the License.
  35916. */
  35917. BaseBarSeries.extend({
  35918. type: 'series.bar',
  35919. dependencies: ['grid', 'polar'],
  35920. brushSelector: 'rect',
  35921. /**
  35922. * @override
  35923. */
  35924. getProgressive: function () {
  35925. // Do not support progressive in normal mode.
  35926. return this.get('large')
  35927. ? this.get('progressive')
  35928. : false;
  35929. },
  35930. /**
  35931. * @override
  35932. */
  35933. getProgressiveThreshold: function () {
  35934. // Do not support progressive in normal mode.
  35935. var progressiveThreshold = this.get('progressiveThreshold');
  35936. var largeThreshold = this.get('largeThreshold');
  35937. if (largeThreshold > progressiveThreshold) {
  35938. progressiveThreshold = largeThreshold;
  35939. }
  35940. return progressiveThreshold;
  35941. }
  35942. });
  35943. /*
  35944. * Licensed to the Apache Software Foundation (ASF) under one
  35945. * or more contributor license agreements. See the NOTICE file
  35946. * distributed with this work for additional information
  35947. * regarding copyright ownership. The ASF licenses this file
  35948. * to you under the Apache License, Version 2.0 (the
  35949. * "License"); you may not use this file except in compliance
  35950. * with the License. You may obtain a copy of the License at
  35951. *
  35952. * http://www.apache.org/licenses/LICENSE-2.0
  35953. *
  35954. * Unless required by applicable law or agreed to in writing,
  35955. * software distributed under the License is distributed on an
  35956. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35957. * KIND, either express or implied. See the License for the
  35958. * specific language governing permissions and limitations
  35959. * under the License.
  35960. */
  35961. function setLabel(
  35962. normalStyle, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside
  35963. ) {
  35964. var labelModel = itemModel.getModel('label');
  35965. var hoverLabelModel = itemModel.getModel('emphasis.label');
  35966. setLabelStyle(
  35967. normalStyle, hoverStyle, labelModel, hoverLabelModel,
  35968. {
  35969. labelFetcher: seriesModel,
  35970. labelDataIndex: dataIndex,
  35971. defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
  35972. isRectText: true,
  35973. autoColor: color
  35974. }
  35975. );
  35976. fixPosition(normalStyle);
  35977. fixPosition(hoverStyle);
  35978. }
  35979. function fixPosition(style, labelPositionOutside) {
  35980. if (style.textPosition === 'outside') {
  35981. style.textPosition = labelPositionOutside;
  35982. }
  35983. }
  35984. /*
  35985. * Licensed to the Apache Software Foundation (ASF) under one
  35986. * or more contributor license agreements. See the NOTICE file
  35987. * distributed with this work for additional information
  35988. * regarding copyright ownership. The ASF licenses this file
  35989. * to you under the Apache License, Version 2.0 (the
  35990. * "License"); you may not use this file except in compliance
  35991. * with the License. You may obtain a copy of the License at
  35992. *
  35993. * http://www.apache.org/licenses/LICENSE-2.0
  35994. *
  35995. * Unless required by applicable law or agreed to in writing,
  35996. * software distributed under the License is distributed on an
  35997. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35998. * KIND, either express or implied. See the License for the
  35999. * specific language governing permissions and limitations
  36000. * under the License.
  36001. */
  36002. var getBarItemStyle = makeStyleMapper(
  36003. [
  36004. ['fill', 'color'],
  36005. ['stroke', 'borderColor'],
  36006. ['lineWidth', 'borderWidth'],
  36007. // Compatitable with 2
  36008. ['stroke', 'barBorderColor'],
  36009. ['lineWidth', 'barBorderWidth'],
  36010. ['opacity'],
  36011. ['shadowBlur'],
  36012. ['shadowOffsetX'],
  36013. ['shadowOffsetY'],
  36014. ['shadowColor']
  36015. ]
  36016. );
  36017. var barItemStyle = {
  36018. getBarItemStyle: function (excludes) {
  36019. var style = getBarItemStyle(this, excludes);
  36020. if (this.getBorderLineDash) {
  36021. var lineDash = this.getBorderLineDash();
  36022. lineDash && (style.lineDash = lineDash);
  36023. }
  36024. return style;
  36025. }
  36026. };
  36027. /*
  36028. * Licensed to the Apache Software Foundation (ASF) under one
  36029. * or more contributor license agreements. See the NOTICE file
  36030. * distributed with this work for additional information
  36031. * regarding copyright ownership. The ASF licenses this file
  36032. * to you under the Apache License, Version 2.0 (the
  36033. * "License"); you may not use this file except in compliance
  36034. * with the License. You may obtain a copy of the License at
  36035. *
  36036. * http://www.apache.org/licenses/LICENSE-2.0
  36037. *
  36038. * Unless required by applicable law or agreed to in writing,
  36039. * software distributed under the License is distributed on an
  36040. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36041. * KIND, either express or implied. See the License for the
  36042. * specific language governing permissions and limitations
  36043. * under the License.
  36044. */
  36045. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'barBorderWidth'];
  36046. // FIXME
  36047. // Just for compatible with ec2.
  36048. extend(Model.prototype, barItemStyle);
  36049. extendChartView({
  36050. type: 'bar',
  36051. render: function (seriesModel, ecModel, api) {
  36052. this._updateDrawMode(seriesModel);
  36053. var coordinateSystemType = seriesModel.get('coordinateSystem');
  36054. if (coordinateSystemType === 'cartesian2d'
  36055. || coordinateSystemType === 'polar'
  36056. ) {
  36057. this._isLargeDraw
  36058. ? this._renderLarge(seriesModel, ecModel, api)
  36059. : this._renderNormal(seriesModel, ecModel, api);
  36060. }
  36061. else if (__DEV__) {
  36062. console.warn('Only cartesian2d and polar supported for bar.');
  36063. }
  36064. return this.group;
  36065. },
  36066. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  36067. this._clear();
  36068. this._updateDrawMode(seriesModel);
  36069. },
  36070. incrementalRender: function (params, seriesModel, ecModel, api) {
  36071. // Do not support progressive in normal mode.
  36072. this._incrementalRenderLarge(params, seriesModel);
  36073. },
  36074. _updateDrawMode: function (seriesModel) {
  36075. var isLargeDraw = seriesModel.pipelineContext.large;
  36076. if (this._isLargeDraw == null || isLargeDraw ^ this._isLargeDraw) {
  36077. this._isLargeDraw = isLargeDraw;
  36078. this._clear();
  36079. }
  36080. },
  36081. _renderNormal: function (seriesModel, ecModel, api) {
  36082. var group = this.group;
  36083. var data = seriesModel.getData();
  36084. var oldData = this._data;
  36085. var coord = seriesModel.coordinateSystem;
  36086. var baseAxis = coord.getBaseAxis();
  36087. var isHorizontalOrRadial;
  36088. if (coord.type === 'cartesian2d') {
  36089. isHorizontalOrRadial = baseAxis.isHorizontal();
  36090. }
  36091. else if (coord.type === 'polar') {
  36092. isHorizontalOrRadial = baseAxis.dim === 'angle';
  36093. }
  36094. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  36095. data.diff(oldData)
  36096. .add(function (dataIndex) {
  36097. if (!data.hasValue(dataIndex)) {
  36098. return;
  36099. }
  36100. var itemModel = data.getItemModel(dataIndex);
  36101. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  36102. var el = elementCreator[coord.type](
  36103. data, dataIndex, itemModel, layout, isHorizontalOrRadial, animationModel
  36104. );
  36105. data.setItemGraphicEl(dataIndex, el);
  36106. group.add(el);
  36107. updateStyle(
  36108. el, data, dataIndex, itemModel, layout,
  36109. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  36110. );
  36111. })
  36112. .update(function (newIndex, oldIndex) {
  36113. var el = oldData.getItemGraphicEl(oldIndex);
  36114. if (!data.hasValue(newIndex)) {
  36115. group.remove(el);
  36116. return;
  36117. }
  36118. var itemModel = data.getItemModel(newIndex);
  36119. var layout = getLayout[coord.type](data, newIndex, itemModel);
  36120. if (el) {
  36121. updateProps(el, {shape: layout}, animationModel, newIndex);
  36122. }
  36123. else {
  36124. el = elementCreator[coord.type](
  36125. data, newIndex, itemModel, layout, isHorizontalOrRadial, animationModel, true
  36126. );
  36127. }
  36128. data.setItemGraphicEl(newIndex, el);
  36129. // Add back
  36130. group.add(el);
  36131. updateStyle(
  36132. el, data, newIndex, itemModel, layout,
  36133. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  36134. );
  36135. })
  36136. .remove(function (dataIndex) {
  36137. var el = oldData.getItemGraphicEl(dataIndex);
  36138. if (coord.type === 'cartesian2d') {
  36139. el && removeRect(dataIndex, animationModel, el);
  36140. }
  36141. else {
  36142. el && removeSector(dataIndex, animationModel, el);
  36143. }
  36144. })
  36145. .execute();
  36146. this._data = data;
  36147. },
  36148. _renderLarge: function (seriesModel, ecModel, api) {
  36149. this._clear();
  36150. createLarge(seriesModel, this.group);
  36151. },
  36152. _incrementalRenderLarge: function (params, seriesModel) {
  36153. createLarge(seriesModel, this.group, true);
  36154. },
  36155. dispose: noop,
  36156. remove: function (ecModel) {
  36157. this._clear(ecModel);
  36158. },
  36159. _clear: function (ecModel) {
  36160. var group = this.group;
  36161. var data = this._data;
  36162. if (ecModel && ecModel.get('animation') && data && !this._isLargeDraw) {
  36163. data.eachItemGraphicEl(function (el) {
  36164. if (el.type === 'sector') {
  36165. removeSector(el.dataIndex, ecModel, el);
  36166. }
  36167. else {
  36168. removeRect(el.dataIndex, ecModel, el);
  36169. }
  36170. });
  36171. }
  36172. else {
  36173. group.removeAll();
  36174. }
  36175. this._data = null;
  36176. }
  36177. });
  36178. var elementCreator = {
  36179. cartesian2d: function (
  36180. data, dataIndex, itemModel, layout, isHorizontal,
  36181. animationModel, isUpdate
  36182. ) {
  36183. var rect = new Rect({shape: extend({}, layout)});
  36184. // Animation
  36185. if (animationModel) {
  36186. var rectShape = rect.shape;
  36187. var animateProperty = isHorizontal ? 'height' : 'width';
  36188. var animateTarget = {};
  36189. rectShape[animateProperty] = 0;
  36190. animateTarget[animateProperty] = layout[animateProperty];
  36191. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  36192. shape: animateTarget
  36193. }, animationModel, dataIndex);
  36194. }
  36195. return rect;
  36196. },
  36197. polar: function (
  36198. data, dataIndex, itemModel, layout, isRadial,
  36199. animationModel, isUpdate
  36200. ) {
  36201. // Keep the same logic with bar in catesion: use end value to control
  36202. // direction. Notice that if clockwise is true (by default), the sector
  36203. // will always draw clockwisely, no matter whether endAngle is greater
  36204. // or less than startAngle.
  36205. var clockwise = layout.startAngle < layout.endAngle;
  36206. var sector = new Sector({
  36207. shape: defaults({clockwise: clockwise}, layout)
  36208. });
  36209. // Animation
  36210. if (animationModel) {
  36211. var sectorShape = sector.shape;
  36212. var animateProperty = isRadial ? 'r' : 'endAngle';
  36213. var animateTarget = {};
  36214. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  36215. animateTarget[animateProperty] = layout[animateProperty];
  36216. graphic[isUpdate ? 'updateProps' : 'initProps'](sector, {
  36217. shape: animateTarget
  36218. }, animationModel, dataIndex);
  36219. }
  36220. return sector;
  36221. }
  36222. };
  36223. function removeRect(dataIndex, animationModel, el) {
  36224. // Not show text when animating
  36225. el.style.text = null;
  36226. updateProps(el, {
  36227. shape: {
  36228. width: 0
  36229. }
  36230. }, animationModel, dataIndex, function () {
  36231. el.parent && el.parent.remove(el);
  36232. });
  36233. }
  36234. function removeSector(dataIndex, animationModel, el) {
  36235. // Not show text when animating
  36236. el.style.text = null;
  36237. updateProps(el, {
  36238. shape: {
  36239. r: el.shape.r0
  36240. }
  36241. }, animationModel, dataIndex, function () {
  36242. el.parent && el.parent.remove(el);
  36243. });
  36244. }
  36245. var getLayout = {
  36246. cartesian2d: function (data, dataIndex, itemModel) {
  36247. var layout = data.getItemLayout(dataIndex);
  36248. var fixedLineWidth = getLineWidth(itemModel, layout);
  36249. // fix layout with lineWidth
  36250. var signX = layout.width > 0 ? 1 : -1;
  36251. var signY = layout.height > 0 ? 1 : -1;
  36252. return {
  36253. x: layout.x + signX * fixedLineWidth / 2,
  36254. y: layout.y + signY * fixedLineWidth / 2,
  36255. width: layout.width - signX * fixedLineWidth,
  36256. height: layout.height - signY * fixedLineWidth
  36257. };
  36258. },
  36259. polar: function (data, dataIndex, itemModel) {
  36260. var layout = data.getItemLayout(dataIndex);
  36261. return {
  36262. cx: layout.cx,
  36263. cy: layout.cy,
  36264. r0: layout.r0,
  36265. r: layout.r,
  36266. startAngle: layout.startAngle,
  36267. endAngle: layout.endAngle
  36268. };
  36269. }
  36270. };
  36271. function updateStyle(
  36272. el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal, isPolar
  36273. ) {
  36274. var color = data.getItemVisual(dataIndex, 'color');
  36275. var opacity = data.getItemVisual(dataIndex, 'opacity');
  36276. var itemStyleModel = itemModel.getModel('itemStyle');
  36277. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getBarItemStyle();
  36278. if (!isPolar) {
  36279. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  36280. }
  36281. el.useStyle(defaults(
  36282. {
  36283. fill: color,
  36284. opacity: opacity
  36285. },
  36286. itemStyleModel.getBarItemStyle()
  36287. ));
  36288. var cursorStyle = itemModel.getShallow('cursor');
  36289. cursorStyle && el.attr('cursor', cursorStyle);
  36290. var labelPositionOutside = isHorizontal
  36291. ? (layout.height > 0 ? 'bottom' : 'top')
  36292. : (layout.width > 0 ? 'left' : 'right');
  36293. if (!isPolar) {
  36294. setLabel(
  36295. el.style, hoverStyle, itemModel, color,
  36296. seriesModel, dataIndex, labelPositionOutside
  36297. );
  36298. }
  36299. setHoverStyle(el, hoverStyle);
  36300. }
  36301. // In case width or height are too small.
  36302. function getLineWidth(itemModel, rawLayout) {
  36303. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  36304. return Math.min(lineWidth, Math.abs(rawLayout.width), Math.abs(rawLayout.height));
  36305. }
  36306. var LargePath = Path.extend({
  36307. type: 'largeBar',
  36308. shape: {points: []},
  36309. buildPath: function (ctx, shape) {
  36310. // Drawing lines is more efficient than drawing
  36311. // a whole line or drawing rects.
  36312. var points = shape.points;
  36313. var startPoint = this.__startPoint;
  36314. var valueIdx = this.__valueIdx;
  36315. for (var i = 0; i < points.length; i += 2) {
  36316. startPoint[this.__valueIdx] = points[i + valueIdx];
  36317. ctx.moveTo(startPoint[0], startPoint[1]);
  36318. ctx.lineTo(points[i], points[i + 1]);
  36319. }
  36320. }
  36321. });
  36322. function createLarge(seriesModel, group, incremental) {
  36323. // TODO support polar
  36324. var data = seriesModel.getData();
  36325. var startPoint = [];
  36326. var valueIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  36327. startPoint[1 - valueIdx] = data.getLayout('valueAxisStart');
  36328. var el = new LargePath({
  36329. shape: {points: data.getLayout('largePoints')},
  36330. incremental: !!incremental,
  36331. __startPoint: startPoint,
  36332. __valueIdx: valueIdx
  36333. });
  36334. group.add(el);
  36335. setLargeStyle(el, seriesModel, data);
  36336. }
  36337. function setLargeStyle(el, seriesModel, data) {
  36338. var borderColor = data.getVisual('borderColor') || data.getVisual('color');
  36339. var itemStyle = seriesModel.getModel('itemStyle').getItemStyle(['color', 'borderColor']);
  36340. el.useStyle(itemStyle);
  36341. el.style.fill = null;
  36342. el.style.stroke = borderColor;
  36343. el.style.lineWidth = data.getLayout('barWidth');
  36344. }
  36345. /*
  36346. * Licensed to the Apache Software Foundation (ASF) under one
  36347. * or more contributor license agreements. See the NOTICE file
  36348. * distributed with this work for additional information
  36349. * regarding copyright ownership. The ASF licenses this file
  36350. * to you under the Apache License, Version 2.0 (the
  36351. * "License"); you may not use this file except in compliance
  36352. * with the License. You may obtain a copy of the License at
  36353. *
  36354. * http://www.apache.org/licenses/LICENSE-2.0
  36355. *
  36356. * Unless required by applicable law or agreed to in writing,
  36357. * software distributed under the License is distributed on an
  36358. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36359. * KIND, either express or implied. See the License for the
  36360. * specific language governing permissions and limitations
  36361. * under the License.
  36362. */
  36363. // In case developer forget to include grid component
  36364. registerLayout(curry(layout, 'bar'));
  36365. // Should after normal bar layout, otherwise it is blocked by normal bar layout.
  36366. registerLayout(largeLayout);
  36367. registerVisual({
  36368. seriesType: 'bar',
  36369. reset: function (seriesModel) {
  36370. // Visual coding for legend
  36371. seriesModel.getData().setVisual('legendSymbol', 'roundRect');
  36372. }
  36373. });
  36374. /*
  36375. * Licensed to the Apache Software Foundation (ASF) under one
  36376. * or more contributor license agreements. See the NOTICE file
  36377. * distributed with this work for additional information
  36378. * regarding copyright ownership. The ASF licenses this file
  36379. * to you under the Apache License, Version 2.0 (the
  36380. * "License"); you may not use this file except in compliance
  36381. * with the License. You may obtain a copy of the License at
  36382. *
  36383. * http://www.apache.org/licenses/LICENSE-2.0
  36384. *
  36385. * Unless required by applicable law or agreed to in writing,
  36386. * software distributed under the License is distributed on an
  36387. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36388. * KIND, either express or implied. See the License for the
  36389. * specific language governing permissions and limitations
  36390. * under the License.
  36391. */
  36392. /**
  36393. * [Usage]:
  36394. * (1)
  36395. * createListSimply(seriesModel, ['value']);
  36396. * (2)
  36397. * createListSimply(seriesModel, {
  36398. * coordDimensions: ['value'],
  36399. * dimensionsCount: 5
  36400. * });
  36401. *
  36402. * @param {module:echarts/model/Series} seriesModel
  36403. * @param {Object|Array.<string|Object>} opt opt or coordDimensions
  36404. * The options in opt, see `echarts/data/helper/createDimensions`
  36405. * @param {Array.<string>} [nameList]
  36406. * @return {module:echarts/data/List}
  36407. */
  36408. var createListSimply = function (seriesModel, opt, nameList) {
  36409. opt = isArray(opt) && {coordDimensions: opt} || extend({}, opt);
  36410. var source = seriesModel.getSource();
  36411. var dimensionsInfo = createDimensions(source, opt);
  36412. var list = new List(dimensionsInfo, seriesModel);
  36413. list.initData(source, nameList);
  36414. return list;
  36415. };
  36416. /*
  36417. * Licensed to the Apache Software Foundation (ASF) under one
  36418. * or more contributor license agreements. See the NOTICE file
  36419. * distributed with this work for additional information
  36420. * regarding copyright ownership. The ASF licenses this file
  36421. * to you under the Apache License, Version 2.0 (the
  36422. * "License"); you may not use this file except in compliance
  36423. * with the License. You may obtain a copy of the License at
  36424. *
  36425. * http://www.apache.org/licenses/LICENSE-2.0
  36426. *
  36427. * Unless required by applicable law or agreed to in writing,
  36428. * software distributed under the License is distributed on an
  36429. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36430. * KIND, either express or implied. See the License for the
  36431. * specific language governing permissions and limitations
  36432. * under the License.
  36433. */
  36434. /**
  36435. * Data selectable mixin for chart series.
  36436. * To eanble data select, option of series must have `selectedMode`.
  36437. * And each data item will use `selected` to toggle itself selected status
  36438. */
  36439. var selectableMixin = {
  36440. /**
  36441. * @param {Array.<Object>} targetList [{name, value, selected}, ...]
  36442. * If targetList is an array, it should like [{name: ..., value: ...}, ...].
  36443. * If targetList is a "List", it must have coordDim: 'value' dimension and name.
  36444. */
  36445. updateSelectedMap: function (targetList) {
  36446. this._targetList = isArray(targetList) ? targetList.slice() : [];
  36447. this._selectTargetMap = reduce(targetList || [], function (targetMap, target) {
  36448. targetMap.set(target.name, target);
  36449. return targetMap;
  36450. }, createHashMap());
  36451. },
  36452. /**
  36453. * Either name or id should be passed as input here.
  36454. * If both of them are defined, id is used.
  36455. *
  36456. * @param {string|undefined} name name of data
  36457. * @param {number|undefined} id dataIndex of data
  36458. */
  36459. // PENGING If selectedMode is null ?
  36460. select: function (name, id) {
  36461. var target = id != null
  36462. ? this._targetList[id]
  36463. : this._selectTargetMap.get(name);
  36464. var selectedMode = this.get('selectedMode');
  36465. if (selectedMode === 'single') {
  36466. this._selectTargetMap.each(function (target) {
  36467. target.selected = false;
  36468. });
  36469. }
  36470. target && (target.selected = true);
  36471. },
  36472. /**
  36473. * Either name or id should be passed as input here.
  36474. * If both of them are defined, id is used.
  36475. *
  36476. * @param {string|undefined} name name of data
  36477. * @param {number|undefined} id dataIndex of data
  36478. */
  36479. unSelect: function (name, id) {
  36480. var target = id != null
  36481. ? this._targetList[id]
  36482. : this._selectTargetMap.get(name);
  36483. // var selectedMode = this.get('selectedMode');
  36484. // selectedMode !== 'single' && target && (target.selected = false);
  36485. target && (target.selected = false);
  36486. },
  36487. /**
  36488. * Either name or id should be passed as input here.
  36489. * If both of them are defined, id is used.
  36490. *
  36491. * @param {string|undefined} name name of data
  36492. * @param {number|undefined} id dataIndex of data
  36493. */
  36494. toggleSelected: function (name, id) {
  36495. var target = id != null
  36496. ? this._targetList[id]
  36497. : this._selectTargetMap.get(name);
  36498. if (target != null) {
  36499. this[target.selected ? 'unSelect' : 'select'](name, id);
  36500. return target.selected;
  36501. }
  36502. },
  36503. /**
  36504. * Either name or id should be passed as input here.
  36505. * If both of them are defined, id is used.
  36506. *
  36507. * @param {string|undefined} name name of data
  36508. * @param {number|undefined} id dataIndex of data
  36509. */
  36510. isSelected: function (name, id) {
  36511. var target = id != null
  36512. ? this._targetList[id]
  36513. : this._selectTargetMap.get(name);
  36514. return target && target.selected;
  36515. }
  36516. };
  36517. /*
  36518. * Licensed to the Apache Software Foundation (ASF) under one
  36519. * or more contributor license agreements. See the NOTICE file
  36520. * distributed with this work for additional information
  36521. * regarding copyright ownership. The ASF licenses this file
  36522. * to you under the Apache License, Version 2.0 (the
  36523. * "License"); you may not use this file except in compliance
  36524. * with the License. You may obtain a copy of the License at
  36525. *
  36526. * http://www.apache.org/licenses/LICENSE-2.0
  36527. *
  36528. * Unless required by applicable law or agreed to in writing,
  36529. * software distributed under the License is distributed on an
  36530. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36531. * KIND, either express or implied. See the License for the
  36532. * specific language governing permissions and limitations
  36533. * under the License.
  36534. */
  36535. var PieSeries = extendSeriesModel({
  36536. type: 'series.pie',
  36537. // Overwrite
  36538. init: function (option) {
  36539. PieSeries.superApply(this, 'init', arguments);
  36540. // Enable legend selection for each data item
  36541. // Use a function instead of direct access because data reference may changed
  36542. this.legendDataProvider = function () {
  36543. return this.getRawData();
  36544. };
  36545. this.updateSelectedMap(this._createSelectableList());
  36546. this._defaultLabelLine(option);
  36547. },
  36548. // Overwrite
  36549. mergeOption: function (newOption) {
  36550. PieSeries.superCall(this, 'mergeOption', newOption);
  36551. this.updateSelectedMap(this._createSelectableList());
  36552. },
  36553. getInitialData: function (option, ecModel) {
  36554. return createListSimply(this, ['value']);
  36555. },
  36556. _createSelectableList: function () {
  36557. var data = this.getRawData();
  36558. var valueDim = data.mapDimension('value');
  36559. var targetList = [];
  36560. for (var i = 0, len = data.count(); i < len; i++) {
  36561. targetList.push({
  36562. name: data.getName(i),
  36563. value: data.get(valueDim, i),
  36564. selected: retrieveRawAttr(data, i, 'selected')
  36565. });
  36566. }
  36567. return targetList;
  36568. },
  36569. // Overwrite
  36570. getDataParams: function (dataIndex) {
  36571. var data = this.getData();
  36572. var params = PieSeries.superCall(this, 'getDataParams', dataIndex);
  36573. // FIXME toFixed?
  36574. var valueList = [];
  36575. data.each(data.mapDimension('value'), function (value) {
  36576. valueList.push(value);
  36577. });
  36578. params.percent = getPercentWithPrecision(
  36579. valueList,
  36580. dataIndex,
  36581. data.hostModel.get('percentPrecision')
  36582. );
  36583. params.$vars.push('percent');
  36584. return params;
  36585. },
  36586. _defaultLabelLine: function (option) {
  36587. // Extend labelLine emphasis
  36588. defaultEmphasis(option, 'labelLine', ['show']);
  36589. var labelLineNormalOpt = option.labelLine;
  36590. var labelLineEmphasisOpt = option.emphasis.labelLine;
  36591. // Not show label line if `label.normal.show = false`
  36592. labelLineNormalOpt.show = labelLineNormalOpt.show
  36593. && option.label.show;
  36594. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  36595. && option.emphasis.label.show;
  36596. },
  36597. defaultOption: {
  36598. zlevel: 0,
  36599. z: 2,
  36600. legendHoverLink: true,
  36601. hoverAnimation: true,
  36602. // 默认全局居中
  36603. center: ['50%', '50%'],
  36604. radius: [0, '75%'],
  36605. // 默认顺时针
  36606. clockwise: true,
  36607. startAngle: 90,
  36608. // 最小角度改为0
  36609. minAngle: 0,
  36610. // 选中时扇区偏移量
  36611. selectedOffset: 10,
  36612. // 高亮扇区偏移量
  36613. hoverOffset: 10,
  36614. // If use strategy to avoid label overlapping
  36615. avoidLabelOverlap: true,
  36616. // 选择模式,默认关闭,可选single,multiple
  36617. // selectedMode: false,
  36618. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  36619. // roseType: null,
  36620. percentPrecision: 2,
  36621. // If still show when all data zero.
  36622. stillShowZeroSum: true,
  36623. // cursor: null,
  36624. label: {
  36625. // If rotate around circle
  36626. rotate: false,
  36627. show: true,
  36628. // 'outer', 'inside', 'center'
  36629. position: 'outer'
  36630. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  36631. // 默认使用全局文本样式,详见TEXTSTYLE
  36632. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  36633. },
  36634. // Enabled when label.normal.position is 'outer'
  36635. labelLine: {
  36636. show: true,
  36637. // 引导线两段中的第一段长度
  36638. length: 15,
  36639. // 引导线两段中的第二段长度
  36640. length2: 15,
  36641. smooth: false,
  36642. lineStyle: {
  36643. // color: 各异,
  36644. width: 1,
  36645. type: 'solid'
  36646. }
  36647. },
  36648. itemStyle: {
  36649. borderWidth: 1
  36650. },
  36651. // Animation type canbe expansion, scale
  36652. animationType: 'expansion',
  36653. animationEasing: 'cubicOut'
  36654. }
  36655. });
  36656. mixin(PieSeries, selectableMixin);
  36657. /*
  36658. * Licensed to the Apache Software Foundation (ASF) under one
  36659. * or more contributor license agreements. See the NOTICE file
  36660. * distributed with this work for additional information
  36661. * regarding copyright ownership. The ASF licenses this file
  36662. * to you under the Apache License, Version 2.0 (the
  36663. * "License"); you may not use this file except in compliance
  36664. * with the License. You may obtain a copy of the License at
  36665. *
  36666. * http://www.apache.org/licenses/LICENSE-2.0
  36667. *
  36668. * Unless required by applicable law or agreed to in writing,
  36669. * software distributed under the License is distributed on an
  36670. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36671. * KIND, either express or implied. See the License for the
  36672. * specific language governing permissions and limitations
  36673. * under the License.
  36674. */
  36675. /**
  36676. * @param {module:echarts/model/Series} seriesModel
  36677. * @param {boolean} hasAnimation
  36678. * @inner
  36679. */
  36680. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  36681. var data = seriesModel.getData();
  36682. var dataIndex = this.dataIndex;
  36683. var name = data.getName(dataIndex);
  36684. var selectedOffset = seriesModel.get('selectedOffset');
  36685. api.dispatchAction({
  36686. type: 'pieToggleSelect',
  36687. from: uid,
  36688. name: name,
  36689. seriesId: seriesModel.id
  36690. });
  36691. data.each(function (idx) {
  36692. toggleItemSelected(
  36693. data.getItemGraphicEl(idx),
  36694. data.getItemLayout(idx),
  36695. seriesModel.isSelected(data.getName(idx)),
  36696. selectedOffset,
  36697. hasAnimation
  36698. );
  36699. });
  36700. }
  36701. /**
  36702. * @param {module:zrender/graphic/Sector} el
  36703. * @param {Object} layout
  36704. * @param {boolean} isSelected
  36705. * @param {number} selectedOffset
  36706. * @param {boolean} hasAnimation
  36707. * @inner
  36708. */
  36709. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  36710. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  36711. var dx = Math.cos(midAngle);
  36712. var dy = Math.sin(midAngle);
  36713. var offset = isSelected ? selectedOffset : 0;
  36714. var position = [dx * offset, dy * offset];
  36715. hasAnimation
  36716. // animateTo will stop revious animation like update transition
  36717. ? el.animate()
  36718. .when(200, {
  36719. position: position
  36720. })
  36721. .start('bounceOut')
  36722. : el.attr('position', position);
  36723. }
  36724. /**
  36725. * Piece of pie including Sector, Label, LabelLine
  36726. * @constructor
  36727. * @extends {module:zrender/graphic/Group}
  36728. */
  36729. function PiePiece(data, idx) {
  36730. Group.call(this);
  36731. var sector = new Sector({
  36732. z2: 2
  36733. });
  36734. var polyline = new Polyline();
  36735. var text = new Text();
  36736. this.add(sector);
  36737. this.add(polyline);
  36738. this.add(text);
  36739. this.updateData(data, idx, true);
  36740. // Hover to change label and labelLine
  36741. function onEmphasis() {
  36742. polyline.ignore = polyline.hoverIgnore;
  36743. text.ignore = text.hoverIgnore;
  36744. }
  36745. function onNormal() {
  36746. polyline.ignore = polyline.normalIgnore;
  36747. text.ignore = text.normalIgnore;
  36748. }
  36749. this.on('emphasis', onEmphasis)
  36750. .on('normal', onNormal)
  36751. .on('mouseover', onEmphasis)
  36752. .on('mouseout', onNormal);
  36753. }
  36754. var piePieceProto = PiePiece.prototype;
  36755. piePieceProto.updateData = function (data, idx, firstCreate) {
  36756. var sector = this.childAt(0);
  36757. var seriesModel = data.hostModel;
  36758. var itemModel = data.getItemModel(idx);
  36759. var layout = data.getItemLayout(idx);
  36760. var sectorShape = extend({}, layout);
  36761. sectorShape.label = null;
  36762. if (firstCreate) {
  36763. sector.setShape(sectorShape);
  36764. var animationType = seriesModel.getShallow('animationType');
  36765. if (animationType === 'scale') {
  36766. sector.shape.r = layout.r0;
  36767. initProps(sector, {
  36768. shape: {
  36769. r: layout.r
  36770. }
  36771. }, seriesModel, idx);
  36772. }
  36773. // Expansion
  36774. else {
  36775. sector.shape.endAngle = layout.startAngle;
  36776. updateProps(sector, {
  36777. shape: {
  36778. endAngle: layout.endAngle
  36779. }
  36780. }, seriesModel, idx);
  36781. }
  36782. }
  36783. else {
  36784. updateProps(sector, {
  36785. shape: sectorShape
  36786. }, seriesModel, idx);
  36787. }
  36788. // Update common style
  36789. var visualColor = data.getItemVisual(idx, 'color');
  36790. sector.useStyle(
  36791. defaults(
  36792. {
  36793. lineJoin: 'bevel',
  36794. fill: visualColor
  36795. },
  36796. itemModel.getModel('itemStyle').getItemStyle()
  36797. )
  36798. );
  36799. sector.hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  36800. var cursorStyle = itemModel.getShallow('cursor');
  36801. cursorStyle && sector.attr('cursor', cursorStyle);
  36802. // Toggle selected
  36803. toggleItemSelected(
  36804. this,
  36805. data.getItemLayout(idx),
  36806. seriesModel.isSelected(null, idx),
  36807. seriesModel.get('selectedOffset'),
  36808. seriesModel.get('animation')
  36809. );
  36810. function onEmphasis() {
  36811. // Sector may has animation of updating data. Force to move to the last frame
  36812. // Or it may stopped on the wrong shape
  36813. sector.stopAnimation(true);
  36814. sector.animateTo({
  36815. shape: {
  36816. r: layout.r + seriesModel.get('hoverOffset')
  36817. }
  36818. }, 300, 'elasticOut');
  36819. }
  36820. function onNormal() {
  36821. sector.stopAnimation(true);
  36822. sector.animateTo({
  36823. shape: {
  36824. r: layout.r
  36825. }
  36826. }, 300, 'elasticOut');
  36827. }
  36828. sector.off('mouseover').off('mouseout').off('emphasis').off('normal');
  36829. if (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled()) {
  36830. sector
  36831. .on('mouseover', onEmphasis)
  36832. .on('mouseout', onNormal)
  36833. .on('emphasis', onEmphasis)
  36834. .on('normal', onNormal);
  36835. }
  36836. this._updateLabel(data, idx);
  36837. setHoverStyle(this);
  36838. };
  36839. piePieceProto._updateLabel = function (data, idx) {
  36840. var labelLine = this.childAt(1);
  36841. var labelText = this.childAt(2);
  36842. var seriesModel = data.hostModel;
  36843. var itemModel = data.getItemModel(idx);
  36844. var layout = data.getItemLayout(idx);
  36845. var labelLayout = layout.label;
  36846. var visualColor = data.getItemVisual(idx, 'color');
  36847. updateProps(labelLine, {
  36848. shape: {
  36849. points: labelLayout.linePoints || [
  36850. [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
  36851. ]
  36852. }
  36853. }, seriesModel, idx);
  36854. updateProps(labelText, {
  36855. style: {
  36856. x: labelLayout.x,
  36857. y: labelLayout.y
  36858. }
  36859. }, seriesModel, idx);
  36860. labelText.attr({
  36861. rotation: labelLayout.rotation,
  36862. origin: [labelLayout.x, labelLayout.y],
  36863. z2: 10
  36864. });
  36865. var labelModel = itemModel.getModel('label');
  36866. var labelHoverModel = itemModel.getModel('emphasis.label');
  36867. var labelLineModel = itemModel.getModel('labelLine');
  36868. var labelLineHoverModel = itemModel.getModel('emphasis.labelLine');
  36869. var visualColor = data.getItemVisual(idx, 'color');
  36870. setLabelStyle(
  36871. labelText.style, labelText.hoverStyle = {}, labelModel, labelHoverModel,
  36872. {
  36873. labelFetcher: data.hostModel,
  36874. labelDataIndex: idx,
  36875. defaultText: data.getName(idx),
  36876. autoColor: visualColor,
  36877. useInsideStyle: !!labelLayout.inside
  36878. },
  36879. {
  36880. textAlign: labelLayout.textAlign,
  36881. textVerticalAlign: labelLayout.verticalAlign,
  36882. opacity: data.getItemVisual(idx, 'opacity')
  36883. }
  36884. );
  36885. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  36886. labelText.hoverIgnore = !labelHoverModel.get('show');
  36887. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  36888. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  36889. // Default use item visual color
  36890. labelLine.setStyle({
  36891. stroke: visualColor,
  36892. opacity: data.getItemVisual(idx, 'opacity')
  36893. });
  36894. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  36895. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  36896. var smooth = labelLineModel.get('smooth');
  36897. if (smooth && smooth === true) {
  36898. smooth = 0.4;
  36899. }
  36900. labelLine.setShape({
  36901. smooth: smooth
  36902. });
  36903. };
  36904. inherits(PiePiece, Group);
  36905. // Pie view
  36906. var PieView = Chart.extend({
  36907. type: 'pie',
  36908. init: function () {
  36909. var sectorGroup = new Group();
  36910. this._sectorGroup = sectorGroup;
  36911. },
  36912. render: function (seriesModel, ecModel, api, payload) {
  36913. if (payload && (payload.from === this.uid)) {
  36914. return;
  36915. }
  36916. var data = seriesModel.getData();
  36917. var oldData = this._data;
  36918. var group = this.group;
  36919. var hasAnimation = ecModel.get('animation');
  36920. var isFirstRender = !oldData;
  36921. var animationType = seriesModel.get('animationType');
  36922. var onSectorClick = curry(
  36923. updateDataSelected, this.uid, seriesModel, hasAnimation, api
  36924. );
  36925. var selectedMode = seriesModel.get('selectedMode');
  36926. data.diff(oldData)
  36927. .add(function (idx) {
  36928. var piePiece = new PiePiece(data, idx);
  36929. // Default expansion animation
  36930. if (isFirstRender && animationType !== 'scale') {
  36931. piePiece.eachChild(function (child) {
  36932. child.stopAnimation(true);
  36933. });
  36934. }
  36935. selectedMode && piePiece.on('click', onSectorClick);
  36936. data.setItemGraphicEl(idx, piePiece);
  36937. group.add(piePiece);
  36938. })
  36939. .update(function (newIdx, oldIdx) {
  36940. var piePiece = oldData.getItemGraphicEl(oldIdx);
  36941. piePiece.updateData(data, newIdx);
  36942. piePiece.off('click');
  36943. selectedMode && piePiece.on('click', onSectorClick);
  36944. group.add(piePiece);
  36945. data.setItemGraphicEl(newIdx, piePiece);
  36946. })
  36947. .remove(function (idx) {
  36948. var piePiece = oldData.getItemGraphicEl(idx);
  36949. group.remove(piePiece);
  36950. })
  36951. .execute();
  36952. if (
  36953. hasAnimation && isFirstRender && data.count() > 0
  36954. // Default expansion animation
  36955. && animationType !== 'scale'
  36956. ) {
  36957. var shape = data.getItemLayout(0);
  36958. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  36959. var removeClipPath = bind(group.removeClipPath, group);
  36960. group.setClipPath(this._createClipPath(
  36961. shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel
  36962. ));
  36963. }
  36964. else {
  36965. // clipPath is used in first-time animation, so remove it when otherwise. See: #8994
  36966. group.removeClipPath();
  36967. }
  36968. this._data = data;
  36969. },
  36970. dispose: function () {},
  36971. _createClipPath: function (
  36972. cx, cy, r, startAngle, clockwise, cb, seriesModel
  36973. ) {
  36974. var clipPath = new Sector({
  36975. shape: {
  36976. cx: cx,
  36977. cy: cy,
  36978. r0: 0,
  36979. r: r,
  36980. startAngle: startAngle,
  36981. endAngle: startAngle,
  36982. clockwise: clockwise
  36983. }
  36984. });
  36985. initProps(clipPath, {
  36986. shape: {
  36987. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  36988. }
  36989. }, seriesModel, cb);
  36990. return clipPath;
  36991. },
  36992. /**
  36993. * @implement
  36994. */
  36995. containPoint: function (point, seriesModel) {
  36996. var data = seriesModel.getData();
  36997. var itemLayout = data.getItemLayout(0);
  36998. if (itemLayout) {
  36999. var dx = point[0] - itemLayout.cx;
  37000. var dy = point[1] - itemLayout.cy;
  37001. var radius = Math.sqrt(dx * dx + dy * dy);
  37002. return radius <= itemLayout.r && radius >= itemLayout.r0;
  37003. }
  37004. }
  37005. });
  37006. /*
  37007. * Licensed to the Apache Software Foundation (ASF) under one
  37008. * or more contributor license agreements. See the NOTICE file
  37009. * distributed with this work for additional information
  37010. * regarding copyright ownership. The ASF licenses this file
  37011. * to you under the Apache License, Version 2.0 (the
  37012. * "License"); you may not use this file except in compliance
  37013. * with the License. You may obtain a copy of the License at
  37014. *
  37015. * http://www.apache.org/licenses/LICENSE-2.0
  37016. *
  37017. * Unless required by applicable law or agreed to in writing,
  37018. * software distributed under the License is distributed on an
  37019. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37020. * KIND, either express or implied. See the License for the
  37021. * specific language governing permissions and limitations
  37022. * under the License.
  37023. */
  37024. var createDataSelectAction = function (seriesType, actionInfos) {
  37025. each$1(actionInfos, function (actionInfo) {
  37026. actionInfo.update = 'updateView';
  37027. /**
  37028. * @payload
  37029. * @property {string} seriesName
  37030. * @property {string} name
  37031. */
  37032. registerAction(actionInfo, function (payload, ecModel) {
  37033. var selected = {};
  37034. ecModel.eachComponent(
  37035. {mainType: 'series', subType: seriesType, query: payload},
  37036. function (seriesModel) {
  37037. if (seriesModel[actionInfo.method]) {
  37038. seriesModel[actionInfo.method](
  37039. payload.name,
  37040. payload.dataIndex
  37041. );
  37042. }
  37043. var data = seriesModel.getData();
  37044. // Create selected map
  37045. data.each(function (idx) {
  37046. var name = data.getName(idx);
  37047. selected[name] = seriesModel.isSelected(name)
  37048. || false;
  37049. });
  37050. }
  37051. );
  37052. return {
  37053. name: payload.name,
  37054. selected: selected
  37055. };
  37056. });
  37057. });
  37058. };
  37059. /*
  37060. * Licensed to the Apache Software Foundation (ASF) under one
  37061. * or more contributor license agreements. See the NOTICE file
  37062. * distributed with this work for additional information
  37063. * regarding copyright ownership. The ASF licenses this file
  37064. * to you under the Apache License, Version 2.0 (the
  37065. * "License"); you may not use this file except in compliance
  37066. * with the License. You may obtain a copy of the License at
  37067. *
  37068. * http://www.apache.org/licenses/LICENSE-2.0
  37069. *
  37070. * Unless required by applicable law or agreed to in writing,
  37071. * software distributed under the License is distributed on an
  37072. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37073. * KIND, either express or implied. See the License for the
  37074. * specific language governing permissions and limitations
  37075. * under the License.
  37076. */
  37077. // Pick color from palette for each data item.
  37078. // Applicable for charts that require applying color palette
  37079. // in data level (like pie, funnel, chord).
  37080. var dataColor = function (seriesType) {
  37081. return {
  37082. getTargetSeries: function (ecModel) {
  37083. // Pie and funnel may use diferrent scope
  37084. var paletteScope = {};
  37085. var seiresModelMap = createHashMap();
  37086. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  37087. seriesModel.__paletteScope = paletteScope;
  37088. seiresModelMap.set(seriesModel.uid, seriesModel);
  37089. });
  37090. return seiresModelMap;
  37091. },
  37092. reset: function (seriesModel, ecModel) {
  37093. var dataAll = seriesModel.getRawData();
  37094. var idxMap = {};
  37095. var data = seriesModel.getData();
  37096. data.each(function (idx) {
  37097. var rawIdx = data.getRawIndex(idx);
  37098. idxMap[rawIdx] = idx;
  37099. });
  37100. dataAll.each(function (rawIdx) {
  37101. var filteredIdx = idxMap[rawIdx];
  37102. // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  37103. var singleDataColor = filteredIdx != null
  37104. && data.getItemVisual(filteredIdx, 'color', true);
  37105. if (!singleDataColor) {
  37106. // FIXME Performance
  37107. var itemModel = dataAll.getItemModel(rawIdx);
  37108. var color = itemModel.get('itemStyle.color')
  37109. || seriesModel.getColorFromPalette(
  37110. dataAll.getName(rawIdx) || (rawIdx + ''), seriesModel.__paletteScope,
  37111. dataAll.count()
  37112. );
  37113. // Legend may use the visual info in data before processed
  37114. dataAll.setItemVisual(rawIdx, 'color', color);
  37115. // Data is not filtered
  37116. if (filteredIdx != null) {
  37117. data.setItemVisual(filteredIdx, 'color', color);
  37118. }
  37119. }
  37120. else {
  37121. // Set data all color for legend
  37122. dataAll.setItemVisual(rawIdx, 'color', singleDataColor);
  37123. }
  37124. });
  37125. }
  37126. };
  37127. };
  37128. /*
  37129. * Licensed to the Apache Software Foundation (ASF) under one
  37130. * or more contributor license agreements. See the NOTICE file
  37131. * distributed with this work for additional information
  37132. * regarding copyright ownership. The ASF licenses this file
  37133. * to you under the Apache License, Version 2.0 (the
  37134. * "License"); you may not use this file except in compliance
  37135. * with the License. You may obtain a copy of the License at
  37136. *
  37137. * http://www.apache.org/licenses/LICENSE-2.0
  37138. *
  37139. * Unless required by applicable law or agreed to in writing,
  37140. * software distributed under the License is distributed on an
  37141. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37142. * KIND, either express or implied. See the License for the
  37143. * specific language governing permissions and limitations
  37144. * under the License.
  37145. */
  37146. // FIXME emphasis label position is not same with normal label position
  37147. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight) {
  37148. list.sort(function (a, b) {
  37149. return a.y - b.y;
  37150. });
  37151. function shiftDown(start, end, delta, dir) {
  37152. for (var j = start; j < end; j++) {
  37153. list[j].y += delta;
  37154. if (j > start
  37155. && j + 1 < end
  37156. && list[j + 1].y > list[j].y + list[j].height
  37157. ) {
  37158. shiftUp(j, delta / 2);
  37159. return;
  37160. }
  37161. }
  37162. shiftUp(end - 1, delta / 2);
  37163. }
  37164. function shiftUp(end, delta) {
  37165. for (var j = end; j >= 0; j--) {
  37166. list[j].y -= delta;
  37167. if (j > 0
  37168. && list[j].y > list[j - 1].y + list[j - 1].height
  37169. ) {
  37170. break;
  37171. }
  37172. }
  37173. }
  37174. function changeX(list, isDownList, cx, cy, r, dir) {
  37175. var lastDeltaX = dir > 0
  37176. ? isDownList // right-side
  37177. ? Number.MAX_VALUE // down
  37178. : 0 // up
  37179. : isDownList // left-side
  37180. ? Number.MAX_VALUE // down
  37181. : 0; // up
  37182. for (var i = 0, l = list.length; i < l; i++) {
  37183. var deltaY = Math.abs(list[i].y - cy);
  37184. var length = list[i].len;
  37185. var length2 = list[i].len2;
  37186. var deltaX = (deltaY < r + length)
  37187. ? Math.sqrt(
  37188. (r + length + length2) * (r + length + length2)
  37189. - deltaY * deltaY
  37190. )
  37191. : Math.abs(list[i].x - cx);
  37192. if (isDownList && deltaX >= lastDeltaX) {
  37193. // right-down, left-down
  37194. deltaX = lastDeltaX - 10;
  37195. }
  37196. if (!isDownList && deltaX <= lastDeltaX) {
  37197. // right-up, left-up
  37198. deltaX = lastDeltaX + 10;
  37199. }
  37200. list[i].x = cx + deltaX * dir;
  37201. lastDeltaX = deltaX;
  37202. }
  37203. }
  37204. var lastY = 0;
  37205. var delta;
  37206. var len = list.length;
  37207. var upList = [];
  37208. var downList = [];
  37209. for (var i = 0; i < len; i++) {
  37210. delta = list[i].y - lastY;
  37211. if (delta < 0) {
  37212. shiftDown(i, len, -delta, dir);
  37213. }
  37214. lastY = list[i].y + list[i].height;
  37215. }
  37216. if (viewHeight - lastY < 0) {
  37217. shiftUp(len - 1, lastY - viewHeight);
  37218. }
  37219. for (var i = 0; i < len; i++) {
  37220. if (list[i].y >= cy) {
  37221. downList.push(list[i]);
  37222. }
  37223. else {
  37224. upList.push(list[i]);
  37225. }
  37226. }
  37227. changeX(upList, false, cx, cy, r, dir);
  37228. changeX(downList, true, cx, cy, r, dir);
  37229. }
  37230. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight) {
  37231. var leftList = [];
  37232. var rightList = [];
  37233. for (var i = 0; i < labelLayoutList.length; i++) {
  37234. if (isPositionCenter(labelLayoutList[i])) {
  37235. continue;
  37236. }
  37237. if (labelLayoutList[i].x < cx) {
  37238. leftList.push(labelLayoutList[i]);
  37239. }
  37240. else {
  37241. rightList.push(labelLayoutList[i]);
  37242. }
  37243. }
  37244. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight);
  37245. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);
  37246. for (var i = 0; i < labelLayoutList.length; i++) {
  37247. if (isPositionCenter(labelLayoutList[i])) {
  37248. continue;
  37249. }
  37250. var linePoints = labelLayoutList[i].linePoints;
  37251. if (linePoints) {
  37252. var dist = linePoints[1][0] - linePoints[2][0];
  37253. if (labelLayoutList[i].x < cx) {
  37254. linePoints[2][0] = labelLayoutList[i].x + 3;
  37255. }
  37256. else {
  37257. linePoints[2][0] = labelLayoutList[i].x - 3;
  37258. }
  37259. linePoints[1][1] = linePoints[2][1] = labelLayoutList[i].y;
  37260. linePoints[1][0] = linePoints[2][0] + dist;
  37261. }
  37262. }
  37263. }
  37264. function isPositionCenter(layout) {
  37265. // Not change x for center label
  37266. return layout.position === 'center';
  37267. }
  37268. var labelLayout = function (seriesModel, r, viewWidth, viewHeight) {
  37269. var data = seriesModel.getData();
  37270. var labelLayoutList = [];
  37271. var cx;
  37272. var cy;
  37273. var hasLabelRotate = false;
  37274. data.each(function (idx) {
  37275. var layout = data.getItemLayout(idx);
  37276. var itemModel = data.getItemModel(idx);
  37277. var labelModel = itemModel.getModel('label');
  37278. // Use position in normal or emphasis
  37279. var labelPosition = labelModel.get('position') || itemModel.get('emphasis.label.position');
  37280. var labelLineModel = itemModel.getModel('labelLine');
  37281. var labelLineLen = labelLineModel.get('length');
  37282. var labelLineLen2 = labelLineModel.get('length2');
  37283. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  37284. var dx = Math.cos(midAngle);
  37285. var dy = Math.sin(midAngle);
  37286. var textX;
  37287. var textY;
  37288. var linePoints;
  37289. var textAlign;
  37290. cx = layout.cx;
  37291. cy = layout.cy;
  37292. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  37293. if (labelPosition === 'center') {
  37294. textX = layout.cx;
  37295. textY = layout.cy;
  37296. textAlign = 'center';
  37297. }
  37298. else {
  37299. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  37300. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  37301. textX = x1 + dx * 3;
  37302. textY = y1 + dy * 3;
  37303. if (!isLabelInside) {
  37304. // For roseType
  37305. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  37306. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  37307. var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
  37308. var y3 = y2;
  37309. textX = x3 + (dx < 0 ? -5 : 5);
  37310. textY = y3;
  37311. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  37312. }
  37313. textAlign = isLabelInside ? 'center' : (dx > 0 ? 'left' : 'right');
  37314. }
  37315. var font = labelModel.getFont();
  37316. var labelRotate = labelModel.get('rotate')
  37317. ? (dx < 0 ? -midAngle + Math.PI : -midAngle) : 0;
  37318. var text = seriesModel.getFormattedLabel(idx, 'normal')
  37319. || data.getName(idx);
  37320. var textRect = getBoundingRect(
  37321. text, font, textAlign, 'top'
  37322. );
  37323. hasLabelRotate = !!labelRotate;
  37324. layout.label = {
  37325. x: textX,
  37326. y: textY,
  37327. position: labelPosition,
  37328. height: textRect.height,
  37329. len: labelLineLen,
  37330. len2: labelLineLen2,
  37331. linePoints: linePoints,
  37332. textAlign: textAlign,
  37333. verticalAlign: 'middle',
  37334. rotation: labelRotate,
  37335. inside: isLabelInside
  37336. };
  37337. // Not layout the inside label
  37338. if (!isLabelInside) {
  37339. labelLayoutList.push(layout.label);
  37340. }
  37341. });
  37342. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  37343. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight);
  37344. }
  37345. };
  37346. /*
  37347. * Licensed to the Apache Software Foundation (ASF) under one
  37348. * or more contributor license agreements. See the NOTICE file
  37349. * distributed with this work for additional information
  37350. * regarding copyright ownership. The ASF licenses this file
  37351. * to you under the Apache License, Version 2.0 (the
  37352. * "License"); you may not use this file except in compliance
  37353. * with the License. You may obtain a copy of the License at
  37354. *
  37355. * http://www.apache.org/licenses/LICENSE-2.0
  37356. *
  37357. * Unless required by applicable law or agreed to in writing,
  37358. * software distributed under the License is distributed on an
  37359. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37360. * KIND, either express or implied. See the License for the
  37361. * specific language governing permissions and limitations
  37362. * under the License.
  37363. */
  37364. var PI2$4 = Math.PI * 2;
  37365. var RADIAN = Math.PI / 180;
  37366. var pieLayout = function (seriesType, ecModel, api, payload) {
  37367. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  37368. var data = seriesModel.getData();
  37369. var valueDim = data.mapDimension('value');
  37370. var center = seriesModel.get('center');
  37371. var radius = seriesModel.get('radius');
  37372. if (!isArray(radius)) {
  37373. radius = [0, radius];
  37374. }
  37375. if (!isArray(center)) {
  37376. center = [center, center];
  37377. }
  37378. var width = api.getWidth();
  37379. var height = api.getHeight();
  37380. var size = Math.min(width, height);
  37381. var cx = parsePercent$1(center[0], width);
  37382. var cy = parsePercent$1(center[1], height);
  37383. var r0 = parsePercent$1(radius[0], size / 2);
  37384. var r = parsePercent$1(radius[1], size / 2);
  37385. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  37386. var minAngle = seriesModel.get('minAngle') * RADIAN;
  37387. var validDataCount = 0;
  37388. data.each(valueDim, function (value) {
  37389. !isNaN(value) && validDataCount++;
  37390. });
  37391. var sum = data.getSum(valueDim);
  37392. // Sum may be 0
  37393. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  37394. var clockwise = seriesModel.get('clockwise');
  37395. var roseType = seriesModel.get('roseType');
  37396. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  37397. // [0...max]
  37398. var extent = data.getDataExtent(valueDim);
  37399. extent[0] = 0;
  37400. // In the case some sector angle is smaller than minAngle
  37401. var restAngle = PI2$4;
  37402. var valueSumLargerThanMinAngle = 0;
  37403. var currentAngle = startAngle;
  37404. var dir = clockwise ? 1 : -1;
  37405. data.each(valueDim, function (value, idx) {
  37406. var angle;
  37407. if (isNaN(value)) {
  37408. data.setItemLayout(idx, {
  37409. angle: NaN,
  37410. startAngle: NaN,
  37411. endAngle: NaN,
  37412. clockwise: clockwise,
  37413. cx: cx,
  37414. cy: cy,
  37415. r0: r0,
  37416. r: roseType
  37417. ? NaN
  37418. : r
  37419. });
  37420. return;
  37421. }
  37422. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  37423. if (roseType !== 'area') {
  37424. angle = (sum === 0 && stillShowZeroSum)
  37425. ? unitRadian : (value * unitRadian);
  37426. }
  37427. else {
  37428. angle = PI2$4 / validDataCount;
  37429. }
  37430. if (angle < minAngle) {
  37431. angle = minAngle;
  37432. restAngle -= minAngle;
  37433. }
  37434. else {
  37435. valueSumLargerThanMinAngle += value;
  37436. }
  37437. var endAngle = currentAngle + dir * angle;
  37438. data.setItemLayout(idx, {
  37439. angle: angle,
  37440. startAngle: currentAngle,
  37441. endAngle: endAngle,
  37442. clockwise: clockwise,
  37443. cx: cx,
  37444. cy: cy,
  37445. r0: r0,
  37446. r: roseType
  37447. ? linearMap(value, extent, [r0, r])
  37448. : r
  37449. });
  37450. currentAngle = endAngle;
  37451. });
  37452. // Some sector is constrained by minAngle
  37453. // Rest sectors needs recalculate angle
  37454. if (restAngle < PI2$4 && validDataCount) {
  37455. // Average the angle if rest angle is not enough after all angles is
  37456. // Constrained by minAngle
  37457. if (restAngle <= 1e-3) {
  37458. var angle = PI2$4 / validDataCount;
  37459. data.each(valueDim, function (value, idx) {
  37460. if (!isNaN(value)) {
  37461. var layout = data.getItemLayout(idx);
  37462. layout.angle = angle;
  37463. layout.startAngle = startAngle + dir * idx * angle;
  37464. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  37465. }
  37466. });
  37467. }
  37468. else {
  37469. unitRadian = restAngle / valueSumLargerThanMinAngle;
  37470. currentAngle = startAngle;
  37471. data.each(valueDim, function (value, idx) {
  37472. if (!isNaN(value)) {
  37473. var layout = data.getItemLayout(idx);
  37474. var angle = layout.angle === minAngle
  37475. ? minAngle : value * unitRadian;
  37476. layout.startAngle = currentAngle;
  37477. layout.endAngle = currentAngle + dir * angle;
  37478. currentAngle += dir * angle;
  37479. }
  37480. });
  37481. }
  37482. }
  37483. labelLayout(seriesModel, r, width, height);
  37484. });
  37485. };
  37486. /*
  37487. * Licensed to the Apache Software Foundation (ASF) under one
  37488. * or more contributor license agreements. See the NOTICE file
  37489. * distributed with this work for additional information
  37490. * regarding copyright ownership. The ASF licenses this file
  37491. * to you under the Apache License, Version 2.0 (the
  37492. * "License"); you may not use this file except in compliance
  37493. * with the License. You may obtain a copy of the License at
  37494. *
  37495. * http://www.apache.org/licenses/LICENSE-2.0
  37496. *
  37497. * Unless required by applicable law or agreed to in writing,
  37498. * software distributed under the License is distributed on an
  37499. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37500. * KIND, either express or implied. See the License for the
  37501. * specific language governing permissions and limitations
  37502. * under the License.
  37503. */
  37504. var dataFilter = function (seriesType) {
  37505. return {
  37506. seriesType: seriesType,
  37507. reset: function (seriesModel, ecModel) {
  37508. var legendModels = ecModel.findComponents({
  37509. mainType: 'legend'
  37510. });
  37511. if (!legendModels || !legendModels.length) {
  37512. return;
  37513. }
  37514. var data = seriesModel.getData();
  37515. data.filterSelf(function (idx) {
  37516. var name = data.getName(idx);
  37517. // If in any legend component the status is not selected.
  37518. for (var i = 0; i < legendModels.length; i++) {
  37519. if (!legendModels[i].isSelected(name)) {
  37520. return false;
  37521. }
  37522. }
  37523. return true;
  37524. });
  37525. }
  37526. };
  37527. };
  37528. /*
  37529. * Licensed to the Apache Software Foundation (ASF) under one
  37530. * or more contributor license agreements. See the NOTICE file
  37531. * distributed with this work for additional information
  37532. * regarding copyright ownership. The ASF licenses this file
  37533. * to you under the Apache License, Version 2.0 (the
  37534. * "License"); you may not use this file except in compliance
  37535. * with the License. You may obtain a copy of the License at
  37536. *
  37537. * http://www.apache.org/licenses/LICENSE-2.0
  37538. *
  37539. * Unless required by applicable law or agreed to in writing,
  37540. * software distributed under the License is distributed on an
  37541. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37542. * KIND, either express or implied. See the License for the
  37543. * specific language governing permissions and limitations
  37544. * under the License.
  37545. */
  37546. createDataSelectAction('pie', [{
  37547. type: 'pieToggleSelect',
  37548. event: 'pieselectchanged',
  37549. method: 'toggleSelected'
  37550. }, {
  37551. type: 'pieSelect',
  37552. event: 'pieselected',
  37553. method: 'select'
  37554. }, {
  37555. type: 'pieUnSelect',
  37556. event: 'pieunselected',
  37557. method: 'unSelect'
  37558. }]);
  37559. registerVisual(dataColor('pie'));
  37560. registerLayout(curry(pieLayout, 'pie'));
  37561. registerProcessor(dataFilter('pie'));
  37562. /*
  37563. * Licensed to the Apache Software Foundation (ASF) under one
  37564. * or more contributor license agreements. See the NOTICE file
  37565. * distributed with this work for additional information
  37566. * regarding copyright ownership. The ASF licenses this file
  37567. * to you under the Apache License, Version 2.0 (the
  37568. * "License"); you may not use this file except in compliance
  37569. * with the License. You may obtain a copy of the License at
  37570. *
  37571. * http://www.apache.org/licenses/LICENSE-2.0
  37572. *
  37573. * Unless required by applicable law or agreed to in writing,
  37574. * software distributed under the License is distributed on an
  37575. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37576. * KIND, either express or implied. See the License for the
  37577. * specific language governing permissions and limitations
  37578. * under the License.
  37579. */
  37580. SeriesModel.extend({
  37581. type: 'series.scatter',
  37582. dependencies: ['grid', 'polar', 'geo', 'singleAxis', 'calendar'],
  37583. getInitialData: function (option, ecModel) {
  37584. return createListFromArray(this.getSource(), this);
  37585. },
  37586. brushSelector: 'point',
  37587. getProgressive: function () {
  37588. var progressive = this.option.progressive;
  37589. if (progressive == null) {
  37590. // PENDING
  37591. return this.option.large ? 5e3 : this.get('progressive');
  37592. }
  37593. return progressive;
  37594. },
  37595. getProgressiveThreshold: function () {
  37596. var progressiveThreshold = this.option.progressiveThreshold;
  37597. if (progressiveThreshold == null) {
  37598. // PENDING
  37599. return this.option.large ? 1e4 : this.get('progressiveThreshold');
  37600. }
  37601. return progressiveThreshold;
  37602. },
  37603. defaultOption: {
  37604. coordinateSystem: 'cartesian2d',
  37605. zlevel: 0,
  37606. z: 2,
  37607. legendHoverLink: true,
  37608. hoverAnimation: true,
  37609. // Cartesian coordinate system
  37610. // xAxisIndex: 0,
  37611. // yAxisIndex: 0,
  37612. // Polar coordinate system
  37613. // polarIndex: 0,
  37614. // Geo coordinate system
  37615. // geoIndex: 0,
  37616. // symbol: null, // 图形类型
  37617. symbolSize: 10, // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  37618. // symbolRotate: null, // 图形旋转控制
  37619. large: false,
  37620. // Available when large is true
  37621. largeThreshold: 2000,
  37622. // cursor: null,
  37623. // label: {
  37624. // show: false
  37625. // distance: 5,
  37626. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  37627. // position: 默认自适应,水平布局为'top',垂直布局为'right',可选为
  37628. // 'inside'|'left'|'right'|'top'|'bottom'
  37629. // 默认使用全局文本样式,详见TEXTSTYLE
  37630. // },
  37631. itemStyle: {
  37632. opacity: 0.8
  37633. // color: 各异
  37634. }
  37635. // progressive: null
  37636. }
  37637. });
  37638. /*
  37639. * Licensed to the Apache Software Foundation (ASF) under one
  37640. * or more contributor license agreements. See the NOTICE file
  37641. * distributed with this work for additional information
  37642. * regarding copyright ownership. The ASF licenses this file
  37643. * to you under the Apache License, Version 2.0 (the
  37644. * "License"); you may not use this file except in compliance
  37645. * with the License. You may obtain a copy of the License at
  37646. *
  37647. * http://www.apache.org/licenses/LICENSE-2.0
  37648. *
  37649. * Unless required by applicable law or agreed to in writing,
  37650. * software distributed under the License is distributed on an
  37651. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37652. * KIND, either express or implied. See the License for the
  37653. * specific language governing permissions and limitations
  37654. * under the License.
  37655. */
  37656. /* global Float32Array */
  37657. // TODO Batch by color
  37658. var BOOST_SIZE_THRESHOLD = 4;
  37659. var LargeSymbolPath = extendShape({
  37660. shape: {
  37661. points: null
  37662. },
  37663. symbolProxy: null,
  37664. buildPath: function (path, shape) {
  37665. var points = shape.points;
  37666. var size = shape.size;
  37667. var symbolProxy = this.symbolProxy;
  37668. var symbolProxyShape = symbolProxy.shape;
  37669. var ctx = path.getContext ? path.getContext() : path;
  37670. var canBoost = ctx && size[0] < BOOST_SIZE_THRESHOLD;
  37671. // Do draw in afterBrush.
  37672. if (canBoost) {
  37673. return;
  37674. }
  37675. for (var i = 0; i < points.length;) {
  37676. var x = points[i++];
  37677. var y = points[i++];
  37678. if (isNaN(x) || isNaN(y)) {
  37679. continue;
  37680. }
  37681. symbolProxyShape.x = x - size[0] / 2;
  37682. symbolProxyShape.y = y - size[1] / 2;
  37683. symbolProxyShape.width = size[0];
  37684. symbolProxyShape.height = size[1];
  37685. symbolProxy.buildPath(path, symbolProxyShape, true);
  37686. }
  37687. },
  37688. afterBrush: function (ctx) {
  37689. var shape = this.shape;
  37690. var points = shape.points;
  37691. var size = shape.size;
  37692. var canBoost = size[0] < BOOST_SIZE_THRESHOLD;
  37693. if (!canBoost) {
  37694. return;
  37695. }
  37696. this.setTransform(ctx);
  37697. // PENDING If style or other canvas status changed?
  37698. for (var i = 0; i < points.length;) {
  37699. var x = points[i++];
  37700. var y = points[i++];
  37701. if (isNaN(x) || isNaN(y)) {
  37702. continue;
  37703. }
  37704. // fillRect is faster than building a rect path and draw.
  37705. // And it support light globalCompositeOperation.
  37706. ctx.fillRect(
  37707. x - size[0] / 2, y - size[1] / 2,
  37708. size[0], size[1]
  37709. );
  37710. }
  37711. this.restoreTransform(ctx);
  37712. },
  37713. findDataIndex: function (x, y) {
  37714. // TODO ???
  37715. // Consider transform
  37716. var shape = this.shape;
  37717. var points = shape.points;
  37718. var size = shape.size;
  37719. var w = Math.max(size[0], 4);
  37720. var h = Math.max(size[1], 4);
  37721. // Not consider transform
  37722. // Treat each element as a rect
  37723. // top down traverse
  37724. for (var idx = points.length / 2 - 1; idx >= 0; idx--) {
  37725. var i = idx * 2;
  37726. var x0 = points[i] - w / 2;
  37727. var y0 = points[i + 1] - h / 2;
  37728. if (x >= x0 && y >= y0 && x <= x0 + w && y <= y0 + h) {
  37729. return idx;
  37730. }
  37731. }
  37732. return -1;
  37733. }
  37734. });
  37735. function LargeSymbolDraw() {
  37736. this.group = new Group();
  37737. }
  37738. var largeSymbolProto = LargeSymbolDraw.prototype;
  37739. largeSymbolProto.isPersistent = function () {
  37740. return !this._incremental;
  37741. };
  37742. /**
  37743. * Update symbols draw by new data
  37744. * @param {module:echarts/data/List} data
  37745. */
  37746. largeSymbolProto.updateData = function (data) {
  37747. this.group.removeAll();
  37748. var symbolEl = new LargeSymbolPath({
  37749. rectHover: true,
  37750. cursor: 'default'
  37751. });
  37752. symbolEl.setShape({
  37753. points: data.getLayout('symbolPoints')
  37754. });
  37755. this._setCommon(symbolEl, data);
  37756. this.group.add(symbolEl);
  37757. this._incremental = null;
  37758. };
  37759. largeSymbolProto.updateLayout = function (data) {
  37760. if (this._incremental) {
  37761. return;
  37762. }
  37763. var points = data.getLayout('symbolPoints');
  37764. this.group.eachChild(function (child) {
  37765. if (child.startIndex != null) {
  37766. var len = (child.endIndex - child.startIndex) * 2;
  37767. var byteOffset = child.startIndex * 4 * 2;
  37768. points = new Float32Array(points.buffer, byteOffset, len);
  37769. }
  37770. child.setShape('points', points);
  37771. });
  37772. };
  37773. largeSymbolProto.incrementalPrepareUpdate = function (data) {
  37774. this.group.removeAll();
  37775. this._clearIncremental();
  37776. // Only use incremental displayables when data amount is larger than 2 million.
  37777. // PENDING Incremental data?
  37778. if (data.count() > 2e6) {
  37779. if (!this._incremental) {
  37780. this._incremental = new IncrementalDisplayble({
  37781. silent: true
  37782. });
  37783. }
  37784. this.group.add(this._incremental);
  37785. }
  37786. else {
  37787. this._incremental = null;
  37788. }
  37789. };
  37790. largeSymbolProto.incrementalUpdate = function (taskParams, data) {
  37791. var symbolEl;
  37792. if (this._incremental) {
  37793. symbolEl = new LargeSymbolPath();
  37794. this._incremental.addDisplayable(symbolEl, true);
  37795. }
  37796. else {
  37797. symbolEl = new LargeSymbolPath({
  37798. rectHover: true,
  37799. cursor: 'default',
  37800. startIndex: taskParams.start,
  37801. endIndex: taskParams.end
  37802. });
  37803. symbolEl.incremental = true;
  37804. this.group.add(symbolEl);
  37805. }
  37806. symbolEl.setShape({
  37807. points: data.getLayout('symbolPoints')
  37808. });
  37809. this._setCommon(symbolEl, data, !!this._incremental);
  37810. };
  37811. largeSymbolProto._setCommon = function (symbolEl, data, isIncremental) {
  37812. var hostModel = data.hostModel;
  37813. // TODO
  37814. // if (data.hasItemVisual.symbolSize) {
  37815. // // TODO typed array?
  37816. // symbolEl.setShape('sizes', data.mapArray(
  37817. // function (idx) {
  37818. // var size = data.getItemVisual(idx, 'symbolSize');
  37819. // return (size instanceof Array) ? size : [size, size];
  37820. // }
  37821. // ));
  37822. // }
  37823. // else {
  37824. var size = data.getVisual('symbolSize');
  37825. symbolEl.setShape('size', (size instanceof Array) ? size : [size, size]);
  37826. // }
  37827. // Create symbolProxy to build path for each data
  37828. symbolEl.symbolProxy = createSymbol(
  37829. data.getVisual('symbol'), 0, 0, 0, 0
  37830. );
  37831. // Use symbolProxy setColor method
  37832. symbolEl.setColor = symbolEl.symbolProxy.setColor;
  37833. var extrudeShadow = symbolEl.shape.size[0] < BOOST_SIZE_THRESHOLD;
  37834. symbolEl.useStyle(
  37835. // Draw shadow when doing fillRect is extremely slow.
  37836. hostModel.getModel('itemStyle').getItemStyle(extrudeShadow ? ['color', 'shadowBlur', 'shadowColor'] : ['color'])
  37837. );
  37838. var visualColor = data.getVisual('color');
  37839. if (visualColor) {
  37840. symbolEl.setColor(visualColor);
  37841. }
  37842. if (!isIncremental) {
  37843. // Enable tooltip
  37844. // PENDING May have performance issue when path is extremely large
  37845. symbolEl.seriesIndex = hostModel.seriesIndex;
  37846. symbolEl.on('mousemove', function (e) {
  37847. symbolEl.dataIndex = null;
  37848. var dataIndex = symbolEl.findDataIndex(e.offsetX, e.offsetY);
  37849. if (dataIndex >= 0) {
  37850. // Provide dataIndex for tooltip
  37851. symbolEl.dataIndex = dataIndex + (symbolEl.startIndex || 0);
  37852. }
  37853. });
  37854. }
  37855. };
  37856. largeSymbolProto.remove = function () {
  37857. this._clearIncremental();
  37858. this._incremental = null;
  37859. this.group.removeAll();
  37860. };
  37861. largeSymbolProto._clearIncremental = function () {
  37862. var incremental = this._incremental;
  37863. if (incremental) {
  37864. incremental.clearDisplaybles();
  37865. }
  37866. };
  37867. /*
  37868. * Licensed to the Apache Software Foundation (ASF) under one
  37869. * or more contributor license agreements. See the NOTICE file
  37870. * distributed with this work for additional information
  37871. * regarding copyright ownership. The ASF licenses this file
  37872. * to you under the Apache License, Version 2.0 (the
  37873. * "License"); you may not use this file except in compliance
  37874. * with the License. You may obtain a copy of the License at
  37875. *
  37876. * http://www.apache.org/licenses/LICENSE-2.0
  37877. *
  37878. * Unless required by applicable law or agreed to in writing,
  37879. * software distributed under the License is distributed on an
  37880. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37881. * KIND, either express or implied. See the License for the
  37882. * specific language governing permissions and limitations
  37883. * under the License.
  37884. */
  37885. extendChartView({
  37886. type: 'scatter',
  37887. render: function (seriesModel, ecModel, api) {
  37888. var data = seriesModel.getData();
  37889. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  37890. symbolDraw.updateData(data);
  37891. this._finished = true;
  37892. },
  37893. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  37894. var data = seriesModel.getData();
  37895. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  37896. symbolDraw.incrementalPrepareUpdate(data);
  37897. this._finished = false;
  37898. },
  37899. incrementalRender: function (taskParams, seriesModel, ecModel) {
  37900. this._symbolDraw.incrementalUpdate(taskParams, seriesModel.getData());
  37901. this._finished = taskParams.end === seriesModel.getData().count();
  37902. },
  37903. updateTransform: function (seriesModel, ecModel, api) {
  37904. var data = seriesModel.getData();
  37905. // Must mark group dirty and make sure the incremental layer will be cleared
  37906. // PENDING
  37907. this.group.dirty();
  37908. if (!this._finished || data.count() > 1e4 || !this._symbolDraw.isPersistent()) {
  37909. return {
  37910. update: true
  37911. };
  37912. }
  37913. else {
  37914. var res = pointsLayout().reset(seriesModel);
  37915. if (res.progress) {
  37916. res.progress({ start: 0, end: data.count() }, data);
  37917. }
  37918. this._symbolDraw.updateLayout(data);
  37919. }
  37920. },
  37921. _updateSymbolDraw: function (data, seriesModel) {
  37922. var symbolDraw = this._symbolDraw;
  37923. var pipelineContext = seriesModel.pipelineContext;
  37924. var isLargeDraw = pipelineContext.large;
  37925. if (!symbolDraw || isLargeDraw !== this._isLargeDraw) {
  37926. symbolDraw && symbolDraw.remove();
  37927. symbolDraw = this._symbolDraw = isLargeDraw
  37928. ? new LargeSymbolDraw()
  37929. : new SymbolDraw();
  37930. this._isLargeDraw = isLargeDraw;
  37931. this.group.removeAll();
  37932. }
  37933. this.group.add(symbolDraw.group);
  37934. return symbolDraw;
  37935. },
  37936. remove: function (ecModel, api) {
  37937. this._symbolDraw && this._symbolDraw.remove(true);
  37938. this._symbolDraw = null;
  37939. },
  37940. dispose: function () {}
  37941. });
  37942. /*
  37943. * Licensed to the Apache Software Foundation (ASF) under one
  37944. * or more contributor license agreements. See the NOTICE file
  37945. * distributed with this work for additional information
  37946. * regarding copyright ownership. The ASF licenses this file
  37947. * to you under the Apache License, Version 2.0 (the
  37948. * "License"); you may not use this file except in compliance
  37949. * with the License. You may obtain a copy of the License at
  37950. *
  37951. * http://www.apache.org/licenses/LICENSE-2.0
  37952. *
  37953. * Unless required by applicable law or agreed to in writing,
  37954. * software distributed under the License is distributed on an
  37955. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37956. * KIND, either express or implied. See the License for the
  37957. * specific language governing permissions and limitations
  37958. * under the License.
  37959. */
  37960. // import * as zrUtil from 'zrender/src/core/util';
  37961. // In case developer forget to include grid component
  37962. registerVisual(visualSymbol('scatter', 'circle'));
  37963. registerLayout(pointsLayout('scatter'));
  37964. // echarts.registerProcessor(function (ecModel, api) {
  37965. // ecModel.eachSeriesByType('scatter', function (seriesModel) {
  37966. // var data = seriesModel.getData();
  37967. // var coordSys = seriesModel.coordinateSystem;
  37968. // if (coordSys.type !== 'geo') {
  37969. // return;
  37970. // }
  37971. // var startPt = coordSys.pointToData([0, 0]);
  37972. // var endPt = coordSys.pointToData([api.getWidth(), api.getHeight()]);
  37973. // var dims = zrUtil.map(coordSys.dimensions, function (dim) {
  37974. // return data.mapDimension(dim);
  37975. // });
  37976. // var range = {};
  37977. // range[dims[0]] = [Math.min(startPt[0], endPt[0]), Math.max(startPt[0], endPt[0])];
  37978. // range[dims[1]] = [Math.min(startPt[1], endPt[1]), Math.max(startPt[1], endPt[1])];
  37979. // data.selectRange(range);
  37980. // });
  37981. // });
  37982. /*
  37983. * Licensed to the Apache Software Foundation (ASF) under one
  37984. * or more contributor license agreements. See the NOTICE file
  37985. * distributed with this work for additional information
  37986. * regarding copyright ownership. The ASF licenses this file
  37987. * to you under the Apache License, Version 2.0 (the
  37988. * "License"); you may not use this file except in compliance
  37989. * with the License. You may obtain a copy of the License at
  37990. *
  37991. * http://www.apache.org/licenses/LICENSE-2.0
  37992. *
  37993. * Unless required by applicable law or agreed to in writing,
  37994. * software distributed under the License is distributed on an
  37995. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37996. * KIND, either express or implied. See the License for the
  37997. * specific language governing permissions and limitations
  37998. * under the License.
  37999. */
  38000. function IndicatorAxis(dim, scale, radiusExtent) {
  38001. Axis.call(this, dim, scale, radiusExtent);
  38002. /**
  38003. * Axis type
  38004. * - 'category'
  38005. * - 'value'
  38006. * - 'time'
  38007. * - 'log'
  38008. * @type {string}
  38009. */
  38010. this.type = 'value';
  38011. this.angle = 0;
  38012. /**
  38013. * Indicator name
  38014. * @type {string}
  38015. */
  38016. this.name = '';
  38017. /**
  38018. * @type {module:echarts/model/Model}
  38019. */
  38020. this.model;
  38021. }
  38022. inherits(IndicatorAxis, Axis);
  38023. /*
  38024. * Licensed to the Apache Software Foundation (ASF) under one
  38025. * or more contributor license agreements. See the NOTICE file
  38026. * distributed with this work for additional information
  38027. * regarding copyright ownership. The ASF licenses this file
  38028. * to you under the Apache License, Version 2.0 (the
  38029. * "License"); you may not use this file except in compliance
  38030. * with the License. You may obtain a copy of the License at
  38031. *
  38032. * http://www.apache.org/licenses/LICENSE-2.0
  38033. *
  38034. * Unless required by applicable law or agreed to in writing,
  38035. * software distributed under the License is distributed on an
  38036. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38037. * KIND, either express or implied. See the License for the
  38038. * specific language governing permissions and limitations
  38039. * under the License.
  38040. */
  38041. // TODO clockwise
  38042. function Radar(radarModel, ecModel, api) {
  38043. this._model = radarModel;
  38044. /**
  38045. * Radar dimensions
  38046. * @type {Array.<string>}
  38047. */
  38048. this.dimensions = [];
  38049. this._indicatorAxes = map(radarModel.getIndicatorModels(), function (indicatorModel, idx) {
  38050. var dim = 'indicator_' + idx;
  38051. var indicatorAxis = new IndicatorAxis(dim, new IntervalScale());
  38052. indicatorAxis.name = indicatorModel.get('name');
  38053. // Inject model and axis
  38054. indicatorAxis.model = indicatorModel;
  38055. indicatorModel.axis = indicatorAxis;
  38056. this.dimensions.push(dim);
  38057. return indicatorAxis;
  38058. }, this);
  38059. this.resize(radarModel, api);
  38060. /**
  38061. * @type {number}
  38062. * @readOnly
  38063. */
  38064. this.cx;
  38065. /**
  38066. * @type {number}
  38067. * @readOnly
  38068. */
  38069. this.cy;
  38070. /**
  38071. * @type {number}
  38072. * @readOnly
  38073. */
  38074. this.r;
  38075. /**
  38076. * @type {number}
  38077. * @readOnly
  38078. */
  38079. this.r0;
  38080. /**
  38081. * @type {number}
  38082. * @readOnly
  38083. */
  38084. this.startAngle;
  38085. }
  38086. Radar.prototype.getIndicatorAxes = function () {
  38087. return this._indicatorAxes;
  38088. };
  38089. Radar.prototype.dataToPoint = function (value, indicatorIndex) {
  38090. var indicatorAxis = this._indicatorAxes[indicatorIndex];
  38091. return this.coordToPoint(indicatorAxis.dataToCoord(value), indicatorIndex);
  38092. };
  38093. Radar.prototype.coordToPoint = function (coord, indicatorIndex) {
  38094. var indicatorAxis = this._indicatorAxes[indicatorIndex];
  38095. var angle = indicatorAxis.angle;
  38096. var x = this.cx + coord * Math.cos(angle);
  38097. var y = this.cy - coord * Math.sin(angle);
  38098. return [x, y];
  38099. };
  38100. Radar.prototype.pointToData = function (pt) {
  38101. var dx = pt[0] - this.cx;
  38102. var dy = pt[1] - this.cy;
  38103. var radius = Math.sqrt(dx * dx + dy * dy);
  38104. dx /= radius;
  38105. dy /= radius;
  38106. var radian = Math.atan2(-dy, dx);
  38107. // Find the closest angle
  38108. // FIXME index can calculated directly
  38109. var minRadianDiff = Infinity;
  38110. var closestAxis;
  38111. var closestAxisIdx = -1;
  38112. for (var i = 0; i < this._indicatorAxes.length; i++) {
  38113. var indicatorAxis = this._indicatorAxes[i];
  38114. var diff = Math.abs(radian - indicatorAxis.angle);
  38115. if (diff < minRadianDiff) {
  38116. closestAxis = indicatorAxis;
  38117. closestAxisIdx = i;
  38118. minRadianDiff = diff;
  38119. }
  38120. }
  38121. return [closestAxisIdx, +(closestAxis && closestAxis.coodToData(radius))];
  38122. };
  38123. Radar.prototype.resize = function (radarModel, api) {
  38124. var center = radarModel.get('center');
  38125. var viewWidth = api.getWidth();
  38126. var viewHeight = api.getHeight();
  38127. var viewSize = Math.min(viewWidth, viewHeight) / 2;
  38128. this.cx = parsePercent$1(center[0], viewWidth);
  38129. this.cy = parsePercent$1(center[1], viewHeight);
  38130. this.startAngle = radarModel.get('startAngle') * Math.PI / 180;
  38131. // radius may be single value like `20`, `'80%'`, or array like `[10, '80%']`
  38132. var radius = radarModel.get('radius');
  38133. if (typeof radius === 'string' || typeof radius === 'number') {
  38134. radius = [0, radius];
  38135. }
  38136. this.r0 = parsePercent$1(radius[0], viewSize);
  38137. this.r = parsePercent$1(radius[1], viewSize);
  38138. each$1(this._indicatorAxes, function (indicatorAxis, idx) {
  38139. indicatorAxis.setExtent(this.r0, this.r);
  38140. var angle = (this.startAngle + idx * Math.PI * 2 / this._indicatorAxes.length);
  38141. // Normalize to [-PI, PI]
  38142. angle = Math.atan2(Math.sin(angle), Math.cos(angle));
  38143. indicatorAxis.angle = angle;
  38144. }, this);
  38145. };
  38146. Radar.prototype.update = function (ecModel, api) {
  38147. var indicatorAxes = this._indicatorAxes;
  38148. var radarModel = this._model;
  38149. each$1(indicatorAxes, function (indicatorAxis) {
  38150. indicatorAxis.scale.setExtent(Infinity, -Infinity);
  38151. });
  38152. ecModel.eachSeriesByType('radar', function (radarSeries, idx) {
  38153. if (radarSeries.get('coordinateSystem') !== 'radar'
  38154. || ecModel.getComponent('radar', radarSeries.get('radarIndex')) !== radarModel
  38155. ) {
  38156. return;
  38157. }
  38158. var data = radarSeries.getData();
  38159. each$1(indicatorAxes, function (indicatorAxis) {
  38160. indicatorAxis.scale.unionExtentFromData(data, data.mapDimension(indicatorAxis.dim));
  38161. });
  38162. }, this);
  38163. var splitNumber = radarModel.get('splitNumber');
  38164. function increaseInterval(interval) {
  38165. var exp10 = Math.pow(10, Math.floor(Math.log(interval) / Math.LN10));
  38166. // Increase interval
  38167. var f = interval / exp10;
  38168. if (f === 2) {
  38169. f = 5;
  38170. }
  38171. else { // f is 2 or 5
  38172. f *= 2;
  38173. }
  38174. return f * exp10;
  38175. }
  38176. // Force all the axis fixing the maxSplitNumber.
  38177. each$1(indicatorAxes, function (indicatorAxis, idx) {
  38178. var rawExtent = getScaleExtent(indicatorAxis.scale, indicatorAxis.model);
  38179. niceScaleExtent(indicatorAxis.scale, indicatorAxis.model);
  38180. var axisModel = indicatorAxis.model;
  38181. var scale = indicatorAxis.scale;
  38182. var fixedMin = axisModel.getMin();
  38183. var fixedMax = axisModel.getMax();
  38184. var interval = scale.getInterval();
  38185. if (fixedMin != null && fixedMax != null) {
  38186. // User set min, max, divide to get new interval
  38187. scale.setExtent(+fixedMin, +fixedMax);
  38188. scale.setInterval(
  38189. (fixedMax - fixedMin) / splitNumber
  38190. );
  38191. }
  38192. else if (fixedMin != null) {
  38193. var max;
  38194. // User set min, expand extent on the other side
  38195. do {
  38196. max = fixedMin + interval * splitNumber;
  38197. scale.setExtent(+fixedMin, max);
  38198. // Interval must been set after extent
  38199. // FIXME
  38200. scale.setInterval(interval);
  38201. interval = increaseInterval(interval);
  38202. } while (max < rawExtent[1] && isFinite(max) && isFinite(rawExtent[1]));
  38203. }
  38204. else if (fixedMax != null) {
  38205. var min;
  38206. // User set min, expand extent on the other side
  38207. do {
  38208. min = fixedMax - interval * splitNumber;
  38209. scale.setExtent(min, +fixedMax);
  38210. scale.setInterval(interval);
  38211. interval = increaseInterval(interval);
  38212. } while (min > rawExtent[0] && isFinite(min) && isFinite(rawExtent[0]));
  38213. }
  38214. else {
  38215. var nicedSplitNumber = scale.getTicks().length - 1;
  38216. if (nicedSplitNumber > splitNumber) {
  38217. interval = increaseInterval(interval);
  38218. }
  38219. // PENDING
  38220. var center = Math.round((rawExtent[0] + rawExtent[1]) / 2 / interval) * interval;
  38221. var halfSplitNumber = Math.round(splitNumber / 2);
  38222. scale.setExtent(
  38223. round$2(center - halfSplitNumber * interval),
  38224. round$2(center + (splitNumber - halfSplitNumber) * interval)
  38225. );
  38226. scale.setInterval(interval);
  38227. }
  38228. });
  38229. };
  38230. /**
  38231. * Radar dimensions is based on the data
  38232. * @type {Array}
  38233. */
  38234. Radar.dimensions = [];
  38235. Radar.create = function (ecModel, api) {
  38236. var radarList = [];
  38237. ecModel.eachComponent('radar', function (radarModel) {
  38238. var radar = new Radar(radarModel, ecModel, api);
  38239. radarList.push(radar);
  38240. radarModel.coordinateSystem = radar;
  38241. });
  38242. ecModel.eachSeriesByType('radar', function (radarSeries) {
  38243. if (radarSeries.get('coordinateSystem') === 'radar') {
  38244. // Inject coordinate system
  38245. radarSeries.coordinateSystem = radarList[radarSeries.get('radarIndex') || 0];
  38246. }
  38247. });
  38248. return radarList;
  38249. };
  38250. CoordinateSystemManager.register('radar', Radar);
  38251. /*
  38252. * Licensed to the Apache Software Foundation (ASF) under one
  38253. * or more contributor license agreements. See the NOTICE file
  38254. * distributed with this work for additional information
  38255. * regarding copyright ownership. The ASF licenses this file
  38256. * to you under the Apache License, Version 2.0 (the
  38257. * "License"); you may not use this file except in compliance
  38258. * with the License. You may obtain a copy of the License at
  38259. *
  38260. * http://www.apache.org/licenses/LICENSE-2.0
  38261. *
  38262. * Unless required by applicable law or agreed to in writing,
  38263. * software distributed under the License is distributed on an
  38264. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38265. * KIND, either express or implied. See the License for the
  38266. * specific language governing permissions and limitations
  38267. * under the License.
  38268. */
  38269. var valueAxisDefault = axisDefault.valueAxis;
  38270. function defaultsShow(opt, show) {
  38271. return defaults({
  38272. show: show
  38273. }, opt);
  38274. }
  38275. var RadarModel = extendComponentModel({
  38276. type: 'radar',
  38277. optionUpdated: function () {
  38278. var boundaryGap = this.get('boundaryGap');
  38279. var splitNumber = this.get('splitNumber');
  38280. var scale = this.get('scale');
  38281. var axisLine = this.get('axisLine');
  38282. var axisTick = this.get('axisTick');
  38283. var axisLabel = this.get('axisLabel');
  38284. var nameTextStyle = this.get('name');
  38285. var showName = this.get('name.show');
  38286. var nameFormatter = this.get('name.formatter');
  38287. var nameGap = this.get('nameGap');
  38288. var triggerEvent = this.get('triggerEvent');
  38289. var indicatorModels = map(this.get('indicator') || [], function (indicatorOpt) {
  38290. // PENDING
  38291. if (indicatorOpt.max != null && indicatorOpt.max > 0 && !indicatorOpt.min) {
  38292. indicatorOpt.min = 0;
  38293. }
  38294. else if (indicatorOpt.min != null && indicatorOpt.min < 0 && !indicatorOpt.max) {
  38295. indicatorOpt.max = 0;
  38296. }
  38297. var iNameTextStyle = nameTextStyle;
  38298. if (indicatorOpt.color != null) {
  38299. iNameTextStyle = defaults({color: indicatorOpt.color}, nameTextStyle);
  38300. }
  38301. // Use same configuration
  38302. indicatorOpt = merge(clone(indicatorOpt), {
  38303. boundaryGap: boundaryGap,
  38304. splitNumber: splitNumber,
  38305. scale: scale,
  38306. axisLine: axisLine,
  38307. axisTick: axisTick,
  38308. axisLabel: axisLabel,
  38309. // Competitable with 2 and use text
  38310. name: indicatorOpt.text,
  38311. nameLocation: 'end',
  38312. nameGap: nameGap,
  38313. // min: 0,
  38314. nameTextStyle: iNameTextStyle,
  38315. triggerEvent: triggerEvent
  38316. }, false);
  38317. if (!showName) {
  38318. indicatorOpt.name = '';
  38319. }
  38320. if (typeof nameFormatter === 'string') {
  38321. var indName = indicatorOpt.name;
  38322. indicatorOpt.name = nameFormatter.replace('{value}', indName != null ? indName : '');
  38323. }
  38324. else if (typeof nameFormatter === 'function') {
  38325. indicatorOpt.name = nameFormatter(
  38326. indicatorOpt.name, indicatorOpt
  38327. );
  38328. }
  38329. var model = extend(
  38330. new Model(indicatorOpt, null, this.ecModel),
  38331. axisModelCommonMixin
  38332. );
  38333. // For triggerEvent.
  38334. model.mainType = 'radar';
  38335. model.componentIndex = this.componentIndex;
  38336. return model;
  38337. }, this);
  38338. this.getIndicatorModels = function () {
  38339. return indicatorModels;
  38340. };
  38341. },
  38342. defaultOption: {
  38343. zlevel: 0,
  38344. z: 0,
  38345. center: ['50%', '50%'],
  38346. radius: '75%',
  38347. startAngle: 90,
  38348. name: {
  38349. show: true
  38350. // formatter: null
  38351. // textStyle: {}
  38352. },
  38353. boundaryGap: [0, 0],
  38354. splitNumber: 5,
  38355. nameGap: 15,
  38356. scale: false,
  38357. // Polygon or circle
  38358. shape: 'polygon',
  38359. axisLine: merge(
  38360. {
  38361. lineStyle: {
  38362. color: '#bbb'
  38363. }
  38364. },
  38365. valueAxisDefault.axisLine
  38366. ),
  38367. axisLabel: defaultsShow(valueAxisDefault.axisLabel, false),
  38368. axisTick: defaultsShow(valueAxisDefault.axisTick, false),
  38369. splitLine: defaultsShow(valueAxisDefault.splitLine, true),
  38370. splitArea: defaultsShow(valueAxisDefault.splitArea, true),
  38371. // {text, min, max}
  38372. indicator: []
  38373. }
  38374. });
  38375. /*
  38376. * Licensed to the Apache Software Foundation (ASF) under one
  38377. * or more contributor license agreements. See the NOTICE file
  38378. * distributed with this work for additional information
  38379. * regarding copyright ownership. The ASF licenses this file
  38380. * to you under the Apache License, Version 2.0 (the
  38381. * "License"); you may not use this file except in compliance
  38382. * with the License. You may obtain a copy of the License at
  38383. *
  38384. * http://www.apache.org/licenses/LICENSE-2.0
  38385. *
  38386. * Unless required by applicable law or agreed to in writing,
  38387. * software distributed under the License is distributed on an
  38388. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38389. * KIND, either express or implied. See the License for the
  38390. * specific language governing permissions and limitations
  38391. * under the License.
  38392. */
  38393. var axisBuilderAttrs$1 = [
  38394. 'axisLine', 'axisTickLabel', 'axisName'
  38395. ];
  38396. extendComponentView({
  38397. type: 'radar',
  38398. render: function (radarModel, ecModel, api) {
  38399. var group = this.group;
  38400. group.removeAll();
  38401. this._buildAxes(radarModel);
  38402. this._buildSplitLineAndArea(radarModel);
  38403. },
  38404. _buildAxes: function (radarModel) {
  38405. var radar = radarModel.coordinateSystem;
  38406. var indicatorAxes = radar.getIndicatorAxes();
  38407. var axisBuilders = map(indicatorAxes, function (indicatorAxis) {
  38408. var axisBuilder = new AxisBuilder(indicatorAxis.model, {
  38409. position: [radar.cx, radar.cy],
  38410. rotation: indicatorAxis.angle,
  38411. labelDirection: -1,
  38412. tickDirection: -1,
  38413. nameDirection: 1
  38414. });
  38415. return axisBuilder;
  38416. });
  38417. each$1(axisBuilders, function (axisBuilder) {
  38418. each$1(axisBuilderAttrs$1, axisBuilder.add, axisBuilder);
  38419. this.group.add(axisBuilder.getGroup());
  38420. }, this);
  38421. },
  38422. _buildSplitLineAndArea: function (radarModel) {
  38423. var radar = radarModel.coordinateSystem;
  38424. var indicatorAxes = radar.getIndicatorAxes();
  38425. if (!indicatorAxes.length) {
  38426. return;
  38427. }
  38428. var shape = radarModel.get('shape');
  38429. var splitLineModel = radarModel.getModel('splitLine');
  38430. var splitAreaModel = radarModel.getModel('splitArea');
  38431. var lineStyleModel = splitLineModel.getModel('lineStyle');
  38432. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  38433. var showSplitLine = splitLineModel.get('show');
  38434. var showSplitArea = splitAreaModel.get('show');
  38435. var splitLineColors = lineStyleModel.get('color');
  38436. var splitAreaColors = areaStyleModel.get('color');
  38437. splitLineColors = isArray(splitLineColors) ? splitLineColors : [splitLineColors];
  38438. splitAreaColors = isArray(splitAreaColors) ? splitAreaColors : [splitAreaColors];
  38439. var splitLines = [];
  38440. var splitAreas = [];
  38441. function getColorIndex(areaOrLine, areaOrLineColorList, idx) {
  38442. var colorIndex = idx % areaOrLineColorList.length;
  38443. areaOrLine[colorIndex] = areaOrLine[colorIndex] || [];
  38444. return colorIndex;
  38445. }
  38446. if (shape === 'circle') {
  38447. var ticksRadius = indicatorAxes[0].getTicksCoords();
  38448. var cx = radar.cx;
  38449. var cy = radar.cy;
  38450. for (var i = 0; i < ticksRadius.length; i++) {
  38451. if (showSplitLine) {
  38452. var colorIndex = getColorIndex(splitLines, splitLineColors, i);
  38453. splitLines[colorIndex].push(new Circle({
  38454. shape: {
  38455. cx: cx,
  38456. cy: cy,
  38457. r: ticksRadius[i].coord
  38458. }
  38459. }));
  38460. }
  38461. if (showSplitArea && i < ticksRadius.length - 1) {
  38462. var colorIndex = getColorIndex(splitAreas, splitAreaColors, i);
  38463. splitAreas[colorIndex].push(new Ring({
  38464. shape: {
  38465. cx: cx,
  38466. cy: cy,
  38467. r0: ticksRadius[i].coord,
  38468. r: ticksRadius[i + 1].coord
  38469. }
  38470. }));
  38471. }
  38472. }
  38473. }
  38474. // Polyyon
  38475. else {
  38476. var realSplitNumber;
  38477. var axesTicksPoints = map(indicatorAxes, function (indicatorAxis, idx) {
  38478. var ticksCoords = indicatorAxis.getTicksCoords();
  38479. realSplitNumber = realSplitNumber == null
  38480. ? ticksCoords.length - 1
  38481. : Math.min(ticksCoords.length - 1, realSplitNumber);
  38482. return map(ticksCoords, function (tickCoord) {
  38483. return radar.coordToPoint(tickCoord.coord, idx);
  38484. });
  38485. });
  38486. var prevPoints = [];
  38487. for (var i = 0; i <= realSplitNumber; i++) {
  38488. var points = [];
  38489. for (var j = 0; j < indicatorAxes.length; j++) {
  38490. points.push(axesTicksPoints[j][i]);
  38491. }
  38492. // Close
  38493. if (points[0]) {
  38494. points.push(points[0].slice());
  38495. }
  38496. else {
  38497. if (__DEV__) {
  38498. console.error('Can\'t draw value axis ' + i);
  38499. }
  38500. }
  38501. if (showSplitLine) {
  38502. var colorIndex = getColorIndex(splitLines, splitLineColors, i);
  38503. splitLines[colorIndex].push(new Polyline({
  38504. shape: {
  38505. points: points
  38506. }
  38507. }));
  38508. }
  38509. if (showSplitArea && prevPoints) {
  38510. var colorIndex = getColorIndex(splitAreas, splitAreaColors, i - 1);
  38511. splitAreas[colorIndex].push(new Polygon({
  38512. shape: {
  38513. points: points.concat(prevPoints)
  38514. }
  38515. }));
  38516. }
  38517. prevPoints = points.slice().reverse();
  38518. }
  38519. }
  38520. var lineStyle = lineStyleModel.getLineStyle();
  38521. var areaStyle = areaStyleModel.getAreaStyle();
  38522. // Add splitArea before splitLine
  38523. each$1(splitAreas, function (splitAreas, idx) {
  38524. this.group.add(mergePath(
  38525. splitAreas, {
  38526. style: defaults({
  38527. stroke: 'none',
  38528. fill: splitAreaColors[idx % splitAreaColors.length]
  38529. }, areaStyle),
  38530. silent: true
  38531. }
  38532. ));
  38533. }, this);
  38534. each$1(splitLines, function (splitLines, idx) {
  38535. this.group.add(mergePath(
  38536. splitLines, {
  38537. style: defaults({
  38538. fill: 'none',
  38539. stroke: splitLineColors[idx % splitLineColors.length]
  38540. }, lineStyle),
  38541. silent: true
  38542. }
  38543. ));
  38544. }, this);
  38545. }
  38546. });
  38547. /*
  38548. * Licensed to the Apache Software Foundation (ASF) under one
  38549. * or more contributor license agreements. See the NOTICE file
  38550. * distributed with this work for additional information
  38551. * regarding copyright ownership. The ASF licenses this file
  38552. * to you under the Apache License, Version 2.0 (the
  38553. * "License"); you may not use this file except in compliance
  38554. * with the License. You may obtain a copy of the License at
  38555. *
  38556. * http://www.apache.org/licenses/LICENSE-2.0
  38557. *
  38558. * Unless required by applicable law or agreed to in writing,
  38559. * software distributed under the License is distributed on an
  38560. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38561. * KIND, either express or implied. See the License for the
  38562. * specific language governing permissions and limitations
  38563. * under the License.
  38564. */
  38565. /*
  38566. * Licensed to the Apache Software Foundation (ASF) under one
  38567. * or more contributor license agreements. See the NOTICE file
  38568. * distributed with this work for additional information
  38569. * regarding copyright ownership. The ASF licenses this file
  38570. * to you under the Apache License, Version 2.0 (the
  38571. * "License"); you may not use this file except in compliance
  38572. * with the License. You may obtain a copy of the License at
  38573. *
  38574. * http://www.apache.org/licenses/LICENSE-2.0
  38575. *
  38576. * Unless required by applicable law or agreed to in writing,
  38577. * software distributed under the License is distributed on an
  38578. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38579. * KIND, either express or implied. See the License for the
  38580. * specific language governing permissions and limitations
  38581. * under the License.
  38582. */
  38583. var RadarSeries = SeriesModel.extend({
  38584. type: 'series.radar',
  38585. dependencies: ['radar'],
  38586. // Overwrite
  38587. init: function (option) {
  38588. RadarSeries.superApply(this, 'init', arguments);
  38589. // Enable legend selection for each data item
  38590. // Use a function instead of direct access because data reference may changed
  38591. this.legendDataProvider = function () {
  38592. return this.getRawData();
  38593. };
  38594. },
  38595. getInitialData: function (option, ecModel) {
  38596. return createListSimply(this, {
  38597. generateCoord: 'indicator_',
  38598. generateCoordCount: Infinity
  38599. });
  38600. },
  38601. formatTooltip: function (dataIndex) {
  38602. var data = this.getData();
  38603. var coordSys = this.coordinateSystem;
  38604. var indicatorAxes = coordSys.getIndicatorAxes();
  38605. var name = this.getData().getName(dataIndex);
  38606. return encodeHTML(name === '' ? this.name : name) + '<br/>'
  38607. + map(indicatorAxes, function (axis, idx) {
  38608. var val = data.get(data.mapDimension(axis.dim), dataIndex);
  38609. return encodeHTML(axis.name + ' : ' + val);
  38610. }).join('<br />');
  38611. },
  38612. defaultOption: {
  38613. zlevel: 0,
  38614. z: 2,
  38615. coordinateSystem: 'radar',
  38616. legendHoverLink: true,
  38617. radarIndex: 0,
  38618. lineStyle: {
  38619. width: 2,
  38620. type: 'solid'
  38621. },
  38622. label: {
  38623. position: 'top'
  38624. },
  38625. // areaStyle: {
  38626. // },
  38627. // itemStyle: {}
  38628. symbol: 'emptyCircle',
  38629. symbolSize: 4
  38630. // symbolRotate: null
  38631. }
  38632. });
  38633. /*
  38634. * Licensed to the Apache Software Foundation (ASF) under one
  38635. * or more contributor license agreements. See the NOTICE file
  38636. * distributed with this work for additional information
  38637. * regarding copyright ownership. The ASF licenses this file
  38638. * to you under the Apache License, Version 2.0 (the
  38639. * "License"); you may not use this file except in compliance
  38640. * with the License. You may obtain a copy of the License at
  38641. *
  38642. * http://www.apache.org/licenses/LICENSE-2.0
  38643. *
  38644. * Unless required by applicable law or agreed to in writing,
  38645. * software distributed under the License is distributed on an
  38646. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38647. * KIND, either express or implied. See the License for the
  38648. * specific language governing permissions and limitations
  38649. * under the License.
  38650. */
  38651. function normalizeSymbolSize(symbolSize) {
  38652. if (!isArray(symbolSize)) {
  38653. symbolSize = [+symbolSize, +symbolSize];
  38654. }
  38655. return symbolSize;
  38656. }
  38657. extendChartView({
  38658. type: 'radar',
  38659. render: function (seriesModel, ecModel, api) {
  38660. var polar = seriesModel.coordinateSystem;
  38661. var group = this.group;
  38662. var data = seriesModel.getData();
  38663. var oldData = this._data;
  38664. function createSymbol$$1(data, idx) {
  38665. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  38666. var color = data.getItemVisual(idx, 'color');
  38667. if (symbolType === 'none') {
  38668. return;
  38669. }
  38670. var symbolSize = normalizeSymbolSize(
  38671. data.getItemVisual(idx, 'symbolSize')
  38672. );
  38673. var symbolPath = createSymbol(
  38674. symbolType, -1, -1, 2, 2, color
  38675. );
  38676. symbolPath.attr({
  38677. style: {
  38678. strokeNoScale: true
  38679. },
  38680. z2: 100,
  38681. scale: [symbolSize[0] / 2, symbolSize[1] / 2]
  38682. });
  38683. return symbolPath;
  38684. }
  38685. function updateSymbols(oldPoints, newPoints, symbolGroup, data, idx, isInit) {
  38686. // Simply rerender all
  38687. symbolGroup.removeAll();
  38688. for (var i = 0; i < newPoints.length - 1; i++) {
  38689. var symbolPath = createSymbol$$1(data, idx);
  38690. if (symbolPath) {
  38691. symbolPath.__dimIdx = i;
  38692. if (oldPoints[i]) {
  38693. symbolPath.attr('position', oldPoints[i]);
  38694. graphic[isInit ? 'initProps' : 'updateProps'](
  38695. symbolPath, {
  38696. position: newPoints[i]
  38697. }, seriesModel, idx
  38698. );
  38699. }
  38700. else {
  38701. symbolPath.attr('position', newPoints[i]);
  38702. }
  38703. symbolGroup.add(symbolPath);
  38704. }
  38705. }
  38706. }
  38707. function getInitialPoints(points) {
  38708. return map(points, function (pt) {
  38709. return [polar.cx, polar.cy];
  38710. });
  38711. }
  38712. data.diff(oldData)
  38713. .add(function (idx) {
  38714. var points = data.getItemLayout(idx);
  38715. if (!points) {
  38716. return;
  38717. }
  38718. var polygon = new Polygon();
  38719. var polyline = new Polyline();
  38720. var target = {
  38721. shape: {
  38722. points: points
  38723. }
  38724. };
  38725. polygon.shape.points = getInitialPoints(points);
  38726. polyline.shape.points = getInitialPoints(points);
  38727. initProps(polygon, target, seriesModel, idx);
  38728. initProps(polyline, target, seriesModel, idx);
  38729. var itemGroup = new Group();
  38730. var symbolGroup = new Group();
  38731. itemGroup.add(polyline);
  38732. itemGroup.add(polygon);
  38733. itemGroup.add(symbolGroup);
  38734. updateSymbols(
  38735. polyline.shape.points, points, symbolGroup, data, idx, true
  38736. );
  38737. data.setItemGraphicEl(idx, itemGroup);
  38738. })
  38739. .update(function (newIdx, oldIdx) {
  38740. var itemGroup = oldData.getItemGraphicEl(oldIdx);
  38741. var polyline = itemGroup.childAt(0);
  38742. var polygon = itemGroup.childAt(1);
  38743. var symbolGroup = itemGroup.childAt(2);
  38744. var target = {
  38745. shape: {
  38746. points: data.getItemLayout(newIdx)
  38747. }
  38748. };
  38749. if (!target.shape.points) {
  38750. return;
  38751. }
  38752. updateSymbols(
  38753. polyline.shape.points, target.shape.points, symbolGroup, data, newIdx, false
  38754. );
  38755. updateProps(polyline, target, seriesModel);
  38756. updateProps(polygon, target, seriesModel);
  38757. data.setItemGraphicEl(newIdx, itemGroup);
  38758. })
  38759. .remove(function (idx) {
  38760. group.remove(oldData.getItemGraphicEl(idx));
  38761. })
  38762. .execute();
  38763. data.eachItemGraphicEl(function (itemGroup, idx) {
  38764. var itemModel = data.getItemModel(idx);
  38765. var polyline = itemGroup.childAt(0);
  38766. var polygon = itemGroup.childAt(1);
  38767. var symbolGroup = itemGroup.childAt(2);
  38768. var color = data.getItemVisual(idx, 'color');
  38769. group.add(itemGroup);
  38770. polyline.useStyle(
  38771. defaults(
  38772. itemModel.getModel('lineStyle').getLineStyle(),
  38773. {
  38774. fill: 'none',
  38775. stroke: color
  38776. }
  38777. )
  38778. );
  38779. polyline.hoverStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
  38780. var areaStyleModel = itemModel.getModel('areaStyle');
  38781. var hoverAreaStyleModel = itemModel.getModel('emphasis.areaStyle');
  38782. var polygonIgnore = areaStyleModel.isEmpty() && areaStyleModel.parentModel.isEmpty();
  38783. var hoverPolygonIgnore = hoverAreaStyleModel.isEmpty() && hoverAreaStyleModel.parentModel.isEmpty();
  38784. hoverPolygonIgnore = hoverPolygonIgnore && polygonIgnore;
  38785. polygon.ignore = polygonIgnore;
  38786. polygon.useStyle(
  38787. defaults(
  38788. areaStyleModel.getAreaStyle(),
  38789. {
  38790. fill: color,
  38791. opacity: 0.7
  38792. }
  38793. )
  38794. );
  38795. polygon.hoverStyle = hoverAreaStyleModel.getAreaStyle();
  38796. var itemStyle = itemModel.getModel('itemStyle').getItemStyle(['color']);
  38797. var itemHoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  38798. var labelModel = itemModel.getModel('label');
  38799. var labelHoverModel = itemModel.getModel('emphasis.label');
  38800. symbolGroup.eachChild(function (symbolPath) {
  38801. symbolPath.setStyle(itemStyle);
  38802. symbolPath.hoverStyle = clone(itemHoverStyle);
  38803. setLabelStyle(
  38804. symbolPath.style, symbolPath.hoverStyle, labelModel, labelHoverModel,
  38805. {
  38806. labelFetcher: data.hostModel,
  38807. labelDataIndex: idx,
  38808. labelDimIndex: symbolPath.__dimIdx,
  38809. defaultText: data.get(data.dimensions[symbolPath.__dimIdx], idx),
  38810. autoColor: color,
  38811. isRectText: true
  38812. }
  38813. );
  38814. });
  38815. function onEmphasis() {
  38816. polygon.attr('ignore', hoverPolygonIgnore);
  38817. }
  38818. function onNormal() {
  38819. polygon.attr('ignore', polygonIgnore);
  38820. }
  38821. itemGroup.off('mouseover').off('mouseout').off('normal').off('emphasis');
  38822. itemGroup.on('emphasis', onEmphasis)
  38823. .on('mouseover', onEmphasis)
  38824. .on('normal', onNormal)
  38825. .on('mouseout', onNormal);
  38826. setHoverStyle(itemGroup);
  38827. });
  38828. this._data = data;
  38829. },
  38830. remove: function () {
  38831. this.group.removeAll();
  38832. this._data = null;
  38833. },
  38834. dispose: function () {}
  38835. });
  38836. /*
  38837. * Licensed to the Apache Software Foundation (ASF) under one
  38838. * or more contributor license agreements. See the NOTICE file
  38839. * distributed with this work for additional information
  38840. * regarding copyright ownership. The ASF licenses this file
  38841. * to you under the Apache License, Version 2.0 (the
  38842. * "License"); you may not use this file except in compliance
  38843. * with the License. You may obtain a copy of the License at
  38844. *
  38845. * http://www.apache.org/licenses/LICENSE-2.0
  38846. *
  38847. * Unless required by applicable law or agreed to in writing,
  38848. * software distributed under the License is distributed on an
  38849. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38850. * KIND, either express or implied. See the License for the
  38851. * specific language governing permissions and limitations
  38852. * under the License.
  38853. */
  38854. var radarLayout = function (ecModel) {
  38855. ecModel.eachSeriesByType('radar', function (seriesModel) {
  38856. var data = seriesModel.getData();
  38857. var points = [];
  38858. var coordSys = seriesModel.coordinateSystem;
  38859. if (!coordSys) {
  38860. return;
  38861. }
  38862. function pointsConverter(val, idx) {
  38863. points[idx] = points[idx] || [];
  38864. points[idx][i] = coordSys.dataToPoint(val, i);
  38865. }
  38866. var axes = coordSys.getIndicatorAxes();
  38867. for (var i = 0; i < axes.length; i++) {
  38868. data.each(data.mapDimension(axes[i].dim), pointsConverter);
  38869. }
  38870. data.each(function (idx) {
  38871. // Close polygon
  38872. points[idx][0] && points[idx].push(points[idx][0].slice());
  38873. data.setItemLayout(idx, points[idx]);
  38874. });
  38875. });
  38876. };
  38877. /*
  38878. * Licensed to the Apache Software Foundation (ASF) under one
  38879. * or more contributor license agreements. See the NOTICE file
  38880. * distributed with this work for additional information
  38881. * regarding copyright ownership. The ASF licenses this file
  38882. * to you under the Apache License, Version 2.0 (the
  38883. * "License"); you may not use this file except in compliance
  38884. * with the License. You may obtain a copy of the License at
  38885. *
  38886. * http://www.apache.org/licenses/LICENSE-2.0
  38887. *
  38888. * Unless required by applicable law or agreed to in writing,
  38889. * software distributed under the License is distributed on an
  38890. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38891. * KIND, either express or implied. See the License for the
  38892. * specific language governing permissions and limitations
  38893. * under the License.
  38894. */
  38895. // Backward compat for radar chart in 2
  38896. var backwardCompat$1 = function (option) {
  38897. var polarOptArr = option.polar;
  38898. if (polarOptArr) {
  38899. if (!isArray(polarOptArr)) {
  38900. polarOptArr = [polarOptArr];
  38901. }
  38902. var polarNotRadar = [];
  38903. each$1(polarOptArr, function (polarOpt, idx) {
  38904. if (polarOpt.indicator) {
  38905. if (polarOpt.type && !polarOpt.shape) {
  38906. polarOpt.shape = polarOpt.type;
  38907. }
  38908. option.radar = option.radar || [];
  38909. if (!isArray(option.radar)) {
  38910. option.radar = [option.radar];
  38911. }
  38912. option.radar.push(polarOpt);
  38913. }
  38914. else {
  38915. polarNotRadar.push(polarOpt);
  38916. }
  38917. });
  38918. option.polar = polarNotRadar;
  38919. }
  38920. each$1(option.series, function (seriesOpt) {
  38921. if (seriesOpt && seriesOpt.type === 'radar' && seriesOpt.polarIndex) {
  38922. seriesOpt.radarIndex = seriesOpt.polarIndex;
  38923. }
  38924. });
  38925. };
  38926. /*
  38927. * Licensed to the Apache Software Foundation (ASF) under one
  38928. * or more contributor license agreements. See the NOTICE file
  38929. * distributed with this work for additional information
  38930. * regarding copyright ownership. The ASF licenses this file
  38931. * to you under the Apache License, Version 2.0 (the
  38932. * "License"); you may not use this file except in compliance
  38933. * with the License. You may obtain a copy of the License at
  38934. *
  38935. * http://www.apache.org/licenses/LICENSE-2.0
  38936. *
  38937. * Unless required by applicable law or agreed to in writing,
  38938. * software distributed under the License is distributed on an
  38939. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38940. * KIND, either express or implied. See the License for the
  38941. * specific language governing permissions and limitations
  38942. * under the License.
  38943. */
  38944. // Must use radar component
  38945. registerVisual(dataColor('radar'));
  38946. registerVisual(visualSymbol('radar', 'circle'));
  38947. registerLayout(radarLayout);
  38948. registerProcessor(dataFilter('radar'));
  38949. registerPreprocessor(backwardCompat$1);
  38950. /*
  38951. * Licensed to the Apache Software Foundation (ASF) under one
  38952. * or more contributor license agreements. See the NOTICE file
  38953. * distributed with this work for additional information
  38954. * regarding copyright ownership. The ASF licenses this file
  38955. * to you under the Apache License, Version 2.0 (the
  38956. * "License"); you may not use this file except in compliance
  38957. * with the License. You may obtain a copy of the License at
  38958. *
  38959. * http://www.apache.org/licenses/LICENSE-2.0
  38960. *
  38961. * Unless required by applicable law or agreed to in writing,
  38962. * software distributed under the License is distributed on an
  38963. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38964. * KIND, either express or implied. See the License for the
  38965. * specific language governing permissions and limitations
  38966. * under the License.
  38967. */
  38968. // Fix for 南海诸岛
  38969. var geoCoord = [126, 25];
  38970. var points$1 = [
  38971. [[0, 3.5], [7, 11.2], [15, 11.9], [30, 7], [42, 0.7], [52, 0.7],
  38972. [56, 7.7], [59, 0.7], [64, 0.7], [64, 0], [5, 0], [0, 3.5]],
  38973. [[13, 16.1], [19, 14.7], [16, 21.7], [11, 23.1], [13, 16.1]],
  38974. [[12, 32.2], [14, 38.5], [15, 38.5], [13, 32.2], [12, 32.2]],
  38975. [[16, 47.6], [12, 53.2], [13, 53.2], [18, 47.6], [16, 47.6]],
  38976. [[6, 64.4], [8, 70], [9, 70], [8, 64.4], [6, 64.4]],
  38977. [[23, 82.6], [29, 79.8], [30, 79.8], [25, 82.6], [23, 82.6]],
  38978. [[37, 70.7], [43, 62.3], [44, 62.3], [39, 70.7], [37, 70.7]],
  38979. [[48, 51.1], [51, 45.5], [53, 45.5], [50, 51.1], [48, 51.1]],
  38980. [[51, 35], [51, 28.7], [53, 28.7], [53, 35], [51, 35]],
  38981. [[52, 22.4], [55, 17.5], [56, 17.5], [53, 22.4], [52, 22.4]],
  38982. [[58, 12.6], [62, 7], [63, 7], [60, 12.6], [58, 12.6]],
  38983. [[0, 3.5], [0, 93.1], [64, 93.1], [64, 0], [63, 0], [63, 92.4],
  38984. [1, 92.4], [1, 3.5], [0, 3.5]]
  38985. ];
  38986. for (var i$1 = 0; i$1 < points$1.length; i$1++) {
  38987. for (var k = 0; k < points$1[i$1].length; k++) {
  38988. points$1[i$1][k][0] /= 10.5;
  38989. points$1[i$1][k][1] /= -10.5 / 0.75;
  38990. points$1[i$1][k][0] += geoCoord[0];
  38991. points$1[i$1][k][1] += geoCoord[1];
  38992. }
  38993. }
  38994. var fixNanhai = function (mapType, regions) {
  38995. if (mapType === 'china') {
  38996. regions.push(new Region(
  38997. '南海诸岛',
  38998. map(points$1, function (exterior) {
  38999. return {
  39000. type: 'polygon',
  39001. exterior: exterior
  39002. };
  39003. }), geoCoord
  39004. ));
  39005. }
  39006. };
  39007. /*
  39008. * Licensed to the Apache Software Foundation (ASF) under one
  39009. * or more contributor license agreements. See the NOTICE file
  39010. * distributed with this work for additional information
  39011. * regarding copyright ownership. The ASF licenses this file
  39012. * to you under the Apache License, Version 2.0 (the
  39013. * "License"); you may not use this file except in compliance
  39014. * with the License. You may obtain a copy of the License at
  39015. *
  39016. * http://www.apache.org/licenses/LICENSE-2.0
  39017. *
  39018. * Unless required by applicable law or agreed to in writing,
  39019. * software distributed under the License is distributed on an
  39020. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39021. * KIND, either express or implied. See the License for the
  39022. * specific language governing permissions and limitations
  39023. * under the License.
  39024. */
  39025. var coordsOffsetMap = {
  39026. '南海诸岛': [32, 80],
  39027. // 全国
  39028. '广东': [0, -10],
  39029. '香港': [10, 5],
  39030. '澳门': [-10, 10],
  39031. //'北京': [-10, 0],
  39032. '天津': [5, 5]
  39033. };
  39034. var fixTextCoord = function (mapType, region) {
  39035. if (mapType === 'china') {
  39036. var coordFix = coordsOffsetMap[region.name];
  39037. if (coordFix) {
  39038. var cp = region.center;
  39039. cp[0] += coordFix[0] / 10.5;
  39040. cp[1] += -coordFix[1] / (10.5 / 0.75);
  39041. }
  39042. }
  39043. };
  39044. /*
  39045. * Licensed to the Apache Software Foundation (ASF) under one
  39046. * or more contributor license agreements. See the NOTICE file
  39047. * distributed with this work for additional information
  39048. * regarding copyright ownership. The ASF licenses this file
  39049. * to you under the Apache License, Version 2.0 (the
  39050. * "License"); you may not use this file except in compliance
  39051. * with the License. You may obtain a copy of the License at
  39052. *
  39053. * http://www.apache.org/licenses/LICENSE-2.0
  39054. *
  39055. * Unless required by applicable law or agreed to in writing,
  39056. * software distributed under the License is distributed on an
  39057. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39058. * KIND, either express or implied. See the License for the
  39059. * specific language governing permissions and limitations
  39060. * under the License.
  39061. */
  39062. var geoCoordMap = {
  39063. 'Russia': [100, 60],
  39064. 'United States': [-99, 38],
  39065. 'United States of America': [-99, 38]
  39066. };
  39067. var fixGeoCoord = function (mapType, region) {
  39068. if (mapType === 'world') {
  39069. var geoCoord = geoCoordMap[region.name];
  39070. if (geoCoord) {
  39071. var cp = region.center;
  39072. cp[0] = geoCoord[0];
  39073. cp[1] = geoCoord[1];
  39074. }
  39075. }
  39076. };
  39077. /*
  39078. * Licensed to the Apache Software Foundation (ASF) under one
  39079. * or more contributor license agreements. See the NOTICE file
  39080. * distributed with this work for additional information
  39081. * regarding copyright ownership. The ASF licenses this file
  39082. * to you under the Apache License, Version 2.0 (the
  39083. * "License"); you may not use this file except in compliance
  39084. * with the License. You may obtain a copy of the License at
  39085. *
  39086. * http://www.apache.org/licenses/LICENSE-2.0
  39087. *
  39088. * Unless required by applicable law or agreed to in writing,
  39089. * software distributed under the License is distributed on an
  39090. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39091. * KIND, either express or implied. See the License for the
  39092. * specific language governing permissions and limitations
  39093. * under the License.
  39094. */
  39095. // Fix for 钓鱼岛
  39096. // var Region = require('../Region');
  39097. // var zrUtil = require('zrender/src/core/util');
  39098. // var geoCoord = [126, 25];
  39099. var points$2 = [
  39100. [
  39101. [123.45165252685547, 25.73527164402261],
  39102. [123.49731445312499, 25.73527164402261],
  39103. [123.49731445312499, 25.750734064600884],
  39104. [123.45165252685547, 25.750734064600884],
  39105. [123.45165252685547, 25.73527164402261]
  39106. ]
  39107. ];
  39108. var fixDiaoyuIsland = function (mapType, region) {
  39109. if (mapType === 'china' && region.name === '台湾') {
  39110. region.geometries.push({
  39111. type: 'polygon',
  39112. exterior: points$2[0]
  39113. });
  39114. }
  39115. };
  39116. /*
  39117. * Licensed to the Apache Software Foundation (ASF) under one
  39118. * or more contributor license agreements. See the NOTICE file
  39119. * distributed with this work for additional information
  39120. * regarding copyright ownership. The ASF licenses this file
  39121. * to you under the Apache License, Version 2.0 (the
  39122. * "License"); you may not use this file except in compliance
  39123. * with the License. You may obtain a copy of the License at
  39124. *
  39125. * http://www.apache.org/licenses/LICENSE-2.0
  39126. *
  39127. * Unless required by applicable law or agreed to in writing,
  39128. * software distributed under the License is distributed on an
  39129. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39130. * KIND, either express or implied. See the License for the
  39131. * specific language governing permissions and limitations
  39132. * under the License.
  39133. */
  39134. // Built-in GEO fixer.
  39135. var inner$7 = makeInner();
  39136. var geoJSONLoader = {
  39137. /**
  39138. * @param {string} mapName
  39139. * @param {Object} mapRecord {specialAreas, geoJSON}
  39140. * @return {Object} {regions, boundingRect}
  39141. */
  39142. load: function (mapName, mapRecord) {
  39143. var parsed = inner$7(mapRecord).parsed;
  39144. if (parsed) {
  39145. return parsed;
  39146. }
  39147. var specialAreas = mapRecord.specialAreas || {};
  39148. var geoJSON = mapRecord.geoJSON;
  39149. var regions;
  39150. // https://jsperf.com/try-catch-performance-overhead
  39151. try {
  39152. regions = geoJSON ? parseGeoJson$1(geoJSON) : [];
  39153. }
  39154. catch (e) {
  39155. throw new Error('Invalid geoJson format\n' + e.message);
  39156. }
  39157. each$1(regions, function (region) {
  39158. var regionName = region.name;
  39159. fixTextCoord(mapName, region);
  39160. fixGeoCoord(mapName, region);
  39161. fixDiaoyuIsland(mapName, region);
  39162. // Some area like Alaska in USA map needs to be tansformed
  39163. // to look better
  39164. var specialArea = specialAreas[regionName];
  39165. if (specialArea) {
  39166. region.transformTo(
  39167. specialArea.left, specialArea.top, specialArea.width, specialArea.height
  39168. );
  39169. }
  39170. });
  39171. fixNanhai(mapName, regions);
  39172. return (inner$7(mapRecord).parsed = {
  39173. regions: regions,
  39174. boundingRect: getBoundingRect$1(regions)
  39175. });
  39176. }
  39177. };
  39178. function getBoundingRect$1(regions) {
  39179. var rect;
  39180. for (var i = 0; i < regions.length; i++) {
  39181. var regionRect = regions[i].getBoundingRect();
  39182. rect = rect || regionRect.clone();
  39183. rect.union(regionRect);
  39184. }
  39185. return rect;
  39186. }
  39187. /*
  39188. * Licensed to the Apache Software Foundation (ASF) under one
  39189. * or more contributor license agreements. See the NOTICE file
  39190. * distributed with this work for additional information
  39191. * regarding copyright ownership. The ASF licenses this file
  39192. * to you under the Apache License, Version 2.0 (the
  39193. * "License"); you may not use this file except in compliance
  39194. * with the License. You may obtain a copy of the License at
  39195. *
  39196. * http://www.apache.org/licenses/LICENSE-2.0
  39197. *
  39198. * Unless required by applicable law or agreed to in writing,
  39199. * software distributed under the License is distributed on an
  39200. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39201. * KIND, either express or implied. See the License for the
  39202. * specific language governing permissions and limitations
  39203. * under the License.
  39204. */
  39205. var inner$8 = makeInner();
  39206. var geoSVGLoader = {
  39207. /**
  39208. * @param {string} mapName
  39209. * @param {Object} mapRecord {specialAreas, geoJSON}
  39210. * @return {Object} {root, boundingRect}
  39211. */
  39212. load: function (mapName, mapRecord) {
  39213. var originRoot = inner$8(mapRecord).originRoot;
  39214. if (originRoot) {
  39215. return {
  39216. root: originRoot,
  39217. boundingRect: inner$8(mapRecord).boundingRect
  39218. };
  39219. }
  39220. var graphic = buildGraphic(mapRecord);
  39221. inner$8(mapRecord).originRoot = graphic.root;
  39222. inner$8(mapRecord).boundingRect = graphic.boundingRect;
  39223. return graphic;
  39224. },
  39225. makeGraphic: function (mapName, mapRecord, hostKey) {
  39226. // For performance consideration (in large SVG), graphic only maked
  39227. // when necessary and reuse them according to hostKey.
  39228. var field = inner$8(mapRecord);
  39229. var rootMap = field.rootMap || (field.rootMap = createHashMap());
  39230. var root = rootMap.get(hostKey);
  39231. if (root) {
  39232. return root;
  39233. }
  39234. var originRoot = field.originRoot;
  39235. var boundingRect = field.boundingRect;
  39236. // For performance, if originRoot is not used by a view,
  39237. // assign it to a view, but not reproduce graphic elements.
  39238. if (!field.originRootHostKey) {
  39239. field.originRootHostKey = hostKey;
  39240. root = originRoot;
  39241. }
  39242. else {
  39243. root = buildGraphic(mapRecord, boundingRect).root;
  39244. }
  39245. return rootMap.set(hostKey, root);
  39246. },
  39247. removeGraphic: function (mapName, mapRecord, hostKey) {
  39248. var field = inner$8(mapRecord);
  39249. var rootMap = field.rootMap;
  39250. rootMap && rootMap.removeKey(hostKey);
  39251. if (hostKey === field.originRootHostKey) {
  39252. field.originRootHostKey = null;
  39253. }
  39254. }
  39255. };
  39256. function buildGraphic(mapRecord, boundingRect) {
  39257. var svgXML = mapRecord.svgXML;
  39258. var result;
  39259. var root;
  39260. try {
  39261. result = svgXML && parseSVG(svgXML, {
  39262. ignoreViewBox: true,
  39263. ignoreRootClip: true
  39264. }) || {};
  39265. root = result.root;
  39266. assert$1(root != null);
  39267. }
  39268. catch (e) {
  39269. throw new Error('Invalid svg format\n' + e.message);
  39270. }
  39271. var svgWidth = result.width;
  39272. var svgHeight = result.height;
  39273. var viewBoxRect = result.viewBoxRect;
  39274. if (!boundingRect) {
  39275. boundingRect = (svgWidth == null || svgHeight == null)
  39276. // If svg width / height not specified, calculate
  39277. // bounding rect as the width / height
  39278. ? root.getBoundingRect()
  39279. : new BoundingRect(0, 0, 0, 0);
  39280. if (svgWidth != null) {
  39281. boundingRect.width = svgWidth;
  39282. }
  39283. if (svgHeight != null) {
  39284. boundingRect.height = svgHeight;
  39285. }
  39286. }
  39287. if (viewBoxRect) {
  39288. var viewBoxTransform = makeViewBoxTransform(viewBoxRect, boundingRect.width, boundingRect.height);
  39289. var elRoot = root;
  39290. root = new Group();
  39291. root.add(elRoot);
  39292. elRoot.scale = viewBoxTransform.scale;
  39293. elRoot.position = viewBoxTransform.position;
  39294. }
  39295. root.setClipPath(new Rect({
  39296. shape: boundingRect.plain()
  39297. }));
  39298. return {
  39299. root: root,
  39300. boundingRect: boundingRect
  39301. };
  39302. }
  39303. /*
  39304. * Licensed to the Apache Software Foundation (ASF) under one
  39305. * or more contributor license agreements. See the NOTICE file
  39306. * distributed with this work for additional information
  39307. * regarding copyright ownership. The ASF licenses this file
  39308. * to you under the Apache License, Version 2.0 (the
  39309. * "License"); you may not use this file except in compliance
  39310. * with the License. You may obtain a copy of the License at
  39311. *
  39312. * http://www.apache.org/licenses/LICENSE-2.0
  39313. *
  39314. * Unless required by applicable law or agreed to in writing,
  39315. * software distributed under the License is distributed on an
  39316. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39317. * KIND, either express or implied. See the License for the
  39318. * specific language governing permissions and limitations
  39319. * under the License.
  39320. */
  39321. var loaders = {
  39322. geoJSON: geoJSONLoader,
  39323. svg: geoSVGLoader
  39324. };
  39325. var geoSourceManager = {
  39326. /**
  39327. * @param {string} mapName
  39328. * @param {Object} nameMap
  39329. * @return {Object} source {regions, regionsMap, nameCoordMap, boundingRect}
  39330. */
  39331. load: function (mapName, nameMap) {
  39332. var regions = [];
  39333. var regionsMap = createHashMap();
  39334. var nameCoordMap = createHashMap();
  39335. var boundingRect;
  39336. var mapRecords = retrieveMap(mapName);
  39337. each$1(mapRecords, function (record) {
  39338. var singleSource = loaders[record.type].load(mapName, record);
  39339. each$1(singleSource.regions, function (region) {
  39340. var regionName = region.name;
  39341. // Try use the alias in geoNameMap
  39342. if (nameMap && nameMap.hasOwnProperty(regionName)) {
  39343. region = region.cloneShallow(regionName = nameMap[regionName]);
  39344. }
  39345. regions.push(region);
  39346. regionsMap.set(regionName, region);
  39347. nameCoordMap.set(regionName, region.center);
  39348. });
  39349. var rect = singleSource.boundingRect;
  39350. if (rect) {
  39351. boundingRect
  39352. ? boundingRect.union(rect)
  39353. : (boundingRect = rect.clone());
  39354. }
  39355. });
  39356. return {
  39357. regions: regions,
  39358. regionsMap: regionsMap,
  39359. nameCoordMap: nameCoordMap,
  39360. // FIXME Always return new ?
  39361. boundingRect: boundingRect || new BoundingRect(0, 0, 0, 0)
  39362. };
  39363. },
  39364. /**
  39365. * @param {string} mapName
  39366. * @param {string} hostKey For cache.
  39367. * @return {Array.<module:zrender/Element>} Roots.
  39368. */
  39369. makeGraphic: makeInvoker('makeGraphic'),
  39370. /**
  39371. * @param {string} mapName
  39372. * @param {string} hostKey For cache.
  39373. */
  39374. removeGraphic: makeInvoker('removeGraphic')
  39375. };
  39376. function makeInvoker(methodName) {
  39377. return function (mapName, hostKey) {
  39378. var mapRecords = retrieveMap(mapName);
  39379. var results = [];
  39380. each$1(mapRecords, function (record) {
  39381. var method = loaders[record.type][methodName];
  39382. method && results.push(method(mapName, record, hostKey));
  39383. });
  39384. return results;
  39385. };
  39386. }
  39387. function mapNotExistsError(mapName) {
  39388. if (__DEV__) {
  39389. console.error(
  39390. 'Map ' + mapName + ' not exists. You can download map file on http://echarts.baidu.com/download-map.html'
  39391. );
  39392. }
  39393. }
  39394. function retrieveMap(mapName) {
  39395. var mapRecords = mapDataStorage.retrieveMap(mapName) || [];
  39396. if (__DEV__) {
  39397. if (!mapRecords.length) {
  39398. mapNotExistsError(mapName);
  39399. }
  39400. }
  39401. return mapRecords;
  39402. }
  39403. /*
  39404. * Licensed to the Apache Software Foundation (ASF) under one
  39405. * or more contributor license agreements. See the NOTICE file
  39406. * distributed with this work for additional information
  39407. * regarding copyright ownership. The ASF licenses this file
  39408. * to you under the Apache License, Version 2.0 (the
  39409. * "License"); you may not use this file except in compliance
  39410. * with the License. You may obtain a copy of the License at
  39411. *
  39412. * http://www.apache.org/licenses/LICENSE-2.0
  39413. *
  39414. * Unless required by applicable law or agreed to in writing,
  39415. * software distributed under the License is distributed on an
  39416. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39417. * KIND, either express or implied. See the License for the
  39418. * specific language governing permissions and limitations
  39419. * under the License.
  39420. */
  39421. var MapSeries = SeriesModel.extend({
  39422. type: 'series.map',
  39423. dependencies: ['geo'],
  39424. layoutMode: 'box',
  39425. /**
  39426. * Only first map series of same mapType will drawMap
  39427. * @type {boolean}
  39428. */
  39429. needsDrawMap: false,
  39430. /**
  39431. * Group of all map series with same mapType
  39432. * @type {boolean}
  39433. */
  39434. seriesGroup: [],
  39435. getInitialData: function (option) {
  39436. var data = createListSimply(this, ['value']);
  39437. var valueDim = data.mapDimension('value');
  39438. var dataNameMap = createHashMap();
  39439. var selectTargetList = [];
  39440. var toAppendNames = [];
  39441. for (var i = 0, len = data.count(); i < len; i++) {
  39442. var name = data.getName(i);
  39443. dataNameMap.set(name, true);
  39444. selectTargetList.push({
  39445. name: name,
  39446. value: data.get(valueDim, i),
  39447. selected: retrieveRawAttr(data, i, 'selected')
  39448. });
  39449. }
  39450. var geoSource = geoSourceManager.load(this.getMapType(), this.option.nameMap);
  39451. each$1(geoSource.regions, function (region) {
  39452. var name = region.name;
  39453. if (!dataNameMap.get(name)) {
  39454. selectTargetList.push({name: name});
  39455. toAppendNames.push(name);
  39456. }
  39457. });
  39458. this.updateSelectedMap(selectTargetList);
  39459. // Complete data with missing regions. The consequent processes (like visual
  39460. // map and render) can not be performed without a "full data". For example,
  39461. // find `dataIndex` by name.
  39462. data.appendValues([], toAppendNames);
  39463. return data;
  39464. },
  39465. /**
  39466. * If no host geo model, return null, which means using a
  39467. * inner exclusive geo model.
  39468. */
  39469. getHostGeoModel: function () {
  39470. var geoIndex = this.option.geoIndex;
  39471. return geoIndex != null
  39472. ? this.dependentModels.geo[geoIndex]
  39473. : null;
  39474. },
  39475. getMapType: function () {
  39476. return (this.getHostGeoModel() || this).option.map;
  39477. },
  39478. // _fillOption: function (option, mapName) {
  39479. // Shallow clone
  39480. // option = zrUtil.extend({}, option);
  39481. // option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap);
  39482. // return option;
  39483. // },
  39484. getRawValue: function (dataIndex) {
  39485. // Use value stored in data instead because it is calculated from multiple series
  39486. // FIXME Provide all value of multiple series ?
  39487. var data = this.getData();
  39488. return data.get(data.mapDimension('value'), dataIndex);
  39489. },
  39490. /**
  39491. * Get model of region
  39492. * @param {string} name
  39493. * @return {module:echarts/model/Model}
  39494. */
  39495. getRegionModel: function (regionName) {
  39496. var data = this.getData();
  39497. return data.getItemModel(data.indexOfName(regionName));
  39498. },
  39499. /**
  39500. * Map tooltip formatter
  39501. *
  39502. * @param {number} dataIndex
  39503. */
  39504. formatTooltip: function (dataIndex) {
  39505. // FIXME orignalData and data is a bit confusing
  39506. var data = this.getData();
  39507. var formattedValue = addCommas(this.getRawValue(dataIndex));
  39508. var name = data.getName(dataIndex);
  39509. var seriesGroup = this.seriesGroup;
  39510. var seriesNames = [];
  39511. for (var i = 0; i < seriesGroup.length; i++) {
  39512. var otherIndex = seriesGroup[i].originalData.indexOfName(name);
  39513. var valueDim = data.mapDimension('value');
  39514. if (!isNaN(seriesGroup[i].originalData.get(valueDim, otherIndex))) {
  39515. seriesNames.push(
  39516. encodeHTML(seriesGroup[i].name)
  39517. );
  39518. }
  39519. }
  39520. return seriesNames.join(', ') + '<br />'
  39521. + encodeHTML(name + ' : ' + formattedValue);
  39522. },
  39523. /**
  39524. * @implement
  39525. */
  39526. getTooltipPosition: function (dataIndex) {
  39527. if (dataIndex != null) {
  39528. var name = this.getData().getName(dataIndex);
  39529. var geo = this.coordinateSystem;
  39530. var region = geo.getRegion(name);
  39531. return region && geo.dataToPoint(region.center);
  39532. }
  39533. },
  39534. setZoom: function (zoom) {
  39535. this.option.zoom = zoom;
  39536. },
  39537. setCenter: function (center) {
  39538. this.option.center = center;
  39539. },
  39540. defaultOption: {
  39541. // 一级层叠
  39542. zlevel: 0,
  39543. // 二级层叠
  39544. z: 2,
  39545. coordinateSystem: 'geo',
  39546. // map should be explicitly specified since ec3.
  39547. map: '',
  39548. // If `geoIndex` is not specified, a exclusive geo will be
  39549. // created. Otherwise use the specified geo component, and
  39550. // `map` and `mapType` are ignored.
  39551. // geoIndex: 0,
  39552. // 'center' | 'left' | 'right' | 'x%' | {number}
  39553. left: 'center',
  39554. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  39555. top: 'center',
  39556. // right
  39557. // bottom
  39558. // width:
  39559. // height
  39560. // Aspect is width / height. Inited to be geoJson bbox aspect
  39561. // This parameter is used for scale this aspect
  39562. aspectScale: 0.75,
  39563. ///// Layout with center and size
  39564. // If you wan't to put map in a fixed size box with right aspect ratio
  39565. // This two properties may more conveninet
  39566. // layoutCenter: [50%, 50%]
  39567. // layoutSize: 100
  39568. // 数值合并方式,默认加和,可选为:
  39569. // 'sum' | 'average' | 'max' | 'min'
  39570. // mapValueCalculation: 'sum',
  39571. // 地图数值计算结果小数精度
  39572. // mapValuePrecision: 0,
  39573. // 显示图例颜色标识(系列标识的小圆点),图例开启时有效
  39574. showLegendSymbol: true,
  39575. // 选择模式,默认关闭,可选single,multiple
  39576. // selectedMode: false,
  39577. dataRangeHoverLink: true,
  39578. // 是否开启缩放及漫游模式
  39579. // roam: false,
  39580. // Define left-top, right-bottom coords to control view
  39581. // For example, [ [180, 90], [-180, -90] ],
  39582. // higher priority than center and zoom
  39583. boundingCoords: null,
  39584. // Default on center of map
  39585. center: null,
  39586. zoom: 1,
  39587. scaleLimit: null,
  39588. label: {
  39589. show: false,
  39590. color: '#000'
  39591. },
  39592. // scaleLimit: null,
  39593. itemStyle: {
  39594. borderWidth: 0.5,
  39595. borderColor: '#444',
  39596. areaColor: '#eee'
  39597. },
  39598. emphasis: {
  39599. label: {
  39600. show: true,
  39601. color: 'rgb(100,0,0)'
  39602. },
  39603. itemStyle: {
  39604. areaColor: 'rgba(255,215,0,0.8)'
  39605. }
  39606. }
  39607. }
  39608. });
  39609. mixin(MapSeries, selectableMixin);
  39610. /*
  39611. * Licensed to the Apache Software Foundation (ASF) under one
  39612. * or more contributor license agreements. See the NOTICE file
  39613. * distributed with this work for additional information
  39614. * regarding copyright ownership. The ASF licenses this file
  39615. * to you under the Apache License, Version 2.0 (the
  39616. * "License"); you may not use this file except in compliance
  39617. * with the License. You may obtain a copy of the License at
  39618. *
  39619. * http://www.apache.org/licenses/LICENSE-2.0
  39620. *
  39621. * Unless required by applicable law or agreed to in writing,
  39622. * software distributed under the License is distributed on an
  39623. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39624. * KIND, either express or implied. See the License for the
  39625. * specific language governing permissions and limitations
  39626. * under the License.
  39627. */
  39628. var ATTR = '\0_ec_interaction_mutex';
  39629. function take(zr, resourceKey, userKey) {
  39630. var store = getStore(zr);
  39631. store[resourceKey] = userKey;
  39632. }
  39633. function release(zr, resourceKey, userKey) {
  39634. var store = getStore(zr);
  39635. var uKey = store[resourceKey];
  39636. if (uKey === userKey) {
  39637. store[resourceKey] = null;
  39638. }
  39639. }
  39640. function isTaken(zr, resourceKey) {
  39641. return !!getStore(zr)[resourceKey];
  39642. }
  39643. function getStore(zr) {
  39644. return zr[ATTR] || (zr[ATTR] = {});
  39645. }
  39646. /**
  39647. * payload: {
  39648. * type: 'takeGlobalCursor',
  39649. * key: 'dataZoomSelect', or 'brush', or ...,
  39650. * If no userKey, release global cursor.
  39651. * }
  39652. */
  39653. registerAction(
  39654. {type: 'takeGlobalCursor', event: 'globalCursorTaken', update: 'update'},
  39655. function () {}
  39656. );
  39657. /*
  39658. * Licensed to the Apache Software Foundation (ASF) under one
  39659. * or more contributor license agreements. See the NOTICE file
  39660. * distributed with this work for additional information
  39661. * regarding copyright ownership. The ASF licenses this file
  39662. * to you under the Apache License, Version 2.0 (the
  39663. * "License"); you may not use this file except in compliance
  39664. * with the License. You may obtain a copy of the License at
  39665. *
  39666. * http://www.apache.org/licenses/LICENSE-2.0
  39667. *
  39668. * Unless required by applicable law or agreed to in writing,
  39669. * software distributed under the License is distributed on an
  39670. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39671. * KIND, either express or implied. See the License for the
  39672. * specific language governing permissions and limitations
  39673. * under the License.
  39674. */
  39675. /**
  39676. * @alias module:echarts/component/helper/RoamController
  39677. * @constructor
  39678. * @mixin {module:zrender/mixin/Eventful}
  39679. *
  39680. * @param {module:zrender/zrender~ZRender} zr
  39681. */
  39682. function RoamController(zr) {
  39683. /**
  39684. * @type {Function}
  39685. */
  39686. this.pointerChecker;
  39687. /**
  39688. * @type {module:zrender}
  39689. */
  39690. this._zr = zr;
  39691. /**
  39692. * @type {Object}
  39693. */
  39694. this._opt = {};
  39695. // Avoid two roamController bind the same handler
  39696. var bind$$1 = bind;
  39697. var mousedownHandler = bind$$1(mousedown, this);
  39698. var mousemoveHandler = bind$$1(mousemove, this);
  39699. var mouseupHandler = bind$$1(mouseup, this);
  39700. var mousewheelHandler = bind$$1(mousewheel, this);
  39701. var pinchHandler = bind$$1(pinch, this);
  39702. Eventful.call(this);
  39703. /**
  39704. * @param {Function} pointerChecker
  39705. * input: x, y
  39706. * output: boolean
  39707. */
  39708. this.setPointerChecker = function (pointerChecker) {
  39709. this.pointerChecker = pointerChecker;
  39710. };
  39711. /**
  39712. * Notice: only enable needed types. For example, if 'zoom'
  39713. * is not needed, 'zoom' should not be enabled, otherwise
  39714. * default mousewheel behaviour (scroll page) will be disabled.
  39715. *
  39716. * @param {boolean|string} [controlType=true] Specify the control type,
  39717. * which can be null/undefined or true/false
  39718. * or 'pan/move' or 'zoom'/'scale'
  39719. * @param {Object} [opt]
  39720. * @param {Object} [opt.zoomOnMouseWheel=true] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  39721. * @param {Object} [opt.moveOnMouseMove=true] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  39722. * @param {Object} [opt.moveOnMouseWheel=false] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  39723. * @param {Object} [opt.preventDefaultMouseMove=true] When pan.
  39724. */
  39725. this.enable = function (controlType, opt) {
  39726. // Disable previous first
  39727. this.disable();
  39728. this._opt = defaults(clone(opt) || {}, {
  39729. zoomOnMouseWheel: true,
  39730. moveOnMouseMove: true,
  39731. // By default, wheel do not trigger move.
  39732. moveOnMouseWheel: false,
  39733. preventDefaultMouseMove: true
  39734. });
  39735. if (controlType == null) {
  39736. controlType = true;
  39737. }
  39738. if (controlType === true || (controlType === 'move' || controlType === 'pan')) {
  39739. zr.on('mousedown', mousedownHandler);
  39740. zr.on('mousemove', mousemoveHandler);
  39741. zr.on('mouseup', mouseupHandler);
  39742. }
  39743. if (controlType === true || (controlType === 'scale' || controlType === 'zoom')) {
  39744. zr.on('mousewheel', mousewheelHandler);
  39745. zr.on('pinch', pinchHandler);
  39746. }
  39747. };
  39748. this.disable = function () {
  39749. zr.off('mousedown', mousedownHandler);
  39750. zr.off('mousemove', mousemoveHandler);
  39751. zr.off('mouseup', mouseupHandler);
  39752. zr.off('mousewheel', mousewheelHandler);
  39753. zr.off('pinch', pinchHandler);
  39754. };
  39755. this.dispose = this.disable;
  39756. this.isDragging = function () {
  39757. return this._dragging;
  39758. };
  39759. this.isPinching = function () {
  39760. return this._pinching;
  39761. };
  39762. }
  39763. mixin(RoamController, Eventful);
  39764. function mousedown(e) {
  39765. if (isMiddleOrRightButtonOnMouseUpDown(e)
  39766. || (e.target && e.target.draggable)
  39767. ) {
  39768. return;
  39769. }
  39770. var x = e.offsetX;
  39771. var y = e.offsetY;
  39772. // Only check on mosedown, but not mousemove.
  39773. // Mouse can be out of target when mouse moving.
  39774. if (this.pointerChecker && this.pointerChecker(e, x, y)) {
  39775. this._x = x;
  39776. this._y = y;
  39777. this._dragging = true;
  39778. }
  39779. }
  39780. function mousemove(e) {
  39781. if (!this._dragging
  39782. || !isAvailableBehavior('moveOnMouseMove', e, this._opt)
  39783. || e.gestureEvent === 'pinch'
  39784. || isTaken(this._zr, 'globalPan')
  39785. ) {
  39786. return;
  39787. }
  39788. var x = e.offsetX;
  39789. var y = e.offsetY;
  39790. var oldX = this._x;
  39791. var oldY = this._y;
  39792. var dx = x - oldX;
  39793. var dy = y - oldY;
  39794. this._x = x;
  39795. this._y = y;
  39796. this._opt.preventDefaultMouseMove && stop(e.event);
  39797. trigger(this, 'pan', 'moveOnMouseMove', e, {
  39798. dx: dx, dy: dy, oldX: oldX, oldY: oldY, newX: x, newY: y
  39799. });
  39800. }
  39801. function mouseup(e) {
  39802. if (!isMiddleOrRightButtonOnMouseUpDown(e)) {
  39803. this._dragging = false;
  39804. }
  39805. }
  39806. function mousewheel(e) {
  39807. var shouldZoom = isAvailableBehavior('zoomOnMouseWheel', e, this._opt);
  39808. var shouldMove = isAvailableBehavior('moveOnMouseWheel', e, this._opt);
  39809. var wheelDelta = e.wheelDelta;
  39810. var absWheelDeltaDelta = Math.abs(wheelDelta);
  39811. var originX = e.offsetX;
  39812. var originY = e.offsetY;
  39813. // wheelDelta maybe -0 in chrome mac.
  39814. if (wheelDelta === 0 || (!shouldZoom && !shouldMove)) {
  39815. return;
  39816. }
  39817. // If both `shouldZoom` and `shouldMove` is true, trigger
  39818. // their event both, and the final behavior is determined
  39819. // by event listener themselves.
  39820. if (shouldZoom) {
  39821. // Convenience:
  39822. // Mac and VM Windows on Mac: scroll up: zoom out.
  39823. // Windows: scroll up: zoom in.
  39824. // FIXME: Should do more test in different environment.
  39825. // wheelDelta is too complicated in difference nvironment
  39826. // (https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel),
  39827. // although it has been normallized by zrender.
  39828. // wheelDelta of mouse wheel is bigger than touch pad.
  39829. var factor = absWheelDeltaDelta > 3 ? 1.4 : absWheelDeltaDelta > 1 ? 1.2 : 1.1;
  39830. var scale = wheelDelta > 0 ? factor : 1 / factor;
  39831. checkPointerAndTrigger(this, 'zoom', 'zoomOnMouseWheel', e, {
  39832. scale: scale, originX: originX, originY: originY
  39833. });
  39834. }
  39835. if (shouldMove) {
  39836. // FIXME: Should do more test in different environment.
  39837. var absDelta = Math.abs(wheelDelta);
  39838. // wheelDelta of mouse wheel is bigger than touch pad.
  39839. var scrollDelta = (wheelDelta > 0 ? 1 : -1) * (absDelta > 3 ? 0.4 : absDelta > 1 ? 0.15 : 0.05);
  39840. checkPointerAndTrigger(this, 'scrollMove', 'moveOnMouseWheel', e, {
  39841. scrollDelta: scrollDelta, originX: originX, originY: originY
  39842. });
  39843. }
  39844. }
  39845. function pinch(e) {
  39846. if (isTaken(this._zr, 'globalPan')) {
  39847. return;
  39848. }
  39849. var scale = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  39850. checkPointerAndTrigger(this, 'zoom', null, e, {
  39851. scale: scale, originX: e.pinchX, originY: e.pinchY
  39852. });
  39853. }
  39854. function checkPointerAndTrigger(controller, eventName, behaviorToCheck, e, contollerEvent) {
  39855. if (controller.pointerChecker
  39856. && controller.pointerChecker(e, contollerEvent.originX, contollerEvent.originY)
  39857. ) {
  39858. // When mouse is out of roamController rect,
  39859. // default befavoius should not be be disabled, otherwise
  39860. // page sliding is disabled, contrary to expectation.
  39861. stop(e.event);
  39862. trigger(controller, eventName, behaviorToCheck, e, contollerEvent);
  39863. }
  39864. }
  39865. function trigger(controller, eventName, behaviorToCheck, e, contollerEvent) {
  39866. // Also provide behavior checker for event listener, for some case that
  39867. // multiple components share one listener.
  39868. contollerEvent.isAvailableBehavior = bind(isAvailableBehavior, null, behaviorToCheck, e);
  39869. controller.trigger(eventName, contollerEvent);
  39870. }
  39871. // settings: {
  39872. // zoomOnMouseWheel
  39873. // moveOnMouseMove
  39874. // moveOnMouseWheel
  39875. // }
  39876. // The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  39877. function isAvailableBehavior(behaviorToCheck, e, settings) {
  39878. var setting = settings[behaviorToCheck];
  39879. return !behaviorToCheck || (
  39880. setting && (!isString(setting) || e.event[setting + 'Key'])
  39881. );
  39882. }
  39883. /*
  39884. * Licensed to the Apache Software Foundation (ASF) under one
  39885. * or more contributor license agreements. See the NOTICE file
  39886. * distributed with this work for additional information
  39887. * regarding copyright ownership. The ASF licenses this file
  39888. * to you under the Apache License, Version 2.0 (the
  39889. * "License"); you may not use this file except in compliance
  39890. * with the License. You may obtain a copy of the License at
  39891. *
  39892. * http://www.apache.org/licenses/LICENSE-2.0
  39893. *
  39894. * Unless required by applicable law or agreed to in writing,
  39895. * software distributed under the License is distributed on an
  39896. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39897. * KIND, either express or implied. See the License for the
  39898. * specific language governing permissions and limitations
  39899. * under the License.
  39900. */
  39901. /**
  39902. * For geo and graph.
  39903. *
  39904. * @param {Object} controllerHost
  39905. * @param {module:zrender/Element} controllerHost.target
  39906. */
  39907. function updateViewOnPan(controllerHost, dx, dy) {
  39908. var target = controllerHost.target;
  39909. var pos = target.position;
  39910. pos[0] += dx;
  39911. pos[1] += dy;
  39912. target.dirty();
  39913. }
  39914. /**
  39915. * For geo and graph.
  39916. *
  39917. * @param {Object} controllerHost
  39918. * @param {module:zrender/Element} controllerHost.target
  39919. * @param {number} controllerHost.zoom
  39920. * @param {number} controllerHost.zoomLimit like: {min: 1, max: 2}
  39921. */
  39922. function updateViewOnZoom(controllerHost, zoomDelta, zoomX, zoomY) {
  39923. var target = controllerHost.target;
  39924. var zoomLimit = controllerHost.zoomLimit;
  39925. var pos = target.position;
  39926. var scale = target.scale;
  39927. var newZoom = controllerHost.zoom = controllerHost.zoom || 1;
  39928. newZoom *= zoomDelta;
  39929. if (zoomLimit) {
  39930. var zoomMin = zoomLimit.min || 0;
  39931. var zoomMax = zoomLimit.max || Infinity;
  39932. newZoom = Math.max(
  39933. Math.min(zoomMax, newZoom),
  39934. zoomMin
  39935. );
  39936. }
  39937. var zoomScale = newZoom / controllerHost.zoom;
  39938. controllerHost.zoom = newZoom;
  39939. // Keep the mouse center when scaling
  39940. pos[0] -= (zoomX - pos[0]) * (zoomScale - 1);
  39941. pos[1] -= (zoomY - pos[1]) * (zoomScale - 1);
  39942. scale[0] *= zoomScale;
  39943. scale[1] *= zoomScale;
  39944. target.dirty();
  39945. }
  39946. /*
  39947. * Licensed to the Apache Software Foundation (ASF) under one
  39948. * or more contributor license agreements. See the NOTICE file
  39949. * distributed with this work for additional information
  39950. * regarding copyright ownership. The ASF licenses this file
  39951. * to you under the Apache License, Version 2.0 (the
  39952. * "License"); you may not use this file except in compliance
  39953. * with the License. You may obtain a copy of the License at
  39954. *
  39955. * http://www.apache.org/licenses/LICENSE-2.0
  39956. *
  39957. * Unless required by applicable law or agreed to in writing,
  39958. * software distributed under the License is distributed on an
  39959. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39960. * KIND, either express or implied. See the License for the
  39961. * specific language governing permissions and limitations
  39962. * under the License.
  39963. */
  39964. var IRRELEVANT_EXCLUDES = {'axisPointer': 1, 'tooltip': 1, 'brush': 1};
  39965. /**
  39966. * Avoid that: mouse click on a elements that is over geo or graph,
  39967. * but roam is triggered.
  39968. */
  39969. function onIrrelevantElement(e, api, targetCoordSysModel) {
  39970. var model = api.getComponentByElement(e.topTarget);
  39971. // If model is axisModel, it works only if it is injected with coordinateSystem.
  39972. var coordSys = model && model.coordinateSystem;
  39973. return model
  39974. && model !== targetCoordSysModel
  39975. && !IRRELEVANT_EXCLUDES[model.mainType]
  39976. && (coordSys && coordSys.model !== targetCoordSysModel);
  39977. }
  39978. /*
  39979. * Licensed to the Apache Software Foundation (ASF) under one
  39980. * or more contributor license agreements. See the NOTICE file
  39981. * distributed with this work for additional information
  39982. * regarding copyright ownership. The ASF licenses this file
  39983. * to you under the Apache License, Version 2.0 (the
  39984. * "License"); you may not use this file except in compliance
  39985. * with the License. You may obtain a copy of the License at
  39986. *
  39987. * http://www.apache.org/licenses/LICENSE-2.0
  39988. *
  39989. * Unless required by applicable law or agreed to in writing,
  39990. * software distributed under the License is distributed on an
  39991. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39992. * KIND, either express or implied. See the License for the
  39993. * specific language governing permissions and limitations
  39994. * under the License.
  39995. */
  39996. function getFixedItemStyle(model, scale) {
  39997. var itemStyle = model.getItemStyle();
  39998. var areaColor = model.get('areaColor');
  39999. // If user want the color not to be changed when hover,
  40000. // they should both set areaColor and color to be null.
  40001. if (areaColor != null) {
  40002. itemStyle.fill = areaColor;
  40003. }
  40004. return itemStyle;
  40005. }
  40006. function updateMapSelectHandler(mapDraw, mapOrGeoModel, regionsGroup, api, fromView) {
  40007. regionsGroup.off('click');
  40008. regionsGroup.off('mousedown');
  40009. if (mapOrGeoModel.get('selectedMode')) {
  40010. regionsGroup.on('mousedown', function () {
  40011. mapDraw._mouseDownFlag = true;
  40012. });
  40013. regionsGroup.on('click', function (e) {
  40014. if (!mapDraw._mouseDownFlag) {
  40015. return;
  40016. }
  40017. mapDraw._mouseDownFlag = false;
  40018. var el = e.target;
  40019. while (!el.__regions) {
  40020. el = el.parent;
  40021. }
  40022. if (!el) {
  40023. return;
  40024. }
  40025. var action = {
  40026. type: (mapOrGeoModel.mainType === 'geo' ? 'geo' : 'map') + 'ToggleSelect',
  40027. batch: map(el.__regions, function (region) {
  40028. return {
  40029. name: region.name,
  40030. from: fromView.uid
  40031. };
  40032. })
  40033. };
  40034. action[mapOrGeoModel.mainType + 'Id'] = mapOrGeoModel.id;
  40035. api.dispatchAction(action);
  40036. updateMapSelected(mapOrGeoModel, regionsGroup);
  40037. });
  40038. }
  40039. }
  40040. function updateMapSelected(mapOrGeoModel, regionsGroup) {
  40041. // FIXME
  40042. regionsGroup.eachChild(function (otherRegionEl) {
  40043. each$1(otherRegionEl.__regions, function (region) {
  40044. otherRegionEl.trigger(mapOrGeoModel.isSelected(region.name) ? 'emphasis' : 'normal');
  40045. });
  40046. });
  40047. }
  40048. /**
  40049. * @alias module:echarts/component/helper/MapDraw
  40050. * @param {module:echarts/ExtensionAPI} api
  40051. * @param {boolean} updateGroup
  40052. */
  40053. function MapDraw(api, updateGroup) {
  40054. var group = new Group();
  40055. /**
  40056. * @type {string}
  40057. * @private
  40058. */
  40059. this.uid = getUID('ec_map_draw');
  40060. /**
  40061. * @type {module:echarts/component/helper/RoamController}
  40062. * @private
  40063. */
  40064. this._controller = new RoamController(api.getZr());
  40065. /**
  40066. * @type {Object} {target, zoom, zoomLimit}
  40067. * @private
  40068. */
  40069. this._controllerHost = {target: updateGroup ? group : null};
  40070. /**
  40071. * @type {module:zrender/container/Group}
  40072. * @readOnly
  40073. */
  40074. this.group = group;
  40075. /**
  40076. * @type {boolean}
  40077. * @private
  40078. */
  40079. this._updateGroup = updateGroup;
  40080. /**
  40081. * This flag is used to make sure that only one among
  40082. * `pan`, `zoom`, `click` can occurs, otherwise 'selected'
  40083. * action may be triggered when `pan`, which is unexpected.
  40084. * @type {booelan}
  40085. */
  40086. this._mouseDownFlag;
  40087. /**
  40088. * @type {string}
  40089. */
  40090. this._mapName;
  40091. /**
  40092. * @type {boolean}
  40093. */
  40094. this._initialized;
  40095. /**
  40096. * @type {module:zrender/container/Group}
  40097. */
  40098. group.add(this._regionsGroup = new Group());
  40099. /**
  40100. * @type {module:zrender/container/Group}
  40101. */
  40102. group.add(this._backgroundGroup = new Group());
  40103. }
  40104. MapDraw.prototype = {
  40105. constructor: MapDraw,
  40106. draw: function (mapOrGeoModel, ecModel, api, fromView, payload) {
  40107. var isGeo = mapOrGeoModel.mainType === 'geo';
  40108. // Map series has data. GEO model that controlled by map series
  40109. // will be assigned with map data. Other GEO model has no data.
  40110. var data = mapOrGeoModel.getData && mapOrGeoModel.getData();
  40111. isGeo && ecModel.eachComponent({mainType: 'series', subType: 'map'}, function (mapSeries) {
  40112. if (!data && mapSeries.getHostGeoModel() === mapOrGeoModel) {
  40113. data = mapSeries.getData();
  40114. }
  40115. });
  40116. var geo = mapOrGeoModel.coordinateSystem;
  40117. this._updateBackground(geo);
  40118. var regionsGroup = this._regionsGroup;
  40119. var group = this.group;
  40120. var scale = geo.scale;
  40121. var transform = {
  40122. position: geo.position,
  40123. scale: scale
  40124. };
  40125. // No animation when first draw or in action
  40126. if (!regionsGroup.childAt(0) || payload) {
  40127. group.attr(transform);
  40128. }
  40129. else {
  40130. updateProps(group, transform, mapOrGeoModel);
  40131. }
  40132. regionsGroup.removeAll();
  40133. var itemStyleAccessPath = ['itemStyle'];
  40134. var hoverItemStyleAccessPath = ['emphasis', 'itemStyle'];
  40135. var labelAccessPath = ['label'];
  40136. var hoverLabelAccessPath = ['emphasis', 'label'];
  40137. var nameMap = createHashMap();
  40138. each$1(geo.regions, function (region) {
  40139. // Consider in GeoJson properties.name may be duplicated, for example,
  40140. // there is multiple region named "United Kindom" or "France" (so many
  40141. // colonies). And it is not appropriate to merge them in geo, which
  40142. // will make them share the same label and bring trouble in label
  40143. // location calculation.
  40144. var regionGroup = nameMap.get(region.name)
  40145. || nameMap.set(region.name, new Group());
  40146. var compoundPath = new CompoundPath({
  40147. shape: {
  40148. paths: []
  40149. }
  40150. });
  40151. regionGroup.add(compoundPath);
  40152. var regionModel = mapOrGeoModel.getRegionModel(region.name) || mapOrGeoModel;
  40153. var itemStyleModel = regionModel.getModel(itemStyleAccessPath);
  40154. var hoverItemStyleModel = regionModel.getModel(hoverItemStyleAccessPath);
  40155. var itemStyle = getFixedItemStyle(itemStyleModel, scale);
  40156. var hoverItemStyle = getFixedItemStyle(hoverItemStyleModel, scale);
  40157. var labelModel = regionModel.getModel(labelAccessPath);
  40158. var hoverLabelModel = regionModel.getModel(hoverLabelAccessPath);
  40159. var dataIdx;
  40160. // Use the itemStyle in data if has data
  40161. if (data) {
  40162. dataIdx = data.indexOfName(region.name);
  40163. // Only visual color of each item will be used. It can be encoded by dataRange
  40164. // But visual color of series is used in symbol drawing
  40165. //
  40166. // Visual color for each series is for the symbol draw
  40167. var visualColor = data.getItemVisual(dataIdx, 'color', true);
  40168. if (visualColor) {
  40169. itemStyle.fill = visualColor;
  40170. }
  40171. }
  40172. each$1(region.geometries, function (geometry) {
  40173. if (geometry.type !== 'polygon') {
  40174. return;
  40175. }
  40176. compoundPath.shape.paths.push(new Polygon({
  40177. shape: {
  40178. points: geometry.exterior
  40179. }
  40180. }));
  40181. for (var i = 0; i < (geometry.interiors ? geometry.interiors.length : 0); i++) {
  40182. compoundPath.shape.paths.push(new Polygon({
  40183. shape: {
  40184. points: geometry.interiors[i]
  40185. }
  40186. }));
  40187. }
  40188. });
  40189. compoundPath.setStyle(itemStyle);
  40190. compoundPath.style.strokeNoScale = true;
  40191. compoundPath.culling = true;
  40192. // Label
  40193. var showLabel = labelModel.get('show');
  40194. var hoverShowLabel = hoverLabelModel.get('show');
  40195. var isDataNaN = data && isNaN(data.get(data.mapDimension('value'), dataIdx));
  40196. var itemLayout = data && data.getItemLayout(dataIdx);
  40197. // In the following cases label will be drawn
  40198. // 1. In map series and data value is NaN
  40199. // 2. In geo component
  40200. // 4. Region has no series legendSymbol, which will be add a showLabel flag in mapSymbolLayout
  40201. if (
  40202. (isGeo || isDataNaN && (showLabel || hoverShowLabel))
  40203. || (itemLayout && itemLayout.showLabel)
  40204. ) {
  40205. var query = !isGeo ? dataIdx : region.name;
  40206. var labelFetcher;
  40207. // Consider dataIdx not found.
  40208. if (!data || dataIdx >= 0) {
  40209. labelFetcher = mapOrGeoModel;
  40210. }
  40211. var textEl = new Text({
  40212. position: region.center.slice(),
  40213. // FIXME
  40214. // label rotation is not support yet in geo or regions of series-map
  40215. // that has no data. The rotation will be effected by this `scale`.
  40216. // So needed to change to RectText?
  40217. scale: [1 / scale[0], 1 / scale[1]],
  40218. z2: 10,
  40219. silent: true
  40220. });
  40221. setLabelStyle(
  40222. textEl.style, textEl.hoverStyle = {}, labelModel, hoverLabelModel,
  40223. {
  40224. labelFetcher: labelFetcher,
  40225. labelDataIndex: query,
  40226. defaultText: region.name,
  40227. useInsideStyle: false
  40228. },
  40229. {
  40230. textAlign: 'center',
  40231. textVerticalAlign: 'middle'
  40232. }
  40233. );
  40234. regionGroup.add(textEl);
  40235. }
  40236. // setItemGraphicEl, setHoverStyle after all polygons and labels
  40237. // are added to the rigionGroup
  40238. if (data) {
  40239. data.setItemGraphicEl(dataIdx, regionGroup);
  40240. }
  40241. else {
  40242. var regionModel = mapOrGeoModel.getRegionModel(region.name);
  40243. // Package custom mouse event for geo component
  40244. compoundPath.eventData = {
  40245. componentType: 'geo',
  40246. componentIndex: mapOrGeoModel.componentIndex,
  40247. geoIndex: mapOrGeoModel.componentIndex,
  40248. name: region.name,
  40249. region: (regionModel && regionModel.option) || {}
  40250. };
  40251. }
  40252. var groupRegions = regionGroup.__regions || (regionGroup.__regions = []);
  40253. groupRegions.push(region);
  40254. setHoverStyle(
  40255. regionGroup,
  40256. hoverItemStyle,
  40257. {hoverSilentOnTouch: !!mapOrGeoModel.get('selectedMode')}
  40258. );
  40259. regionsGroup.add(regionGroup);
  40260. });
  40261. this._updateController(mapOrGeoModel, ecModel, api);
  40262. updateMapSelectHandler(this, mapOrGeoModel, regionsGroup, api, fromView);
  40263. updateMapSelected(mapOrGeoModel, regionsGroup);
  40264. },
  40265. remove: function () {
  40266. this._regionsGroup.removeAll();
  40267. this._backgroundGroup.removeAll();
  40268. this._controller.dispose();
  40269. this._mapName && geoSourceManager.removeGraphic(this._mapName, this.uid);
  40270. this._mapName = null;
  40271. this._controllerHost = {};
  40272. },
  40273. _updateBackground: function (geo) {
  40274. var mapName = geo.map;
  40275. if (this._mapName !== mapName) {
  40276. each$1(geoSourceManager.makeGraphic(mapName, this.uid), function (root) {
  40277. this._backgroundGroup.add(root);
  40278. }, this);
  40279. }
  40280. this._mapName = mapName;
  40281. },
  40282. _updateController: function (mapOrGeoModel, ecModel, api) {
  40283. var geo = mapOrGeoModel.coordinateSystem;
  40284. var controller = this._controller;
  40285. var controllerHost = this._controllerHost;
  40286. controllerHost.zoomLimit = mapOrGeoModel.get('scaleLimit');
  40287. controllerHost.zoom = geo.getZoom();
  40288. // roamType is will be set default true if it is null
  40289. controller.enable(mapOrGeoModel.get('roam') || false);
  40290. var mainType = mapOrGeoModel.mainType;
  40291. function makeActionBase() {
  40292. var action = {
  40293. type: 'geoRoam',
  40294. componentType: mainType
  40295. };
  40296. action[mainType + 'Id'] = mapOrGeoModel.id;
  40297. return action;
  40298. }
  40299. controller.off('pan').on('pan', function (e) {
  40300. this._mouseDownFlag = false;
  40301. updateViewOnPan(controllerHost, e.dx, e.dy);
  40302. api.dispatchAction(extend(makeActionBase(), {
  40303. dx: e.dx,
  40304. dy: e.dy
  40305. }));
  40306. }, this);
  40307. controller.off('zoom').on('zoom', function (e) {
  40308. this._mouseDownFlag = false;
  40309. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  40310. api.dispatchAction(extend(makeActionBase(), {
  40311. zoom: e.scale,
  40312. originX: e.originX,
  40313. originY: e.originY
  40314. }));
  40315. if (this._updateGroup) {
  40316. var scale = this.group.scale;
  40317. this._regionsGroup.traverse(function (el) {
  40318. if (el.type === 'text') {
  40319. el.attr('scale', [1 / scale[0], 1 / scale[1]]);
  40320. }
  40321. });
  40322. }
  40323. }, this);
  40324. controller.setPointerChecker(function (e, x, y) {
  40325. return geo.getViewRectAfterRoam().contain(x, y)
  40326. && !onIrrelevantElement(e, api, mapOrGeoModel);
  40327. });
  40328. }
  40329. };
  40330. /*
  40331. * Licensed to the Apache Software Foundation (ASF) under one
  40332. * or more contributor license agreements. See the NOTICE file
  40333. * distributed with this work for additional information
  40334. * regarding copyright ownership. The ASF licenses this file
  40335. * to you under the Apache License, Version 2.0 (the
  40336. * "License"); you may not use this file except in compliance
  40337. * with the License. You may obtain a copy of the License at
  40338. *
  40339. * http://www.apache.org/licenses/LICENSE-2.0
  40340. *
  40341. * Unless required by applicable law or agreed to in writing,
  40342. * software distributed under the License is distributed on an
  40343. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40344. * KIND, either express or implied. See the License for the
  40345. * specific language governing permissions and limitations
  40346. * under the License.
  40347. */
  40348. var HIGH_DOWN_PROP = '__seriesMapHighDown';
  40349. var RECORD_VERSION_PROP = '__seriesMapCallKey';
  40350. extendChartView({
  40351. type: 'map',
  40352. render: function (mapModel, ecModel, api, payload) {
  40353. // Not render if it is an toggleSelect action from self
  40354. if (payload && payload.type === 'mapToggleSelect'
  40355. && payload.from === this.uid
  40356. ) {
  40357. return;
  40358. }
  40359. var group = this.group;
  40360. group.removeAll();
  40361. if (mapModel.getHostGeoModel()) {
  40362. return;
  40363. }
  40364. // Not update map if it is an roam action from self
  40365. if (!(payload && payload.type === 'geoRoam'
  40366. && payload.componentType === 'series'
  40367. && payload.seriesId === mapModel.id
  40368. )
  40369. ) {
  40370. if (mapModel.needsDrawMap) {
  40371. var mapDraw = this._mapDraw || new MapDraw(api, true);
  40372. group.add(mapDraw.group);
  40373. mapDraw.draw(mapModel, ecModel, api, this, payload);
  40374. this._mapDraw = mapDraw;
  40375. }
  40376. else {
  40377. // Remove drawed map
  40378. this._mapDraw && this._mapDraw.remove();
  40379. this._mapDraw = null;
  40380. }
  40381. }
  40382. else {
  40383. var mapDraw = this._mapDraw;
  40384. mapDraw && group.add(mapDraw.group);
  40385. }
  40386. mapModel.get('showLegendSymbol') && ecModel.getComponent('legend')
  40387. && this._renderSymbols(mapModel, ecModel, api);
  40388. },
  40389. remove: function () {
  40390. this._mapDraw && this._mapDraw.remove();
  40391. this._mapDraw = null;
  40392. this.group.removeAll();
  40393. },
  40394. dispose: function () {
  40395. this._mapDraw && this._mapDraw.remove();
  40396. this._mapDraw = null;
  40397. },
  40398. _renderSymbols: function (mapModel, ecModel, api) {
  40399. var originalData = mapModel.originalData;
  40400. var group = this.group;
  40401. originalData.each(originalData.mapDimension('value'), function (value, originalDataIndex) {
  40402. if (isNaN(value)) {
  40403. return;
  40404. }
  40405. var layout = originalData.getItemLayout(originalDataIndex);
  40406. if (!layout || !layout.point) {
  40407. // Not exists in map
  40408. return;
  40409. }
  40410. var point = layout.point;
  40411. var offset = layout.offset;
  40412. var circle = new Circle({
  40413. style: {
  40414. // Because the special of map draw.
  40415. // Which needs statistic of multiple series and draw on one map.
  40416. // And each series also need a symbol with legend color
  40417. //
  40418. // Layout and visual are put one the different data
  40419. fill: mapModel.getData().getVisual('color')
  40420. },
  40421. shape: {
  40422. cx: point[0] + offset * 9,
  40423. cy: point[1],
  40424. r: 3
  40425. },
  40426. silent: true,
  40427. // Do not overlap the first series, on which labels are displayed.
  40428. z2: 8 + (!offset ? Z2_EMPHASIS_LIFT + 1 : 0)
  40429. });
  40430. // Only the series that has the first value on the same region is in charge of rendering the label.
  40431. // But consider the case:
  40432. // series: [
  40433. // {id: 'X', type: 'map', map: 'm', {data: [{name: 'A', value: 11}, {name: 'B', {value: 22}]},
  40434. // {id: 'Y', type: 'map', map: 'm', {data: [{name: 'A', value: 21}, {name: 'C', {value: 33}]}
  40435. // ]
  40436. // The offset `0` of item `A` is at series `X`, but of item `C` is at series `Y`.
  40437. // For backward compatibility, we follow the rule that render label `A` by the
  40438. // settings on series `X` but render label `C` by the settings on series `Y`.
  40439. if (!offset) {
  40440. var fullData = mapModel.mainSeries.getData();
  40441. var name = originalData.getName(originalDataIndex);
  40442. var fullIndex = fullData.indexOfName(name);
  40443. var itemModel = originalData.getItemModel(originalDataIndex);
  40444. var labelModel = itemModel.getModel('label');
  40445. var hoverLabelModel = itemModel.getModel('emphasis.label');
  40446. var regionGroup = fullData.getItemGraphicEl(fullIndex);
  40447. // `getFormattedLabel` needs to use `getData` inside. Here
  40448. // `mapModel.getData()` is shallow cloned from `mainSeries.getData()`.
  40449. // FIXME
  40450. // If this is not the `mainSeries`, the item model (like label formatter)
  40451. // set on original data item will never get. But it has been working
  40452. // like that from the begining, and this scenario is rarely encountered.
  40453. // So it won't be fixed until have to.
  40454. var normalText = retrieve2(
  40455. mapModel.getFormattedLabel(fullIndex, 'normal'),
  40456. name
  40457. );
  40458. var emphasisText = retrieve2(
  40459. mapModel.getFormattedLabel(fullIndex, 'emphasis'),
  40460. normalText
  40461. );
  40462. var highDownRecord = regionGroup[HIGH_DOWN_PROP];
  40463. var recordVersion = Math.random();
  40464. // Prevent from register listeners duplicatedly when roaming.
  40465. if (!highDownRecord) {
  40466. highDownRecord = regionGroup[HIGH_DOWN_PROP] = {};
  40467. var onEmphasis = curry(onRegionHighDown, true);
  40468. var onNormal = curry(onRegionHighDown, false);
  40469. regionGroup.on('mouseover', onEmphasis)
  40470. .on('mouseout', onNormal)
  40471. .on('emphasis', onEmphasis)
  40472. .on('normal', onNormal);
  40473. }
  40474. // Prevent removed regions effect current grapics.
  40475. regionGroup[RECORD_VERSION_PROP] = recordVersion;
  40476. extend(highDownRecord, {
  40477. recordVersion: recordVersion,
  40478. circle: circle,
  40479. labelModel: labelModel,
  40480. hoverLabelModel: hoverLabelModel,
  40481. emphasisText: emphasisText,
  40482. normalText: normalText
  40483. });
  40484. // FIXME
  40485. // Consider set option when emphasis.
  40486. enterRegionHighDown(highDownRecord, false);
  40487. }
  40488. group.add(circle);
  40489. });
  40490. }
  40491. });
  40492. function onRegionHighDown(toHighOrDown) {
  40493. var highDownRecord = this[HIGH_DOWN_PROP];
  40494. if (highDownRecord && highDownRecord.recordVersion === this[RECORD_VERSION_PROP]) {
  40495. enterRegionHighDown(highDownRecord, toHighOrDown);
  40496. }
  40497. }
  40498. function enterRegionHighDown(highDownRecord, toHighOrDown) {
  40499. var circle = highDownRecord.circle;
  40500. var labelModel = highDownRecord.labelModel;
  40501. var hoverLabelModel = highDownRecord.hoverLabelModel;
  40502. var emphasisText = highDownRecord.emphasisText;
  40503. var normalText = highDownRecord.normalText;
  40504. if (toHighOrDown) {
  40505. circle.style.extendFrom(
  40506. setTextStyle({}, hoverLabelModel, {
  40507. text: hoverLabelModel.get('show') ? emphasisText : null
  40508. }, {isRectText: true, useInsideStyle: false}, true)
  40509. );
  40510. // Make label upper than others if overlaps.
  40511. circle.__mapOriginalZ2 = circle.z2;
  40512. circle.z2 += Z2_EMPHASIS_LIFT;
  40513. }
  40514. else {
  40515. setTextStyle(circle.style, labelModel, {
  40516. text: labelModel.get('show') ? normalText : null,
  40517. textPosition: labelModel.getShallow('position') || 'bottom'
  40518. }, {isRectText: true, useInsideStyle: false});
  40519. // Trigger normalize style like padding.
  40520. circle.dirty(false);
  40521. if (circle.__mapOriginalZ2 != null) {
  40522. circle.z2 = circle.__mapOriginalZ2;
  40523. circle.__mapOriginalZ2 = null;
  40524. }
  40525. }
  40526. }
  40527. /*
  40528. * Licensed to the Apache Software Foundation (ASF) under one
  40529. * or more contributor license agreements. See the NOTICE file
  40530. * distributed with this work for additional information
  40531. * regarding copyright ownership. The ASF licenses this file
  40532. * to you under the Apache License, Version 2.0 (the
  40533. * "License"); you may not use this file except in compliance
  40534. * with the License. You may obtain a copy of the License at
  40535. *
  40536. * http://www.apache.org/licenses/LICENSE-2.0
  40537. *
  40538. * Unless required by applicable law or agreed to in writing,
  40539. * software distributed under the License is distributed on an
  40540. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40541. * KIND, either express or implied. See the License for the
  40542. * specific language governing permissions and limitations
  40543. * under the License.
  40544. */
  40545. /**
  40546. * @param {module:echarts/coord/View} view
  40547. * @param {Object} payload
  40548. * @param {Object} [zoomLimit]
  40549. */
  40550. function updateCenterAndZoom(
  40551. view, payload, zoomLimit
  40552. ) {
  40553. var previousZoom = view.getZoom();
  40554. var center = view.getCenter();
  40555. var zoom = payload.zoom;
  40556. var point = view.dataToPoint(center);
  40557. if (payload.dx != null && payload.dy != null) {
  40558. point[0] -= payload.dx;
  40559. point[1] -= payload.dy;
  40560. var center = view.pointToData(point);
  40561. view.setCenter(center);
  40562. }
  40563. if (zoom != null) {
  40564. if (zoomLimit) {
  40565. var zoomMin = zoomLimit.min || 0;
  40566. var zoomMax = zoomLimit.max || Infinity;
  40567. zoom = Math.max(
  40568. Math.min(previousZoom * zoom, zoomMax),
  40569. zoomMin
  40570. ) / previousZoom;
  40571. }
  40572. // Zoom on given point(originX, originY)
  40573. view.scale[0] *= zoom;
  40574. view.scale[1] *= zoom;
  40575. var position = view.position;
  40576. var fixX = (payload.originX - position[0]) * (zoom - 1);
  40577. var fixY = (payload.originY - position[1]) * (zoom - 1);
  40578. position[0] -= fixX;
  40579. position[1] -= fixY;
  40580. view.updateTransform();
  40581. // Get the new center
  40582. var center = view.pointToData(point);
  40583. view.setCenter(center);
  40584. view.setZoom(zoom * previousZoom);
  40585. }
  40586. return {
  40587. center: view.getCenter(),
  40588. zoom: view.getZoom()
  40589. };
  40590. }
  40591. /*
  40592. * Licensed to the Apache Software Foundation (ASF) under one
  40593. * or more contributor license agreements. See the NOTICE file
  40594. * distributed with this work for additional information
  40595. * regarding copyright ownership. The ASF licenses this file
  40596. * to you under the Apache License, Version 2.0 (the
  40597. * "License"); you may not use this file except in compliance
  40598. * with the License. You may obtain a copy of the License at
  40599. *
  40600. * http://www.apache.org/licenses/LICENSE-2.0
  40601. *
  40602. * Unless required by applicable law or agreed to in writing,
  40603. * software distributed under the License is distributed on an
  40604. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40605. * KIND, either express or implied. See the License for the
  40606. * specific language governing permissions and limitations
  40607. * under the License.
  40608. */
  40609. /**
  40610. * @payload
  40611. * @property {string} [componentType=series]
  40612. * @property {number} [dx]
  40613. * @property {number} [dy]
  40614. * @property {number} [zoom]
  40615. * @property {number} [originX]
  40616. * @property {number} [originY]
  40617. */
  40618. registerAction({
  40619. type: 'geoRoam',
  40620. event: 'geoRoam',
  40621. update: 'updateTransform'
  40622. }, function (payload, ecModel) {
  40623. var componentType = payload.componentType || 'series';
  40624. ecModel.eachComponent(
  40625. { mainType: componentType, query: payload },
  40626. function (componentModel) {
  40627. var geo = componentModel.coordinateSystem;
  40628. if (geo.type !== 'geo') {
  40629. return;
  40630. }
  40631. var res = updateCenterAndZoom(
  40632. geo, payload, componentModel.get('scaleLimit')
  40633. );
  40634. componentModel.setCenter
  40635. && componentModel.setCenter(res.center);
  40636. componentModel.setZoom
  40637. && componentModel.setZoom(res.zoom);
  40638. // All map series with same `map` use the same geo coordinate system
  40639. // So the center and zoom must be in sync. Include the series not selected by legend
  40640. if (componentType === 'series') {
  40641. each$1(componentModel.seriesGroup, function (seriesModel) {
  40642. seriesModel.setCenter(res.center);
  40643. seriesModel.setZoom(res.zoom);
  40644. });
  40645. }
  40646. }
  40647. );
  40648. });
  40649. /*
  40650. * Licensed to the Apache Software Foundation (ASF) under one
  40651. * or more contributor license agreements. See the NOTICE file
  40652. * distributed with this work for additional information
  40653. * regarding copyright ownership. The ASF licenses this file
  40654. * to you under the Apache License, Version 2.0 (the
  40655. * "License"); you may not use this file except in compliance
  40656. * with the License. You may obtain a copy of the License at
  40657. *
  40658. * http://www.apache.org/licenses/LICENSE-2.0
  40659. *
  40660. * Unless required by applicable law or agreed to in writing,
  40661. * software distributed under the License is distributed on an
  40662. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40663. * KIND, either express or implied. See the License for the
  40664. * specific language governing permissions and limitations
  40665. * under the License.
  40666. */
  40667. /**
  40668. * Simple view coordinate system
  40669. * Mapping given x, y to transformd view x, y
  40670. */
  40671. var v2ApplyTransform$1 = applyTransform;
  40672. // Dummy transform node
  40673. function TransformDummy() {
  40674. Transformable.call(this);
  40675. }
  40676. mixin(TransformDummy, Transformable);
  40677. function View(name) {
  40678. /**
  40679. * @type {string}
  40680. */
  40681. this.name = name;
  40682. /**
  40683. * @type {Object}
  40684. */
  40685. this.zoomLimit;
  40686. Transformable.call(this);
  40687. this._roamTransformable = new TransformDummy();
  40688. this._rawTransformable = new TransformDummy();
  40689. this._center;
  40690. this._zoom;
  40691. }
  40692. View.prototype = {
  40693. constructor: View,
  40694. type: 'view',
  40695. /**
  40696. * @param {Array.<string>}
  40697. * @readOnly
  40698. */
  40699. dimensions: ['x', 'y'],
  40700. /**
  40701. * Set bounding rect
  40702. * @param {number} x
  40703. * @param {number} y
  40704. * @param {number} width
  40705. * @param {number} height
  40706. */
  40707. // PENDING to getRect
  40708. setBoundingRect: function (x, y, width, height) {
  40709. this._rect = new BoundingRect(x, y, width, height);
  40710. return this._rect;
  40711. },
  40712. /**
  40713. * @return {module:zrender/core/BoundingRect}
  40714. */
  40715. // PENDING to getRect
  40716. getBoundingRect: function () {
  40717. return this._rect;
  40718. },
  40719. /**
  40720. * @param {number} x
  40721. * @param {number} y
  40722. * @param {number} width
  40723. * @param {number} height
  40724. */
  40725. setViewRect: function (x, y, width, height) {
  40726. this.transformTo(x, y, width, height);
  40727. this._viewRect = new BoundingRect(x, y, width, height);
  40728. },
  40729. /**
  40730. * Transformed to particular position and size
  40731. * @param {number} x
  40732. * @param {number} y
  40733. * @param {number} width
  40734. * @param {number} height
  40735. */
  40736. transformTo: function (x, y, width, height) {
  40737. var rect = this.getBoundingRect();
  40738. var rawTransform = this._rawTransformable;
  40739. rawTransform.transform = rect.calculateTransform(
  40740. new BoundingRect(x, y, width, height)
  40741. );
  40742. rawTransform.decomposeTransform();
  40743. this._updateTransform();
  40744. },
  40745. /**
  40746. * Set center of view
  40747. * @param {Array.<number>} [centerCoord]
  40748. */
  40749. setCenter: function (centerCoord) {
  40750. if (!centerCoord) {
  40751. return;
  40752. }
  40753. this._center = centerCoord;
  40754. this._updateCenterAndZoom();
  40755. },
  40756. /**
  40757. * @param {number} zoom
  40758. */
  40759. setZoom: function (zoom) {
  40760. zoom = zoom || 1;
  40761. var zoomLimit = this.zoomLimit;
  40762. if (zoomLimit) {
  40763. if (zoomLimit.max != null) {
  40764. zoom = Math.min(zoomLimit.max, zoom);
  40765. }
  40766. if (zoomLimit.min != null) {
  40767. zoom = Math.max(zoomLimit.min, zoom);
  40768. }
  40769. }
  40770. this._zoom = zoom;
  40771. this._updateCenterAndZoom();
  40772. },
  40773. /**
  40774. * Get default center without roam
  40775. */
  40776. getDefaultCenter: function () {
  40777. // Rect before any transform
  40778. var rawRect = this.getBoundingRect();
  40779. var cx = rawRect.x + rawRect.width / 2;
  40780. var cy = rawRect.y + rawRect.height / 2;
  40781. return [cx, cy];
  40782. },
  40783. getCenter: function () {
  40784. return this._center || this.getDefaultCenter();
  40785. },
  40786. getZoom: function () {
  40787. return this._zoom || 1;
  40788. },
  40789. /**
  40790. * @return {Array.<number}
  40791. */
  40792. getRoamTransform: function () {
  40793. return this._roamTransformable.getLocalTransform();
  40794. },
  40795. /**
  40796. * Remove roam
  40797. */
  40798. _updateCenterAndZoom: function () {
  40799. // Must update after view transform updated
  40800. var rawTransformMatrix = this._rawTransformable.getLocalTransform();
  40801. var roamTransform = this._roamTransformable;
  40802. var defaultCenter = this.getDefaultCenter();
  40803. var center = this.getCenter();
  40804. var zoom = this.getZoom();
  40805. center = applyTransform([], center, rawTransformMatrix);
  40806. defaultCenter = applyTransform([], defaultCenter, rawTransformMatrix);
  40807. roamTransform.origin = center;
  40808. roamTransform.position = [
  40809. defaultCenter[0] - center[0],
  40810. defaultCenter[1] - center[1]
  40811. ];
  40812. roamTransform.scale = [zoom, zoom];
  40813. this._updateTransform();
  40814. },
  40815. /**
  40816. * Update transform from roam and mapLocation
  40817. * @private
  40818. */
  40819. _updateTransform: function () {
  40820. var roamTransformable = this._roamTransformable;
  40821. var rawTransformable = this._rawTransformable;
  40822. rawTransformable.parent = roamTransformable;
  40823. roamTransformable.updateTransform();
  40824. rawTransformable.updateTransform();
  40825. copy$1(this.transform || (this.transform = []), rawTransformable.transform || create$1());
  40826. this._rawTransform = rawTransformable.getLocalTransform();
  40827. this.invTransform = this.invTransform || [];
  40828. invert(this.invTransform, this.transform);
  40829. this.decomposeTransform();
  40830. },
  40831. /**
  40832. * @return {module:zrender/core/BoundingRect}
  40833. */
  40834. getViewRect: function () {
  40835. return this._viewRect;
  40836. },
  40837. /**
  40838. * Get view rect after roam transform
  40839. * @return {module:zrender/core/BoundingRect}
  40840. */
  40841. getViewRectAfterRoam: function () {
  40842. var rect = this.getBoundingRect().clone();
  40843. rect.applyTransform(this.transform);
  40844. return rect;
  40845. },
  40846. /**
  40847. * Convert a single (lon, lat) data item to (x, y) point.
  40848. * @param {Array.<number>} data
  40849. * @param {boolean} noRoam
  40850. * @param {Array.<number>} [out]
  40851. * @return {Array.<number>}
  40852. */
  40853. dataToPoint: function (data, noRoam, out) {
  40854. var transform = noRoam ? this._rawTransform : this.transform;
  40855. out = out || [];
  40856. return transform
  40857. ? v2ApplyTransform$1(out, data, transform)
  40858. : copy(out, data);
  40859. },
  40860. /**
  40861. * Convert a (x, y) point to (lon, lat) data
  40862. * @param {Array.<number>} point
  40863. * @return {Array.<number>}
  40864. */
  40865. pointToData: function (point) {
  40866. var invTransform = this.invTransform;
  40867. return invTransform
  40868. ? v2ApplyTransform$1([], point, invTransform)
  40869. : [point[0], point[1]];
  40870. },
  40871. /**
  40872. * @implements
  40873. * see {module:echarts/CoodinateSystem}
  40874. */
  40875. convertToPixel: curry(doConvert$1, 'dataToPoint'),
  40876. /**
  40877. * @implements
  40878. * see {module:echarts/CoodinateSystem}
  40879. */
  40880. convertFromPixel: curry(doConvert$1, 'pointToData'),
  40881. /**
  40882. * @implements
  40883. * see {module:echarts/CoodinateSystem}
  40884. */
  40885. containPoint: function (point) {
  40886. return this.getViewRectAfterRoam().contain(point[0], point[1]);
  40887. }
  40888. /**
  40889. * @return {number}
  40890. */
  40891. // getScalarScale: function () {
  40892. // // Use determinant square root of transform to mutiply scalar
  40893. // var m = this.transform;
  40894. // var det = Math.sqrt(Math.abs(m[0] * m[3] - m[2] * m[1]));
  40895. // return det;
  40896. // }
  40897. };
  40898. mixin(View, Transformable);
  40899. function doConvert$1(methodName, ecModel, finder, value) {
  40900. var seriesModel = finder.seriesModel;
  40901. var coordSys = seriesModel ? seriesModel.coordinateSystem : null; // e.g., graph.
  40902. return coordSys === this ? coordSys[methodName](value) : null;
  40903. }
  40904. /*
  40905. * Licensed to the Apache Software Foundation (ASF) under one
  40906. * or more contributor license agreements. See the NOTICE file
  40907. * distributed with this work for additional information
  40908. * regarding copyright ownership. The ASF licenses this file
  40909. * to you under the Apache License, Version 2.0 (the
  40910. * "License"); you may not use this file except in compliance
  40911. * with the License. You may obtain a copy of the License at
  40912. *
  40913. * http://www.apache.org/licenses/LICENSE-2.0
  40914. *
  40915. * Unless required by applicable law or agreed to in writing,
  40916. * software distributed under the License is distributed on an
  40917. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40918. * KIND, either express or implied. See the License for the
  40919. * specific language governing permissions and limitations
  40920. * under the License.
  40921. */
  40922. /**
  40923. * [Geo description]
  40924. * For backward compatibility, the orginal interface:
  40925. * `name, map, geoJson, specialAreas, nameMap` is kept.
  40926. *
  40927. * @param {string|Object} name
  40928. * @param {string} map Map type
  40929. * Specify the positioned areas by left, top, width, height
  40930. * @param {Object.<string, string>} [nameMap]
  40931. * Specify name alias
  40932. * @param {boolean} [invertLongitute=true]
  40933. */
  40934. function Geo(name, map$$1, nameMap, invertLongitute) {
  40935. View.call(this, name);
  40936. /**
  40937. * Map type
  40938. * @type {string}
  40939. */
  40940. this.map = map$$1;
  40941. var source = geoSourceManager.load(map$$1, nameMap);
  40942. this._nameCoordMap = source.nameCoordMap;
  40943. this._regionsMap = source.regionsMap;
  40944. this._invertLongitute = invertLongitute == null ? true : invertLongitute;
  40945. /**
  40946. * @readOnly
  40947. */
  40948. this.regions = source.regions;
  40949. /**
  40950. * @type {module:zrender/src/core/BoundingRect}
  40951. */
  40952. this._rect = source.boundingRect;
  40953. }
  40954. Geo.prototype = {
  40955. constructor: Geo,
  40956. type: 'geo',
  40957. /**
  40958. * @param {Array.<string>}
  40959. * @readOnly
  40960. */
  40961. dimensions: ['lng', 'lat'],
  40962. /**
  40963. * If contain given lng,lat coord
  40964. * @param {Array.<number>}
  40965. * @readOnly
  40966. */
  40967. containCoord: function (coord) {
  40968. var regions = this.regions;
  40969. for (var i = 0; i < regions.length; i++) {
  40970. if (regions[i].contain(coord)) {
  40971. return true;
  40972. }
  40973. }
  40974. return false;
  40975. },
  40976. /**
  40977. * @override
  40978. */
  40979. transformTo: function (x, y, width, height) {
  40980. var rect = this.getBoundingRect();
  40981. var invertLongitute = this._invertLongitute;
  40982. rect = rect.clone();
  40983. if (invertLongitute) {
  40984. // Longitute is inverted
  40985. rect.y = -rect.y - rect.height;
  40986. }
  40987. var rawTransformable = this._rawTransformable;
  40988. rawTransformable.transform = rect.calculateTransform(
  40989. new BoundingRect(x, y, width, height)
  40990. );
  40991. rawTransformable.decomposeTransform();
  40992. if (invertLongitute) {
  40993. var scale = rawTransformable.scale;
  40994. scale[1] = -scale[1];
  40995. }
  40996. rawTransformable.updateTransform();
  40997. this._updateTransform();
  40998. },
  40999. /**
  41000. * @param {string} name
  41001. * @return {module:echarts/coord/geo/Region}
  41002. */
  41003. getRegion: function (name) {
  41004. return this._regionsMap.get(name);
  41005. },
  41006. getRegionByCoord: function (coord) {
  41007. var regions = this.regions;
  41008. for (var i = 0; i < regions.length; i++) {
  41009. if (regions[i].contain(coord)) {
  41010. return regions[i];
  41011. }
  41012. }
  41013. },
  41014. /**
  41015. * Add geoCoord for indexing by name
  41016. * @param {string} name
  41017. * @param {Array.<number>} geoCoord
  41018. */
  41019. addGeoCoord: function (name, geoCoord) {
  41020. this._nameCoordMap.set(name, geoCoord);
  41021. },
  41022. /**
  41023. * Get geoCoord by name
  41024. * @param {string} name
  41025. * @return {Array.<number>}
  41026. */
  41027. getGeoCoord: function (name) {
  41028. return this._nameCoordMap.get(name);
  41029. },
  41030. /**
  41031. * @override
  41032. */
  41033. getBoundingRect: function () {
  41034. return this._rect;
  41035. },
  41036. /**
  41037. * @param {string|Array.<number>} data
  41038. * @param {boolean} noRoam
  41039. * @param {Array.<number>} [out]
  41040. * @return {Array.<number>}
  41041. */
  41042. dataToPoint: function (data, noRoam, out) {
  41043. if (typeof data === 'string') {
  41044. // Map area name to geoCoord
  41045. data = this.getGeoCoord(data);
  41046. }
  41047. if (data) {
  41048. return View.prototype.dataToPoint.call(this, data, noRoam, out);
  41049. }
  41050. },
  41051. /**
  41052. * @override
  41053. */
  41054. convertToPixel: curry(doConvert, 'dataToPoint'),
  41055. /**
  41056. * @override
  41057. */
  41058. convertFromPixel: curry(doConvert, 'pointToData')
  41059. };
  41060. mixin(Geo, View);
  41061. function doConvert(methodName, ecModel, finder, value) {
  41062. var geoModel = finder.geoModel;
  41063. var seriesModel = finder.seriesModel;
  41064. var coordSys = geoModel
  41065. ? geoModel.coordinateSystem
  41066. : seriesModel
  41067. ? (
  41068. seriesModel.coordinateSystem // For map.
  41069. || (seriesModel.getReferringComponents('geo')[0] || {}).coordinateSystem
  41070. )
  41071. : null;
  41072. return coordSys === this ? coordSys[methodName](value) : null;
  41073. }
  41074. /*
  41075. * Licensed to the Apache Software Foundation (ASF) under one
  41076. * or more contributor license agreements. See the NOTICE file
  41077. * distributed with this work for additional information
  41078. * regarding copyright ownership. The ASF licenses this file
  41079. * to you under the Apache License, Version 2.0 (the
  41080. * "License"); you may not use this file except in compliance
  41081. * with the License. You may obtain a copy of the License at
  41082. *
  41083. * http://www.apache.org/licenses/LICENSE-2.0
  41084. *
  41085. * Unless required by applicable law or agreed to in writing,
  41086. * software distributed under the License is distributed on an
  41087. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41088. * KIND, either express or implied. See the License for the
  41089. * specific language governing permissions and limitations
  41090. * under the License.
  41091. */
  41092. /**
  41093. * Resize method bound to the geo
  41094. * @param {module:echarts/coord/geo/GeoModel|module:echarts/chart/map/MapModel} geoModel
  41095. * @param {module:echarts/ExtensionAPI} api
  41096. */
  41097. function resizeGeo(geoModel, api) {
  41098. var boundingCoords = geoModel.get('boundingCoords');
  41099. if (boundingCoords != null) {
  41100. var leftTop = boundingCoords[0];
  41101. var rightBottom = boundingCoords[1];
  41102. if (isNaN(leftTop[0]) || isNaN(leftTop[1]) || isNaN(rightBottom[0]) || isNaN(rightBottom[1])) {
  41103. if (__DEV__) {
  41104. console.error('Invalid boundingCoords');
  41105. }
  41106. }
  41107. else {
  41108. this.setBoundingRect(leftTop[0], leftTop[1], rightBottom[0] - leftTop[0], rightBottom[1] - leftTop[1]);
  41109. }
  41110. }
  41111. var rect = this.getBoundingRect();
  41112. var boxLayoutOption;
  41113. var center = geoModel.get('layoutCenter');
  41114. var size = geoModel.get('layoutSize');
  41115. var viewWidth = api.getWidth();
  41116. var viewHeight = api.getHeight();
  41117. var aspect = rect.width / rect.height * this.aspectScale;
  41118. var useCenterAndSize = false;
  41119. if (center && size) {
  41120. center = [
  41121. parsePercent$1(center[0], viewWidth),
  41122. parsePercent$1(center[1], viewHeight)
  41123. ];
  41124. size = parsePercent$1(size, Math.min(viewWidth, viewHeight));
  41125. if (!isNaN(center[0]) && !isNaN(center[1]) && !isNaN(size)) {
  41126. useCenterAndSize = true;
  41127. }
  41128. else {
  41129. if (__DEV__) {
  41130. console.warn('Given layoutCenter or layoutSize data are invalid. Use left/top/width/height instead.');
  41131. }
  41132. }
  41133. }
  41134. var viewRect;
  41135. if (useCenterAndSize) {
  41136. var viewRect = {};
  41137. if (aspect > 1) {
  41138. // Width is same with size
  41139. viewRect.width = size;
  41140. viewRect.height = size / aspect;
  41141. }
  41142. else {
  41143. viewRect.height = size;
  41144. viewRect.width = size * aspect;
  41145. }
  41146. viewRect.y = center[1] - viewRect.height / 2;
  41147. viewRect.x = center[0] - viewRect.width / 2;
  41148. }
  41149. else {
  41150. // Use left/top/width/height
  41151. boxLayoutOption = geoModel.getBoxLayoutParams();
  41152. // 0.75 rate
  41153. boxLayoutOption.aspect = aspect;
  41154. viewRect = getLayoutRect(boxLayoutOption, {
  41155. width: viewWidth,
  41156. height: viewHeight
  41157. });
  41158. }
  41159. this.setViewRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
  41160. this.setCenter(geoModel.get('center'));
  41161. this.setZoom(geoModel.get('zoom'));
  41162. }
  41163. /**
  41164. * @param {module:echarts/coord/Geo} geo
  41165. * @param {module:echarts/model/Model} model
  41166. * @inner
  41167. */
  41168. function setGeoCoords(geo, model) {
  41169. each$1(model.get('geoCoord'), function (geoCoord, name) {
  41170. geo.addGeoCoord(name, geoCoord);
  41171. });
  41172. }
  41173. var geoCreator = {
  41174. // For deciding which dimensions to use when creating list data
  41175. dimensions: Geo.prototype.dimensions,
  41176. create: function (ecModel, api) {
  41177. var geoList = [];
  41178. // FIXME Create each time may be slow
  41179. ecModel.eachComponent('geo', function (geoModel, idx) {
  41180. var name = geoModel.get('map');
  41181. var aspectScale = geoModel.get('aspectScale');
  41182. var invertLongitute = true;
  41183. var mapRecords = mapDataStorage.retrieveMap(name);
  41184. if (mapRecords && mapRecords[0] && mapRecords[0].type === 'svg') {
  41185. aspectScale == null && (aspectScale = 1);
  41186. invertLongitute = false;
  41187. }
  41188. else {
  41189. aspectScale == null && (aspectScale = 0.75);
  41190. }
  41191. var geo = new Geo(name + idx, name, geoModel.get('nameMap'), invertLongitute);
  41192. geo.aspectScale = aspectScale;
  41193. geo.zoomLimit = geoModel.get('scaleLimit');
  41194. geoList.push(geo);
  41195. setGeoCoords(geo, geoModel);
  41196. geoModel.coordinateSystem = geo;
  41197. geo.model = geoModel;
  41198. // Inject resize method
  41199. geo.resize = resizeGeo;
  41200. geo.resize(geoModel, api);
  41201. });
  41202. ecModel.eachSeries(function (seriesModel) {
  41203. var coordSys = seriesModel.get('coordinateSystem');
  41204. if (coordSys === 'geo') {
  41205. var geoIndex = seriesModel.get('geoIndex') || 0;
  41206. seriesModel.coordinateSystem = geoList[geoIndex];
  41207. }
  41208. });
  41209. // If has map series
  41210. var mapModelGroupBySeries = {};
  41211. ecModel.eachSeriesByType('map', function (seriesModel) {
  41212. if (!seriesModel.getHostGeoModel()) {
  41213. var mapType = seriesModel.getMapType();
  41214. mapModelGroupBySeries[mapType] = mapModelGroupBySeries[mapType] || [];
  41215. mapModelGroupBySeries[mapType].push(seriesModel);
  41216. }
  41217. });
  41218. each$1(mapModelGroupBySeries, function (mapSeries, mapType) {
  41219. var nameMapList = map(mapSeries, function (singleMapSeries) {
  41220. return singleMapSeries.get('nameMap');
  41221. });
  41222. var geo = new Geo(mapType, mapType, mergeAll(nameMapList));
  41223. geo.zoomLimit = retrieve.apply(null, map(mapSeries, function (singleMapSeries) {
  41224. return singleMapSeries.get('scaleLimit');
  41225. }));
  41226. geoList.push(geo);
  41227. // Inject resize method
  41228. geo.resize = resizeGeo;
  41229. geo.aspectScale = mapSeries[0].get('aspectScale');
  41230. geo.resize(mapSeries[0], api);
  41231. each$1(mapSeries, function (singleMapSeries) {
  41232. singleMapSeries.coordinateSystem = geo;
  41233. setGeoCoords(geo, singleMapSeries);
  41234. });
  41235. });
  41236. return geoList;
  41237. },
  41238. /**
  41239. * Fill given regions array
  41240. * @param {Array.<Object>} originRegionArr
  41241. * @param {string} mapName
  41242. * @param {Object} [nameMap]
  41243. * @return {Array}
  41244. */
  41245. getFilledRegions: function (originRegionArr, mapName, nameMap) {
  41246. // Not use the original
  41247. var regionsArr = (originRegionArr || []).slice();
  41248. var dataNameMap = createHashMap();
  41249. for (var i = 0; i < regionsArr.length; i++) {
  41250. dataNameMap.set(regionsArr[i].name, regionsArr[i]);
  41251. }
  41252. var source = geoSourceManager.load(mapName, nameMap);
  41253. each$1(source.regions, function (region) {
  41254. var name = region.name;
  41255. !dataNameMap.get(name) && regionsArr.push({name: name});
  41256. });
  41257. return regionsArr;
  41258. }
  41259. };
  41260. registerCoordinateSystem('geo', geoCreator);
  41261. /*
  41262. * Licensed to the Apache Software Foundation (ASF) under one
  41263. * or more contributor license agreements. See the NOTICE file
  41264. * distributed with this work for additional information
  41265. * regarding copyright ownership. The ASF licenses this file
  41266. * to you under the Apache License, Version 2.0 (the
  41267. * "License"); you may not use this file except in compliance
  41268. * with the License. You may obtain a copy of the License at
  41269. *
  41270. * http://www.apache.org/licenses/LICENSE-2.0
  41271. *
  41272. * Unless required by applicable law or agreed to in writing,
  41273. * software distributed under the License is distributed on an
  41274. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41275. * KIND, either express or implied. See the License for the
  41276. * specific language governing permissions and limitations
  41277. * under the License.
  41278. */
  41279. var mapSymbolLayout = function (ecModel) {
  41280. var processedMapType = {};
  41281. ecModel.eachSeriesByType('map', function (mapSeries) {
  41282. var mapType = mapSeries.getMapType();
  41283. if (mapSeries.getHostGeoModel() || processedMapType[mapType]) {
  41284. return;
  41285. }
  41286. var mapSymbolOffsets = {};
  41287. each$1(mapSeries.seriesGroup, function (subMapSeries) {
  41288. var geo = subMapSeries.coordinateSystem;
  41289. var data = subMapSeries.originalData;
  41290. if (subMapSeries.get('showLegendSymbol') && ecModel.getComponent('legend')) {
  41291. data.each(data.mapDimension('value'), function (value, idx) {
  41292. var name = data.getName(idx);
  41293. var region = geo.getRegion(name);
  41294. // If input series.data is [11, 22, '-'/null/undefined, 44],
  41295. // it will be filled with NaN: [11, 22, NaN, 44] and NaN will
  41296. // not be drawn. So here must validate if value is NaN.
  41297. if (!region || isNaN(value)) {
  41298. return;
  41299. }
  41300. var offset = mapSymbolOffsets[name] || 0;
  41301. var point = geo.dataToPoint(region.center);
  41302. mapSymbolOffsets[name] = offset + 1;
  41303. data.setItemLayout(idx, {
  41304. point: point,
  41305. offset: offset
  41306. });
  41307. });
  41308. }
  41309. });
  41310. // Show label of those region not has legendSymbol(which is offset 0)
  41311. var data = mapSeries.getData();
  41312. data.each(function (idx) {
  41313. var name = data.getName(idx);
  41314. var layout = data.getItemLayout(idx) || {};
  41315. layout.showLabel = !mapSymbolOffsets[name];
  41316. data.setItemLayout(idx, layout);
  41317. });
  41318. processedMapType[mapType] = true;
  41319. });
  41320. };
  41321. /*
  41322. * Licensed to the Apache Software Foundation (ASF) under one
  41323. * or more contributor license agreements. See the NOTICE file
  41324. * distributed with this work for additional information
  41325. * regarding copyright ownership. The ASF licenses this file
  41326. * to you under the Apache License, Version 2.0 (the
  41327. * "License"); you may not use this file except in compliance
  41328. * with the License. You may obtain a copy of the License at
  41329. *
  41330. * http://www.apache.org/licenses/LICENSE-2.0
  41331. *
  41332. * Unless required by applicable law or agreed to in writing,
  41333. * software distributed under the License is distributed on an
  41334. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41335. * KIND, either express or implied. See the License for the
  41336. * specific language governing permissions and limitations
  41337. * under the License.
  41338. */
  41339. var mapVisual = function (ecModel) {
  41340. ecModel.eachSeriesByType('map', function (seriesModel) {
  41341. var colorList = seriesModel.get('color');
  41342. var itemStyleModel = seriesModel.getModel('itemStyle');
  41343. var areaColor = itemStyleModel.get('areaColor');
  41344. var color = itemStyleModel.get('color')
  41345. || colorList[seriesModel.seriesIndex % colorList.length];
  41346. seriesModel.getData().setVisual({
  41347. 'areaColor': areaColor,
  41348. 'color': color
  41349. });
  41350. });
  41351. };
  41352. /*
  41353. * Licensed to the Apache Software Foundation (ASF) under one
  41354. * or more contributor license agreements. See the NOTICE file
  41355. * distributed with this work for additional information
  41356. * regarding copyright ownership. The ASF licenses this file
  41357. * to you under the Apache License, Version 2.0 (the
  41358. * "License"); you may not use this file except in compliance
  41359. * with the License. You may obtain a copy of the License at
  41360. *
  41361. * http://www.apache.org/licenses/LICENSE-2.0
  41362. *
  41363. * Unless required by applicable law or agreed to in writing,
  41364. * software distributed under the License is distributed on an
  41365. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41366. * KIND, either express or implied. See the License for the
  41367. * specific language governing permissions and limitations
  41368. * under the License.
  41369. */
  41370. // FIXME 公用?
  41371. /**
  41372. * @param {Array.<module:echarts/data/List>} datas
  41373. * @param {string} statisticType 'average' 'sum'
  41374. * @inner
  41375. */
  41376. function dataStatistics(datas, statisticType) {
  41377. var dataNameMap = {};
  41378. each$1(datas, function (data) {
  41379. data.each(data.mapDimension('value'), function (value, idx) {
  41380. // Add prefix to avoid conflict with Object.prototype.
  41381. var mapKey = 'ec-' + data.getName(idx);
  41382. dataNameMap[mapKey] = dataNameMap[mapKey] || [];
  41383. if (!isNaN(value)) {
  41384. dataNameMap[mapKey].push(value);
  41385. }
  41386. });
  41387. });
  41388. return datas[0].map(datas[0].mapDimension('value'), function (value, idx) {
  41389. var mapKey = 'ec-' + datas[0].getName(idx);
  41390. var sum = 0;
  41391. var min = Infinity;
  41392. var max = -Infinity;
  41393. var len = dataNameMap[mapKey].length;
  41394. for (var i = 0; i < len; i++) {
  41395. min = Math.min(min, dataNameMap[mapKey][i]);
  41396. max = Math.max(max, dataNameMap[mapKey][i]);
  41397. sum += dataNameMap[mapKey][i];
  41398. }
  41399. var result;
  41400. if (statisticType === 'min') {
  41401. result = min;
  41402. }
  41403. else if (statisticType === 'max') {
  41404. result = max;
  41405. }
  41406. else if (statisticType === 'average') {
  41407. result = sum / len;
  41408. }
  41409. else {
  41410. result = sum;
  41411. }
  41412. return len === 0 ? NaN : result;
  41413. });
  41414. }
  41415. var mapDataStatistic = function (ecModel) {
  41416. var seriesGroups = {};
  41417. ecModel.eachSeriesByType('map', function (seriesModel) {
  41418. var hostGeoModel = seriesModel.getHostGeoModel();
  41419. var key = hostGeoModel ? 'o' + hostGeoModel.id : 'i' + seriesModel.getMapType();
  41420. (seriesGroups[key] = seriesGroups[key] || []).push(seriesModel);
  41421. });
  41422. each$1(seriesGroups, function (seriesList, key) {
  41423. var data = dataStatistics(
  41424. map(seriesList, function (seriesModel) {
  41425. return seriesModel.getData();
  41426. }),
  41427. seriesList[0].get('mapValueCalculation')
  41428. );
  41429. for (var i = 0; i < seriesList.length; i++) {
  41430. seriesList[i].originalData = seriesList[i].getData();
  41431. }
  41432. // FIXME Put where?
  41433. for (var i = 0; i < seriesList.length; i++) {
  41434. seriesList[i].seriesGroup = seriesList;
  41435. seriesList[i].needsDrawMap = i === 0 && !seriesList[i].getHostGeoModel();
  41436. seriesList[i].setData(data.cloneShallow());
  41437. seriesList[i].mainSeries = seriesList[0];
  41438. }
  41439. });
  41440. };
  41441. /*
  41442. * Licensed to the Apache Software Foundation (ASF) under one
  41443. * or more contributor license agreements. See the NOTICE file
  41444. * distributed with this work for additional information
  41445. * regarding copyright ownership. The ASF licenses this file
  41446. * to you under the Apache License, Version 2.0 (the
  41447. * "License"); you may not use this file except in compliance
  41448. * with the License. You may obtain a copy of the License at
  41449. *
  41450. * http://www.apache.org/licenses/LICENSE-2.0
  41451. *
  41452. * Unless required by applicable law or agreed to in writing,
  41453. * software distributed under the License is distributed on an
  41454. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41455. * KIND, either express or implied. See the License for the
  41456. * specific language governing permissions and limitations
  41457. * under the License.
  41458. */
  41459. var backwardCompat$2 = function (option) {
  41460. // Save geoCoord
  41461. var mapSeries = [];
  41462. each$1(option.series, function (seriesOpt) {
  41463. if (seriesOpt && seriesOpt.type === 'map') {
  41464. mapSeries.push(seriesOpt);
  41465. seriesOpt.map = seriesOpt.map || seriesOpt.mapType;
  41466. // Put x, y, width, height, x2, y2 in the top level
  41467. defaults(seriesOpt, seriesOpt.mapLocation);
  41468. }
  41469. });
  41470. };
  41471. /*
  41472. * Licensed to the Apache Software Foundation (ASF) under one
  41473. * or more contributor license agreements. See the NOTICE file
  41474. * distributed with this work for additional information
  41475. * regarding copyright ownership. The ASF licenses this file
  41476. * to you under the Apache License, Version 2.0 (the
  41477. * "License"); you may not use this file except in compliance
  41478. * with the License. You may obtain a copy of the License at
  41479. *
  41480. * http://www.apache.org/licenses/LICENSE-2.0
  41481. *
  41482. * Unless required by applicable law or agreed to in writing,
  41483. * software distributed under the License is distributed on an
  41484. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41485. * KIND, either express or implied. See the License for the
  41486. * specific language governing permissions and limitations
  41487. * under the License.
  41488. */
  41489. registerLayout(mapSymbolLayout);
  41490. registerVisual(mapVisual);
  41491. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, mapDataStatistic);
  41492. registerPreprocessor(backwardCompat$2);
  41493. createDataSelectAction('map', [{
  41494. type: 'mapToggleSelect',
  41495. event: 'mapselectchanged',
  41496. method: 'toggleSelected'
  41497. }, {
  41498. type: 'mapSelect',
  41499. event: 'mapselected',
  41500. method: 'select'
  41501. }, {
  41502. type: 'mapUnSelect',
  41503. event: 'mapunselected',
  41504. method: 'unSelect'
  41505. }]);
  41506. /*
  41507. * Licensed to the Apache Software Foundation (ASF) under one
  41508. * or more contributor license agreements. See the NOTICE file
  41509. * distributed with this work for additional information
  41510. * regarding copyright ownership. The ASF licenses this file
  41511. * to you under the Apache License, Version 2.0 (the
  41512. * "License"); you may not use this file except in compliance
  41513. * with the License. You may obtain a copy of the License at
  41514. *
  41515. * http://www.apache.org/licenses/LICENSE-2.0
  41516. *
  41517. * Unless required by applicable law or agreed to in writing,
  41518. * software distributed under the License is distributed on an
  41519. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41520. * KIND, either express or implied. See the License for the
  41521. * specific language governing permissions and limitations
  41522. * under the License.
  41523. */
  41524. /**
  41525. * Link lists and struct (graph or tree)
  41526. */
  41527. var each$7 = each$1;
  41528. var DATAS = '\0__link_datas';
  41529. var MAIN_DATA = '\0__link_mainData';
  41530. // Caution:
  41531. // In most case, either list or its shallow clones (see list.cloneShallow)
  41532. // is active in echarts process. So considering heap memory consumption,
  41533. // we do not clone tree or graph, but share them among list and its shallow clones.
  41534. // But in some rare case, we have to keep old list (like do animation in chart). So
  41535. // please take care that both the old list and the new list share the same tree/graph.
  41536. /**
  41537. * @param {Object} opt
  41538. * @param {module:echarts/data/List} opt.mainData
  41539. * @param {Object} [opt.struct] For example, instance of Graph or Tree.
  41540. * @param {string} [opt.structAttr] designation: list[structAttr] = struct;
  41541. * @param {Object} [opt.datas] {dataType: data},
  41542. * like: {node: nodeList, edge: edgeList}.
  41543. * Should contain mainData.
  41544. * @param {Object} [opt.datasAttr] {dataType: attr},
  41545. * designation: struct[datasAttr[dataType]] = list;
  41546. */
  41547. function linkList(opt) {
  41548. var mainData = opt.mainData;
  41549. var datas = opt.datas;
  41550. if (!datas) {
  41551. datas = {main: mainData};
  41552. opt.datasAttr = {main: 'data'};
  41553. }
  41554. opt.datas = opt.mainData = null;
  41555. linkAll(mainData, datas, opt);
  41556. // Porxy data original methods.
  41557. each$7(datas, function (data) {
  41558. each$7(mainData.TRANSFERABLE_METHODS, function (methodName) {
  41559. data.wrapMethod(methodName, curry(transferInjection, opt));
  41560. });
  41561. });
  41562. // Beyond transfer, additional features should be added to `cloneShallow`.
  41563. mainData.wrapMethod('cloneShallow', curry(cloneShallowInjection, opt));
  41564. // Only mainData trigger change, because struct.update may trigger
  41565. // another changable methods, which may bring about dead lock.
  41566. each$7(mainData.CHANGABLE_METHODS, function (methodName) {
  41567. mainData.wrapMethod(methodName, curry(changeInjection, opt));
  41568. });
  41569. // Make sure datas contains mainData.
  41570. assert$1(datas[mainData.dataType] === mainData);
  41571. }
  41572. function transferInjection(opt, res) {
  41573. if (isMainData(this)) {
  41574. // Transfer datas to new main data.
  41575. var datas = extend({}, this[DATAS]);
  41576. datas[this.dataType] = res;
  41577. linkAll(res, datas, opt);
  41578. }
  41579. else {
  41580. // Modify the reference in main data to point newData.
  41581. linkSingle(res, this.dataType, this[MAIN_DATA], opt);
  41582. }
  41583. return res;
  41584. }
  41585. function changeInjection(opt, res) {
  41586. opt.struct && opt.struct.update(this);
  41587. return res;
  41588. }
  41589. function cloneShallowInjection(opt, res) {
  41590. // cloneShallow, which brings about some fragilities, may be inappropriate
  41591. // to be exposed as an API. So for implementation simplicity we can make
  41592. // the restriction that cloneShallow of not-mainData should not be invoked
  41593. // outside, but only be invoked here.
  41594. each$7(res[DATAS], function (data, dataType) {
  41595. data !== res && linkSingle(data.cloneShallow(), dataType, res, opt);
  41596. });
  41597. return res;
  41598. }
  41599. /**
  41600. * Supplement method to List.
  41601. *
  41602. * @public
  41603. * @param {string} [dataType] If not specified, return mainData.
  41604. * @return {module:echarts/data/List}
  41605. */
  41606. function getLinkedData(dataType) {
  41607. var mainData = this[MAIN_DATA];
  41608. return (dataType == null || mainData == null)
  41609. ? mainData
  41610. : mainData[DATAS][dataType];
  41611. }
  41612. function isMainData(data) {
  41613. return data[MAIN_DATA] === data;
  41614. }
  41615. function linkAll(mainData, datas, opt) {
  41616. mainData[DATAS] = {};
  41617. each$7(datas, function (data, dataType) {
  41618. linkSingle(data, dataType, mainData, opt);
  41619. });
  41620. }
  41621. function linkSingle(data, dataType, mainData, opt) {
  41622. mainData[DATAS][dataType] = data;
  41623. data[MAIN_DATA] = mainData;
  41624. data.dataType = dataType;
  41625. if (opt.struct) {
  41626. data[opt.structAttr] = opt.struct;
  41627. opt.struct[opt.datasAttr[dataType]] = data;
  41628. }
  41629. // Supplement method.
  41630. data.getLinkedData = getLinkedData;
  41631. }
  41632. /*
  41633. * Licensed to the Apache Software Foundation (ASF) under one
  41634. * or more contributor license agreements. See the NOTICE file
  41635. * distributed with this work for additional information
  41636. * regarding copyright ownership. The ASF licenses this file
  41637. * to you under the Apache License, Version 2.0 (the
  41638. * "License"); you may not use this file except in compliance
  41639. * with the License. You may obtain a copy of the License at
  41640. *
  41641. * http://www.apache.org/licenses/LICENSE-2.0
  41642. *
  41643. * Unless required by applicable law or agreed to in writing,
  41644. * software distributed under the License is distributed on an
  41645. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41646. * KIND, either express or implied. See the License for the
  41647. * specific language governing permissions and limitations
  41648. * under the License.
  41649. */
  41650. /**
  41651. * Tree data structure
  41652. *
  41653. * @module echarts/data/Tree
  41654. */
  41655. /**
  41656. * @constructor module:echarts/data/Tree~TreeNode
  41657. * @param {string} name
  41658. * @param {module:echarts/data/Tree} hostTree
  41659. */
  41660. var TreeNode = function (name, hostTree) {
  41661. /**
  41662. * @type {string}
  41663. */
  41664. this.name = name || '';
  41665. /**
  41666. * Depth of node
  41667. *
  41668. * @type {number}
  41669. * @readOnly
  41670. */
  41671. this.depth = 0;
  41672. /**
  41673. * Height of the subtree rooted at this node.
  41674. * @type {number}
  41675. * @readOnly
  41676. */
  41677. this.height = 0;
  41678. /**
  41679. * @type {module:echarts/data/Tree~TreeNode}
  41680. * @readOnly
  41681. */
  41682. this.parentNode = null;
  41683. /**
  41684. * Reference to list item.
  41685. * Do not persistent dataIndex outside,
  41686. * besause it may be changed by list.
  41687. * If dataIndex -1,
  41688. * this node is logical deleted (filtered) in list.
  41689. *
  41690. * @type {Object}
  41691. * @readOnly
  41692. */
  41693. this.dataIndex = -1;
  41694. /**
  41695. * @type {Array.<module:echarts/data/Tree~TreeNode>}
  41696. * @readOnly
  41697. */
  41698. this.children = [];
  41699. /**
  41700. * @type {Array.<module:echarts/data/Tree~TreeNode>}
  41701. * @pubilc
  41702. */
  41703. this.viewChildren = [];
  41704. /**
  41705. * @type {moduel:echarts/data/Tree}
  41706. * @readOnly
  41707. */
  41708. this.hostTree = hostTree;
  41709. };
  41710. TreeNode.prototype = {
  41711. constructor: TreeNode,
  41712. /**
  41713. * The node is removed.
  41714. * @return {boolean} is removed.
  41715. */
  41716. isRemoved: function () {
  41717. return this.dataIndex < 0;
  41718. },
  41719. /**
  41720. * Travel this subtree (include this node).
  41721. * Usage:
  41722. * node.eachNode(function () { ... }); // preorder
  41723. * node.eachNode('preorder', function () { ... }); // preorder
  41724. * node.eachNode('postorder', function () { ... }); // postorder
  41725. * node.eachNode(
  41726. * {order: 'postorder', attr: 'viewChildren'},
  41727. * function () { ... }
  41728. * ); // postorder
  41729. *
  41730. * @param {(Object|string)} options If string, means order.
  41731. * @param {string=} options.order 'preorder' or 'postorder'
  41732. * @param {string=} options.attr 'children' or 'viewChildren'
  41733. * @param {Function} cb If in preorder and return false,
  41734. * its subtree will not be visited.
  41735. * @param {Object} [context]
  41736. */
  41737. eachNode: function (options, cb, context) {
  41738. if (typeof options === 'function') {
  41739. context = cb;
  41740. cb = options;
  41741. options = null;
  41742. }
  41743. options = options || {};
  41744. if (isString(options)) {
  41745. options = {order: options};
  41746. }
  41747. var order = options.order || 'preorder';
  41748. var children = this[options.attr || 'children'];
  41749. var suppressVisitSub;
  41750. order === 'preorder' && (suppressVisitSub = cb.call(context, this));
  41751. for (var i = 0; !suppressVisitSub && i < children.length; i++) {
  41752. children[i].eachNode(options, cb, context);
  41753. }
  41754. order === 'postorder' && cb.call(context, this);
  41755. },
  41756. /**
  41757. * Update depth and height of this subtree.
  41758. *
  41759. * @param {number} depth
  41760. */
  41761. updateDepthAndHeight: function (depth) {
  41762. var height = 0;
  41763. this.depth = depth;
  41764. for (var i = 0; i < this.children.length; i++) {
  41765. var child = this.children[i];
  41766. child.updateDepthAndHeight(depth + 1);
  41767. if (child.height > height) {
  41768. height = child.height;
  41769. }
  41770. }
  41771. this.height = height + 1;
  41772. },
  41773. /**
  41774. * @param {string} id
  41775. * @return {module:echarts/data/Tree~TreeNode}
  41776. */
  41777. getNodeById: function (id) {
  41778. if (this.getId() === id) {
  41779. return this;
  41780. }
  41781. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  41782. var res = children[i].getNodeById(id);
  41783. if (res) {
  41784. return res;
  41785. }
  41786. }
  41787. },
  41788. /**
  41789. * @param {module:echarts/data/Tree~TreeNode} node
  41790. * @return {boolean}
  41791. */
  41792. contains: function (node) {
  41793. if (node === this) {
  41794. return true;
  41795. }
  41796. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  41797. var res = children[i].contains(node);
  41798. if (res) {
  41799. return res;
  41800. }
  41801. }
  41802. },
  41803. /**
  41804. * @param {boolean} includeSelf Default false.
  41805. * @return {Array.<module:echarts/data/Tree~TreeNode>} order: [root, child, grandchild, ...]
  41806. */
  41807. getAncestors: function (includeSelf) {
  41808. var ancestors = [];
  41809. var node = includeSelf ? this : this.parentNode;
  41810. while (node) {
  41811. ancestors.push(node);
  41812. node = node.parentNode;
  41813. }
  41814. ancestors.reverse();
  41815. return ancestors;
  41816. },
  41817. /**
  41818. * @param {string|Array=} [dimension='value'] Default 'value'. can be 0, 1, 2, 3
  41819. * @return {number} Value.
  41820. */
  41821. getValue: function (dimension) {
  41822. var data = this.hostTree.data;
  41823. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  41824. },
  41825. /**
  41826. * @param {Object} layout
  41827. * @param {boolean=} [merge=false]
  41828. */
  41829. setLayout: function (layout, merge$$1) {
  41830. this.dataIndex >= 0
  41831. && this.hostTree.data.setItemLayout(this.dataIndex, layout, merge$$1);
  41832. },
  41833. /**
  41834. * @return {Object} layout
  41835. */
  41836. getLayout: function () {
  41837. return this.hostTree.data.getItemLayout(this.dataIndex);
  41838. },
  41839. /**
  41840. * @param {string} [path]
  41841. * @return {module:echarts/model/Model}
  41842. */
  41843. getModel: function (path) {
  41844. if (this.dataIndex < 0) {
  41845. return;
  41846. }
  41847. var hostTree = this.hostTree;
  41848. var itemModel = hostTree.data.getItemModel(this.dataIndex);
  41849. var levelModel = this.getLevelModel();
  41850. var leavesModel;
  41851. if (!levelModel && (this.children.length === 0 || (this.children.length !== 0 && this.isExpand === false))) {
  41852. leavesModel = this.getLeavesModel();
  41853. }
  41854. return itemModel.getModel(path, (levelModel || leavesModel || hostTree.hostModel).getModel(path));
  41855. },
  41856. /**
  41857. * @return {module:echarts/model/Model}
  41858. */
  41859. getLevelModel: function () {
  41860. return (this.hostTree.levelModels || [])[this.depth];
  41861. },
  41862. /**
  41863. * @return {module:echarts/model/Model}
  41864. */
  41865. getLeavesModel: function () {
  41866. return this.hostTree.leavesModel;
  41867. },
  41868. /**
  41869. * @example
  41870. * setItemVisual('color', color);
  41871. * setItemVisual({
  41872. * 'color': color
  41873. * });
  41874. */
  41875. setVisual: function (key, value) {
  41876. this.dataIndex >= 0
  41877. && this.hostTree.data.setItemVisual(this.dataIndex, key, value);
  41878. },
  41879. /**
  41880. * Get item visual
  41881. */
  41882. getVisual: function (key, ignoreParent) {
  41883. return this.hostTree.data.getItemVisual(this.dataIndex, key, ignoreParent);
  41884. },
  41885. /**
  41886. * @public
  41887. * @return {number}
  41888. */
  41889. getRawIndex: function () {
  41890. return this.hostTree.data.getRawIndex(this.dataIndex);
  41891. },
  41892. /**
  41893. * @public
  41894. * @return {string}
  41895. */
  41896. getId: function () {
  41897. return this.hostTree.data.getId(this.dataIndex);
  41898. },
  41899. /**
  41900. * if this is an ancestor of another node
  41901. *
  41902. * @public
  41903. * @param {TreeNode} node another node
  41904. * @return {boolean} if is ancestor
  41905. */
  41906. isAncestorOf: function (node) {
  41907. var parent = node.parentNode;
  41908. while (parent) {
  41909. if (parent === this) {
  41910. return true;
  41911. }
  41912. parent = parent.parentNode;
  41913. }
  41914. return false;
  41915. },
  41916. /**
  41917. * if this is an descendant of another node
  41918. *
  41919. * @public
  41920. * @param {TreeNode} node another node
  41921. * @return {boolean} if is descendant
  41922. */
  41923. isDescendantOf: function (node) {
  41924. return node !== this && node.isAncestorOf(this);
  41925. }
  41926. };
  41927. /**
  41928. * @constructor
  41929. * @alias module:echarts/data/Tree
  41930. * @param {module:echarts/model/Model} hostModel
  41931. * @param {Array.<Object>} levelOptions
  41932. * @param {Object} leavesOption
  41933. */
  41934. function Tree(hostModel, levelOptions, leavesOption) {
  41935. /**
  41936. * @type {module:echarts/data/Tree~TreeNode}
  41937. * @readOnly
  41938. */
  41939. this.root;
  41940. /**
  41941. * @type {module:echarts/data/List}
  41942. * @readOnly
  41943. */
  41944. this.data;
  41945. /**
  41946. * Index of each item is the same as the raw index of coresponding list item.
  41947. * @private
  41948. * @type {Array.<module:echarts/data/Tree~TreeNode}
  41949. */
  41950. this._nodes = [];
  41951. /**
  41952. * @private
  41953. * @readOnly
  41954. * @type {module:echarts/model/Model}
  41955. */
  41956. this.hostModel = hostModel;
  41957. /**
  41958. * @private
  41959. * @readOnly
  41960. * @type {Array.<module:echarts/model/Model}
  41961. */
  41962. this.levelModels = map(levelOptions || [], function (levelDefine) {
  41963. return new Model(levelDefine, hostModel, hostModel.ecModel);
  41964. });
  41965. this.leavesModel = new Model(leavesOption || {}, hostModel, hostModel.ecModel);
  41966. }
  41967. Tree.prototype = {
  41968. constructor: Tree,
  41969. type: 'tree',
  41970. /**
  41971. * Travel this subtree (include this node).
  41972. * Usage:
  41973. * node.eachNode(function () { ... }); // preorder
  41974. * node.eachNode('preorder', function () { ... }); // preorder
  41975. * node.eachNode('postorder', function () { ... }); // postorder
  41976. * node.eachNode(
  41977. * {order: 'postorder', attr: 'viewChildren'},
  41978. * function () { ... }
  41979. * ); // postorder
  41980. *
  41981. * @param {(Object|string)} options If string, means order.
  41982. * @param {string=} options.order 'preorder' or 'postorder'
  41983. * @param {string=} options.attr 'children' or 'viewChildren'
  41984. * @param {Function} cb
  41985. * @param {Object} [context]
  41986. */
  41987. eachNode: function (options, cb, context) {
  41988. this.root.eachNode(options, cb, context);
  41989. },
  41990. /**
  41991. * @param {number} dataIndex
  41992. * @return {module:echarts/data/Tree~TreeNode}
  41993. */
  41994. getNodeByDataIndex: function (dataIndex) {
  41995. var rawIndex = this.data.getRawIndex(dataIndex);
  41996. return this._nodes[rawIndex];
  41997. },
  41998. /**
  41999. * @param {string} name
  42000. * @return {module:echarts/data/Tree~TreeNode}
  42001. */
  42002. getNodeByName: function (name) {
  42003. return this.root.getNodeByName(name);
  42004. },
  42005. /**
  42006. * Update item available by list,
  42007. * when list has been performed options like 'filterSelf' or 'map'.
  42008. */
  42009. update: function () {
  42010. var data = this.data;
  42011. var nodes = this._nodes;
  42012. for (var i = 0, len = nodes.length; i < len; i++) {
  42013. nodes[i].dataIndex = -1;
  42014. }
  42015. for (var i = 0, len = data.count(); i < len; i++) {
  42016. nodes[data.getRawIndex(i)].dataIndex = i;
  42017. }
  42018. },
  42019. /**
  42020. * Clear all layouts
  42021. */
  42022. clearLayouts: function () {
  42023. this.data.clearItemLayouts();
  42024. }
  42025. };
  42026. /**
  42027. * data node format:
  42028. * {
  42029. * name: ...
  42030. * value: ...
  42031. * children: [
  42032. * {
  42033. * name: ...
  42034. * value: ...
  42035. * children: ...
  42036. * },
  42037. * ...
  42038. * ]
  42039. * }
  42040. *
  42041. * @static
  42042. * @param {Object} dataRoot Root node.
  42043. * @param {module:echarts/model/Model} hostModel
  42044. * @param {Object} treeOptions
  42045. * @param {Array.<Object>} treeOptions.levels
  42046. * @param {Array.<Object>} treeOptions.leaves
  42047. * @return module:echarts/data/Tree
  42048. */
  42049. Tree.createTree = function (dataRoot, hostModel, treeOptions) {
  42050. var tree = new Tree(hostModel, treeOptions.levels, treeOptions.leaves);
  42051. var listData = [];
  42052. var dimMax = 1;
  42053. buildHierarchy(dataRoot);
  42054. function buildHierarchy(dataNode, parentNode) {
  42055. var value = dataNode.value;
  42056. dimMax = Math.max(dimMax, isArray(value) ? value.length : 1);
  42057. listData.push(dataNode);
  42058. var node = new TreeNode(dataNode.name, tree);
  42059. parentNode
  42060. ? addChild(node, parentNode)
  42061. : (tree.root = node);
  42062. tree._nodes.push(node);
  42063. var children = dataNode.children;
  42064. if (children) {
  42065. for (var i = 0; i < children.length; i++) {
  42066. buildHierarchy(children[i], node);
  42067. }
  42068. }
  42069. }
  42070. tree.root.updateDepthAndHeight(0);
  42071. var dimensionsInfo = createDimensions(listData, {
  42072. coordDimensions: ['value'],
  42073. dimensionsCount: dimMax
  42074. });
  42075. var list = new List(dimensionsInfo, hostModel);
  42076. list.initData(listData);
  42077. linkList({
  42078. mainData: list,
  42079. struct: tree,
  42080. structAttr: 'tree'
  42081. });
  42082. tree.update();
  42083. return tree;
  42084. };
  42085. /**
  42086. * It is needed to consider the mess of 'list', 'hostModel' when creating a TreeNote,
  42087. * so this function is not ready and not necessary to be public.
  42088. *
  42089. * @param {(module:echarts/data/Tree~TreeNode|Object)} child
  42090. */
  42091. function addChild(child, node) {
  42092. var children = node.children;
  42093. if (child.parentNode === node) {
  42094. return;
  42095. }
  42096. children.push(child);
  42097. child.parentNode = node;
  42098. }
  42099. /*
  42100. * Licensed to the Apache Software Foundation (ASF) under one
  42101. * or more contributor license agreements. See the NOTICE file
  42102. * distributed with this work for additional information
  42103. * regarding copyright ownership. The ASF licenses this file
  42104. * to you under the Apache License, Version 2.0 (the
  42105. * "License"); you may not use this file except in compliance
  42106. * with the License. You may obtain a copy of the License at
  42107. *
  42108. * http://www.apache.org/licenses/LICENSE-2.0
  42109. *
  42110. * Unless required by applicable law or agreed to in writing,
  42111. * software distributed under the License is distributed on an
  42112. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42113. * KIND, either express or implied. See the License for the
  42114. * specific language governing permissions and limitations
  42115. * under the License.
  42116. */
  42117. /**
  42118. * @file Create data struct and define tree view's series model
  42119. * @author Deqing Li(annong035@gmail.com)
  42120. */
  42121. SeriesModel.extend({
  42122. type: 'series.tree',
  42123. layoutInfo: null,
  42124. // can support the position parameters 'left', 'top','right','bottom', 'width',
  42125. // 'height' in the setOption() with 'merge' mode normal.
  42126. layoutMode: 'box',
  42127. /**
  42128. * Init a tree data structure from data in option series
  42129. * @param {Object} option the object used to config echarts view
  42130. * @return {module:echarts/data/List} storage initial data
  42131. */
  42132. getInitialData: function (option) {
  42133. //create an virtual root
  42134. var root = {name: option.name, children: option.data};
  42135. var leaves = option.leaves || {};
  42136. var treeOption = {};
  42137. treeOption.leaves = leaves;
  42138. var tree = Tree.createTree(root, this, treeOption);
  42139. var treeDepth = 0;
  42140. tree.eachNode('preorder', function (node) {
  42141. if (node.depth > treeDepth) {
  42142. treeDepth = node.depth;
  42143. }
  42144. });
  42145. var expandAndCollapse = option.expandAndCollapse;
  42146. var expandTreeDepth = (expandAndCollapse && option.initialTreeDepth >= 0)
  42147. ? option.initialTreeDepth : treeDepth;
  42148. tree.root.eachNode('preorder', function (node) {
  42149. var item = node.hostTree.data.getRawDataItem(node.dataIndex);
  42150. // Add item.collapsed != null, because users can collapse node original in the series.data.
  42151. node.isExpand = (item && item.collapsed != null)
  42152. ? !item.collapsed
  42153. : node.depth <= expandTreeDepth;
  42154. });
  42155. return tree.data;
  42156. },
  42157. /**
  42158. * Make the configuration 'orient' backward compatibly, with 'horizontal = LR', 'vertical = TB'.
  42159. * @returns {string} orient
  42160. */
  42161. getOrient: function () {
  42162. var orient = this.get('orient');
  42163. if (orient === 'horizontal') {
  42164. orient = 'LR';
  42165. }
  42166. else if (orient === 'vertical') {
  42167. orient = 'TB';
  42168. }
  42169. return orient;
  42170. },
  42171. setZoom: function (zoom) {
  42172. this.option.zoom = zoom;
  42173. },
  42174. setCenter: function (center) {
  42175. this.option.center = center;
  42176. },
  42177. /**
  42178. * @override
  42179. * @param {number} dataIndex
  42180. */
  42181. formatTooltip: function (dataIndex) {
  42182. var tree = this.getData().tree;
  42183. var realRoot = tree.root.children[0];
  42184. var node = tree.getNodeByDataIndex(dataIndex);
  42185. var value = node.getValue();
  42186. var name = node.name;
  42187. while (node && (node !== realRoot)) {
  42188. name = node.parentNode.name + '.' + name;
  42189. node = node.parentNode;
  42190. }
  42191. return encodeHTML(name + (
  42192. (isNaN(value) || value == null) ? '' : ' : ' + value
  42193. ));
  42194. },
  42195. defaultOption: {
  42196. zlevel: 0,
  42197. z: 2,
  42198. coordinateSystem: 'view',
  42199. // the position of the whole view
  42200. left: '12%',
  42201. top: '12%',
  42202. right: '12%',
  42203. bottom: '12%',
  42204. // the layout of the tree, two value can be selected, 'orthogonal' or 'radial'
  42205. layout: 'orthogonal',
  42206. roam: false, // true | false | 'move' | 'scale', see module:component/helper/RoamController.
  42207. // Symbol size scale ratio in roam
  42208. nodeScaleRatio: 0.4,
  42209. // Default on center of graph
  42210. center: null,
  42211. zoom: 1,
  42212. // The orient of orthoginal layout, can be setted to 'LR', 'TB', 'RL', 'BT'.
  42213. // and the backward compatibility configuration 'horizontal = LR', 'vertical = TB'.
  42214. orient: 'LR',
  42215. symbol: 'emptyCircle',
  42216. symbolSize: 7,
  42217. expandAndCollapse: true,
  42218. initialTreeDepth: 2,
  42219. lineStyle: {
  42220. color: '#ccc',
  42221. width: 1.5,
  42222. curveness: 0.5
  42223. },
  42224. itemStyle: {
  42225. color: 'lightsteelblue',
  42226. borderColor: '#c23531',
  42227. borderWidth: 1.5
  42228. },
  42229. label: {
  42230. show: true,
  42231. color: '#555'
  42232. },
  42233. leaves: {
  42234. label: {
  42235. show: true
  42236. }
  42237. },
  42238. animationEasing: 'linear',
  42239. animationDuration: 700,
  42240. animationDurationUpdate: 1000
  42241. }
  42242. });
  42243. /*
  42244. * Licensed to the Apache Software Foundation (ASF) under one
  42245. * or more contributor license agreements. See the NOTICE file
  42246. * distributed with this work for additional information
  42247. * regarding copyright ownership. The ASF licenses this file
  42248. * to you under the Apache License, Version 2.0 (the
  42249. * "License"); you may not use this file except in compliance
  42250. * with the License. You may obtain a copy of the License at
  42251. *
  42252. * http://www.apache.org/licenses/LICENSE-2.0
  42253. *
  42254. * Unless required by applicable law or agreed to in writing,
  42255. * software distributed under the License is distributed on an
  42256. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42257. * KIND, either express or implied. See the License for the
  42258. * specific language governing permissions and limitations
  42259. * under the License.
  42260. */
  42261. /*
  42262. * A third-party license is embeded for some of the code in this file:
  42263. * The tree layoutHelper implementation was originally copied from
  42264. * "d3.js"(https://github.com/d3/d3-hierarchy) with
  42265. * some modifications made for this project.
  42266. * (see more details in the comment of the specific method below.)
  42267. * The use of the source code of this file is also subject to the terms
  42268. * and consitions of the licence of "d3.js" (BSD-3Clause, see
  42269. * </licenses/LICENSE-d3>).
  42270. */
  42271. /**
  42272. * @file The layout algorithm of node-link tree diagrams. Here we using Reingold-Tilford algorithm to drawing
  42273. * the tree.
  42274. */
  42275. /**
  42276. * Initialize all computational message for following algorithm.
  42277. *
  42278. * @param {module:echarts/data/Tree~TreeNode} root The virtual root of the tree.
  42279. */
  42280. function init$2(root) {
  42281. root.hierNode = {
  42282. defaultAncestor: null,
  42283. ancestor: root,
  42284. prelim: 0,
  42285. modifier: 0,
  42286. change: 0,
  42287. shift: 0,
  42288. i: 0,
  42289. thread: null
  42290. };
  42291. var nodes = [root];
  42292. var node;
  42293. var children;
  42294. while (node = nodes.pop()) { // jshint ignore:line
  42295. children = node.children;
  42296. if (node.isExpand && children.length) {
  42297. var n = children.length;
  42298. for (var i = n - 1; i >= 0; i--) {
  42299. var child = children[i];
  42300. child.hierNode = {
  42301. defaultAncestor: null,
  42302. ancestor: child,
  42303. prelim: 0,
  42304. modifier: 0,
  42305. change: 0,
  42306. shift: 0,
  42307. i: i,
  42308. thread: null
  42309. };
  42310. nodes.push(child);
  42311. }
  42312. }
  42313. }
  42314. }
  42315. /**
  42316. * The implementation of this function was originally copied from "d3.js"
  42317. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42318. * with some modifications made for this program.
  42319. * See the license statement at the head of this file.
  42320. *
  42321. * Computes a preliminary x coordinate for node. Before that, this function is
  42322. * applied recursively to the children of node, as well as the function
  42323. * apportion(). After spacing out the children by calling executeShifts(), the
  42324. * node is placed to the midpoint of its outermost children.
  42325. *
  42326. * @param {module:echarts/data/Tree~TreeNode} node
  42327. * @param {Function} separation
  42328. */
  42329. function firstWalk(node, separation) {
  42330. var children = node.isExpand ? node.children : [];
  42331. var siblings = node.parentNode.children;
  42332. var subtreeW = node.hierNode.i ? siblings[node.hierNode.i - 1] : null;
  42333. if (children.length) {
  42334. executeShifts(node);
  42335. var midPoint = (children[0].hierNode.prelim + children[children.length - 1].hierNode.prelim) / 2;
  42336. if (subtreeW) {
  42337. node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
  42338. node.hierNode.modifier = node.hierNode.prelim - midPoint;
  42339. }
  42340. else {
  42341. node.hierNode.prelim = midPoint;
  42342. }
  42343. }
  42344. else if (subtreeW) {
  42345. node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
  42346. }
  42347. node.parentNode.hierNode.defaultAncestor = apportion(
  42348. node,
  42349. subtreeW,
  42350. node.parentNode.hierNode.defaultAncestor || siblings[0],
  42351. separation
  42352. );
  42353. }
  42354. /**
  42355. * The implementation of this function was originally copied from "d3.js"
  42356. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42357. * with some modifications made for this program.
  42358. * See the license statement at the head of this file.
  42359. *
  42360. * Computes all real x-coordinates by summing up the modifiers recursively.
  42361. *
  42362. * @param {module:echarts/data/Tree~TreeNode} node
  42363. */
  42364. function secondWalk(node) {
  42365. var nodeX = node.hierNode.prelim + node.parentNode.hierNode.modifier;
  42366. node.setLayout({x: nodeX}, true);
  42367. node.hierNode.modifier += node.parentNode.hierNode.modifier;
  42368. }
  42369. function separation(cb) {
  42370. return arguments.length ? cb : defaultSeparation;
  42371. }
  42372. /**
  42373. * Transform the common coordinate to radial coordinate.
  42374. *
  42375. * @param {number} x
  42376. * @param {number} y
  42377. * @return {Object}
  42378. */
  42379. function radialCoordinate(x, y) {
  42380. var radialCoor = {};
  42381. x -= Math.PI / 2;
  42382. radialCoor.x = y * Math.cos(x);
  42383. radialCoor.y = y * Math.sin(x);
  42384. return radialCoor;
  42385. }
  42386. /**
  42387. * Get the layout position of the whole view.
  42388. *
  42389. * @param {module:echarts/model/Series} seriesModel the model object of sankey series
  42390. * @param {module:echarts/ExtensionAPI} api provide the API list that the developer can call
  42391. * @return {module:zrender/core/BoundingRect} size of rect to draw the sankey view
  42392. */
  42393. function getViewRect(seriesModel, api) {
  42394. return getLayoutRect(
  42395. seriesModel.getBoxLayoutParams(), {
  42396. width: api.getWidth(),
  42397. height: api.getHeight()
  42398. }
  42399. );
  42400. }
  42401. /**
  42402. * All other shifts, applied to the smaller subtrees between w- and w+, are
  42403. * performed by this function.
  42404. *
  42405. * The implementation of this function was originally copied from "d3.js"
  42406. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42407. * with some modifications made for this program.
  42408. * See the license statement at the head of this file.
  42409. *
  42410. * @param {module:echarts/data/Tree~TreeNode} node
  42411. */
  42412. function executeShifts(node) {
  42413. var children = node.children;
  42414. var n = children.length;
  42415. var shift = 0;
  42416. var change = 0;
  42417. while (--n >= 0) {
  42418. var child = children[n];
  42419. child.hierNode.prelim += shift;
  42420. child.hierNode.modifier += shift;
  42421. change += child.hierNode.change;
  42422. shift += child.hierNode.shift + change;
  42423. }
  42424. }
  42425. /**
  42426. * The implementation of this function was originally copied from "d3.js"
  42427. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42428. * with some modifications made for this program.
  42429. * See the license statement at the head of this file.
  42430. *
  42431. * The core of the algorithm. Here, a new subtree is combined with the
  42432. * previous subtrees. Threads are used to traverse the inside and outside
  42433. * contours of the left and right subtree up to the highest common level.
  42434. * Whenever two nodes of the inside contours conflict, we compute the left
  42435. * one of the greatest uncommon ancestors using the function nextAncestor()
  42436. * and call moveSubtree() to shift the subtree and prepare the shifts of
  42437. * smaller subtrees. Finally, we add a new thread (if necessary).
  42438. *
  42439. * @param {module:echarts/data/Tree~TreeNode} subtreeV
  42440. * @param {module:echarts/data/Tree~TreeNode} subtreeW
  42441. * @param {module:echarts/data/Tree~TreeNode} ancestor
  42442. * @param {Function} separation
  42443. * @return {module:echarts/data/Tree~TreeNode}
  42444. */
  42445. function apportion(subtreeV, subtreeW, ancestor, separation) {
  42446. if (subtreeW) {
  42447. var nodeOutRight = subtreeV;
  42448. var nodeInRight = subtreeV;
  42449. var nodeOutLeft = nodeInRight.parentNode.children[0];
  42450. var nodeInLeft = subtreeW;
  42451. var sumOutRight = nodeOutRight.hierNode.modifier;
  42452. var sumInRight = nodeInRight.hierNode.modifier;
  42453. var sumOutLeft = nodeOutLeft.hierNode.modifier;
  42454. var sumInLeft = nodeInLeft.hierNode.modifier;
  42455. while (nodeInLeft = nextRight(nodeInLeft), nodeInRight = nextLeft(nodeInRight), nodeInLeft && nodeInRight) {
  42456. nodeOutRight = nextRight(nodeOutRight);
  42457. nodeOutLeft = nextLeft(nodeOutLeft);
  42458. nodeOutRight.hierNode.ancestor = subtreeV;
  42459. var shift = nodeInLeft.hierNode.prelim + sumInLeft - nodeInRight.hierNode.prelim
  42460. - sumInRight + separation(nodeInLeft, nodeInRight);
  42461. if (shift > 0) {
  42462. moveSubtree(nextAncestor(nodeInLeft, subtreeV, ancestor), subtreeV, shift);
  42463. sumInRight += shift;
  42464. sumOutRight += shift;
  42465. }
  42466. sumInLeft += nodeInLeft.hierNode.modifier;
  42467. sumInRight += nodeInRight.hierNode.modifier;
  42468. sumOutRight += nodeOutRight.hierNode.modifier;
  42469. sumOutLeft += nodeOutLeft.hierNode.modifier;
  42470. }
  42471. if (nodeInLeft && !nextRight(nodeOutRight)) {
  42472. nodeOutRight.hierNode.thread = nodeInLeft;
  42473. nodeOutRight.hierNode.modifier += sumInLeft - sumOutRight;
  42474. }
  42475. if (nodeInRight && !nextLeft(nodeOutLeft)) {
  42476. nodeOutLeft.hierNode.thread = nodeInRight;
  42477. nodeOutLeft.hierNode.modifier += sumInRight - sumOutLeft;
  42478. ancestor = subtreeV;
  42479. }
  42480. }
  42481. return ancestor;
  42482. }
  42483. /**
  42484. * This function is used to traverse the right contour of a subtree.
  42485. * It returns the rightmost child of node or the thread of node. The function
  42486. * returns null if and only if node is on the highest depth of its subtree.
  42487. *
  42488. * @param {module:echarts/data/Tree~TreeNode} node
  42489. * @return {module:echarts/data/Tree~TreeNode}
  42490. */
  42491. function nextRight(node) {
  42492. var children = node.children;
  42493. return children.length && node.isExpand ? children[children.length - 1] : node.hierNode.thread;
  42494. }
  42495. /**
  42496. * This function is used to traverse the left contour of a subtree (or a subforest).
  42497. * It returns the leftmost child of node or the thread of node. The function
  42498. * returns null if and only if node is on the highest depth of its subtree.
  42499. *
  42500. * @param {module:echarts/data/Tree~TreeNode} node
  42501. * @return {module:echarts/data/Tree~TreeNode}
  42502. */
  42503. function nextLeft(node) {
  42504. var children = node.children;
  42505. return children.length && node.isExpand ? children[0] : node.hierNode.thread;
  42506. }
  42507. /**
  42508. * If nodeInLeft’s ancestor is a sibling of node, returns nodeInLeft’s ancestor.
  42509. * Otherwise, returns the specified ancestor.
  42510. *
  42511. * @param {module:echarts/data/Tree~TreeNode} nodeInLeft
  42512. * @param {module:echarts/data/Tree~TreeNode} node
  42513. * @param {module:echarts/data/Tree~TreeNode} ancestor
  42514. * @return {module:echarts/data/Tree~TreeNode}
  42515. */
  42516. function nextAncestor(nodeInLeft, node, ancestor) {
  42517. return nodeInLeft.hierNode.ancestor.parentNode === node.parentNode
  42518. ? nodeInLeft.hierNode.ancestor : ancestor;
  42519. }
  42520. /**
  42521. * The implementation of this function was originally copied from "d3.js"
  42522. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42523. * with some modifications made for this program.
  42524. * See the license statement at the head of this file.
  42525. *
  42526. * Shifts the current subtree rooted at wr.
  42527. * This is done by increasing prelim(w+) and modifier(w+) by shift.
  42528. *
  42529. * @param {module:echarts/data/Tree~TreeNode} wl
  42530. * @param {module:echarts/data/Tree~TreeNode} wr
  42531. * @param {number} shift [description]
  42532. */
  42533. function moveSubtree(wl, wr, shift) {
  42534. var change = shift / (wr.hierNode.i - wl.hierNode.i);
  42535. wr.hierNode.change -= change;
  42536. wr.hierNode.shift += shift;
  42537. wr.hierNode.modifier += shift;
  42538. wr.hierNode.prelim += shift;
  42539. wl.hierNode.change += change;
  42540. }
  42541. /**
  42542. * The implementation of this function was originally copied from "d3.js"
  42543. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42544. * with some modifications made for this program.
  42545. * See the license statement at the head of this file.
  42546. */
  42547. function defaultSeparation(node1, node2) {
  42548. return node1.parentNode === node2.parentNode ? 1 : 2;
  42549. }
  42550. /*
  42551. * Licensed to the Apache Software Foundation (ASF) under one
  42552. * or more contributor license agreements. See the NOTICE file
  42553. * distributed with this work for additional information
  42554. * regarding copyright ownership. The ASF licenses this file
  42555. * to you under the Apache License, Version 2.0 (the
  42556. * "License"); you may not use this file except in compliance
  42557. * with the License. You may obtain a copy of the License at
  42558. *
  42559. * http://www.apache.org/licenses/LICENSE-2.0
  42560. *
  42561. * Unless required by applicable law or agreed to in writing,
  42562. * software distributed under the License is distributed on an
  42563. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42564. * KIND, either express or implied. See the License for the
  42565. * specific language governing permissions and limitations
  42566. * under the License.
  42567. */
  42568. /**
  42569. * @file This file used to draw tree view.
  42570. * @author Deqing Li(annong035@gmail.com)
  42571. */
  42572. extendChartView({
  42573. type: 'tree',
  42574. /**
  42575. * Init the chart
  42576. * @override
  42577. * @param {module:echarts/model/Global} ecModel
  42578. * @param {module:echarts/ExtensionAPI} api
  42579. */
  42580. init: function (ecModel, api) {
  42581. /**
  42582. * @private
  42583. * @type {module:echarts/data/Tree}
  42584. */
  42585. this._oldTree;
  42586. /**
  42587. * @private
  42588. * @type {module:zrender/container/Group}
  42589. */
  42590. this._mainGroup = new Group();
  42591. /**
  42592. * @private
  42593. * @type {module:echarts/componet/helper/RoamController}
  42594. */
  42595. this._controller = new RoamController(api.getZr());
  42596. this._controllerHost = {target: this.group};
  42597. this.group.add(this._mainGroup);
  42598. },
  42599. render: function (seriesModel, ecModel, api, payload) {
  42600. var data = seriesModel.getData();
  42601. var layoutInfo = seriesModel.layoutInfo;
  42602. var group = this._mainGroup;
  42603. var layout = seriesModel.get('layout');
  42604. if (layout === 'radial') {
  42605. group.attr('position', [layoutInfo.x + layoutInfo.width / 2, layoutInfo.y + layoutInfo.height / 2]);
  42606. }
  42607. else {
  42608. group.attr('position', [layoutInfo.x, layoutInfo.y]);
  42609. }
  42610. this._updateViewCoordSys(seriesModel);
  42611. this._updateController(seriesModel, ecModel, api);
  42612. var oldData = this._data;
  42613. var seriesScope = {
  42614. expandAndCollapse: seriesModel.get('expandAndCollapse'),
  42615. layout: layout,
  42616. orient: seriesModel.getOrient(),
  42617. curvature: seriesModel.get('lineStyle.curveness'),
  42618. symbolRotate: seriesModel.get('symbolRotate'),
  42619. symbolOffset: seriesModel.get('symbolOffset'),
  42620. hoverAnimation: seriesModel.get('hoverAnimation'),
  42621. useNameLabel: true,
  42622. fadeIn: true
  42623. };
  42624. data.diff(oldData)
  42625. .add(function (newIdx) {
  42626. if (symbolNeedsDraw$1(data, newIdx)) {
  42627. // Create node and edge
  42628. updateNode(data, newIdx, null, group, seriesModel, seriesScope);
  42629. }
  42630. })
  42631. .update(function (newIdx, oldIdx) {
  42632. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  42633. if (!symbolNeedsDraw$1(data, newIdx)) {
  42634. symbolEl && removeNode(oldData, oldIdx, symbolEl, group, seriesModel, seriesScope);
  42635. return;
  42636. }
  42637. // Update node and edge
  42638. updateNode(data, newIdx, symbolEl, group, seriesModel, seriesScope);
  42639. })
  42640. .remove(function (oldIdx) {
  42641. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  42642. // When remove a collapsed node of subtree, since the collapsed
  42643. // node haven't been initialized with a symbol element,
  42644. // you can't found it's symbol element through index.
  42645. // so if we want to remove the symbol element we should insure
  42646. // that the symbol element is not null.
  42647. if (symbolEl) {
  42648. removeNode(oldData, oldIdx, symbolEl, group, seriesModel, seriesScope);
  42649. }
  42650. })
  42651. .execute();
  42652. this._nodeScaleRatio = seriesModel.get('nodeScaleRatio');
  42653. this._updateNodeAndLinkScale(seriesModel);
  42654. if (seriesScope.expandAndCollapse === true) {
  42655. data.eachItemGraphicEl(function (el, dataIndex) {
  42656. el.off('click').on('click', function () {
  42657. api.dispatchAction({
  42658. type: 'treeExpandAndCollapse',
  42659. seriesId: seriesModel.id,
  42660. dataIndex: dataIndex
  42661. });
  42662. });
  42663. });
  42664. }
  42665. this._data = data;
  42666. },
  42667. _updateViewCoordSys: function (seriesModel) {
  42668. var data = seriesModel.getData();
  42669. var points = [];
  42670. data.each(function (idx) {
  42671. var layout = data.getItemLayout(idx);
  42672. if (layout && !isNaN(layout.x) && !isNaN(layout.y)) {
  42673. points.push([+layout.x, +layout.y]);
  42674. }
  42675. });
  42676. var min = [];
  42677. var max = [];
  42678. fromPoints(points, min, max);
  42679. // If width or height is 0
  42680. if (max[0] - min[0] === 0) {
  42681. max[0] += 1;
  42682. min[0] -= 1;
  42683. }
  42684. if (max[1] - min[1] === 0) {
  42685. max[1] += 1;
  42686. min[1] -= 1;
  42687. }
  42688. var viewCoordSys = seriesModel.coordinateSystem = new View();
  42689. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  42690. viewCoordSys.setBoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  42691. viewCoordSys.setCenter(seriesModel.get('center'));
  42692. viewCoordSys.setZoom(seriesModel.get('zoom'));
  42693. // Here we use viewCoordSys just for computing the 'position' and 'scale' of the group
  42694. this.group.attr({
  42695. position: viewCoordSys.position,
  42696. scale: viewCoordSys.scale
  42697. });
  42698. this._viewCoordSys = viewCoordSys;
  42699. },
  42700. _updateController: function (seriesModel, ecModel, api) {
  42701. var controller = this._controller;
  42702. var controllerHost = this._controllerHost;
  42703. var group = this.group;
  42704. controller.setPointerChecker(function (e, x, y) {
  42705. var rect = group.getBoundingRect();
  42706. rect.applyTransform(group.transform);
  42707. return rect.contain(x, y)
  42708. && !onIrrelevantElement(e, api, seriesModel);
  42709. });
  42710. controller.enable(seriesModel.get('roam'));
  42711. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  42712. controllerHost.zoom = seriesModel.coordinateSystem.getZoom();
  42713. controller
  42714. .off('pan')
  42715. .off('zoom')
  42716. .on('pan', function (e) {
  42717. updateViewOnPan(controllerHost, e.dx, e.dy);
  42718. api.dispatchAction({
  42719. seriesId: seriesModel.id,
  42720. type: 'treeRoam',
  42721. dx: e.dx,
  42722. dy: e.dy
  42723. });
  42724. }, this)
  42725. .on('zoom', function (e) {
  42726. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  42727. api.dispatchAction({
  42728. seriesId: seriesModel.id,
  42729. type: 'treeRoam',
  42730. zoom: e.scale,
  42731. originX: e.originX,
  42732. originY: e.originY
  42733. });
  42734. this._updateNodeAndLinkScale(seriesModel);
  42735. }, this);
  42736. },
  42737. _updateNodeAndLinkScale: function (seriesModel) {
  42738. var data = seriesModel.getData();
  42739. var nodeScale = this._getNodeGlobalScale(seriesModel);
  42740. var invScale = [nodeScale, nodeScale];
  42741. data.eachItemGraphicEl(function (el, idx) {
  42742. el.attr('scale', invScale);
  42743. });
  42744. },
  42745. _getNodeGlobalScale: function (seriesModel) {
  42746. var coordSys = seriesModel.coordinateSystem;
  42747. if (coordSys.type !== 'view') {
  42748. return 1;
  42749. }
  42750. var nodeScaleRatio = this._nodeScaleRatio;
  42751. var groupScale = coordSys.scale;
  42752. var groupZoom = (groupScale && groupScale[0]) || 1;
  42753. // Scale node when zoom changes
  42754. var roamZoom = coordSys.getZoom();
  42755. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  42756. return nodeScale / groupZoom;
  42757. },
  42758. dispose: function () {
  42759. this._controller && this._controller.dispose();
  42760. this._controllerHost = {};
  42761. },
  42762. remove: function () {
  42763. this._mainGroup.removeAll();
  42764. this._data = null;
  42765. }
  42766. });
  42767. function symbolNeedsDraw$1(data, dataIndex) {
  42768. var layout = data.getItemLayout(dataIndex);
  42769. return layout
  42770. && !isNaN(layout.x) && !isNaN(layout.y)
  42771. && data.getItemVisual(dataIndex, 'symbol') !== 'none';
  42772. }
  42773. function getTreeNodeStyle(node, itemModel, seriesScope) {
  42774. seriesScope.itemModel = itemModel;
  42775. seriesScope.itemStyle = itemModel.getModel('itemStyle').getItemStyle();
  42776. seriesScope.hoverItemStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  42777. seriesScope.lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  42778. seriesScope.labelModel = itemModel.getModel('label');
  42779. seriesScope.hoverLabelModel = itemModel.getModel('emphasis.label');
  42780. if (node.isExpand === false && node.children.length !== 0) {
  42781. seriesScope.symbolInnerColor = seriesScope.itemStyle.fill;
  42782. }
  42783. else {
  42784. seriesScope.symbolInnerColor = '#fff';
  42785. }
  42786. return seriesScope;
  42787. }
  42788. function updateNode(data, dataIndex, symbolEl, group, seriesModel, seriesScope) {
  42789. var isInit = !symbolEl;
  42790. var node = data.tree.getNodeByDataIndex(dataIndex);
  42791. var itemModel = node.getModel();
  42792. var seriesScope = getTreeNodeStyle(node, itemModel, seriesScope);
  42793. var virtualRoot = data.tree.root;
  42794. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  42795. var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
  42796. var sourceLayout = source.getLayout();
  42797. var sourceOldLayout = sourceSymbolEl
  42798. ? {
  42799. x: sourceSymbolEl.position[0],
  42800. y: sourceSymbolEl.position[1],
  42801. rawX: sourceSymbolEl.__radialOldRawX,
  42802. rawY: sourceSymbolEl.__radialOldRawY
  42803. }
  42804. : sourceLayout;
  42805. var targetLayout = node.getLayout();
  42806. if (isInit) {
  42807. symbolEl = new SymbolClz$1(data, dataIndex, seriesScope);
  42808. symbolEl.attr('position', [sourceOldLayout.x, sourceOldLayout.y]);
  42809. }
  42810. else {
  42811. symbolEl.updateData(data, dataIndex, seriesScope);
  42812. }
  42813. symbolEl.__radialOldRawX = symbolEl.__radialRawX;
  42814. symbolEl.__radialOldRawY = symbolEl.__radialRawY;
  42815. symbolEl.__radialRawX = targetLayout.rawX;
  42816. symbolEl.__radialRawY = targetLayout.rawY;
  42817. group.add(symbolEl);
  42818. data.setItemGraphicEl(dataIndex, symbolEl);
  42819. updateProps(symbolEl, {
  42820. position: [targetLayout.x, targetLayout.y]
  42821. }, seriesModel);
  42822. var symbolPath = symbolEl.getSymbolPath();
  42823. if (seriesScope.layout === 'radial') {
  42824. var realRoot = virtualRoot.children[0];
  42825. var rootLayout = realRoot.getLayout();
  42826. var length = realRoot.children.length;
  42827. var rad;
  42828. var isLeft;
  42829. if (targetLayout.x === rootLayout.x && node.isExpand === true) {
  42830. var center = {};
  42831. center.x = (realRoot.children[0].getLayout().x + realRoot.children[length - 1].getLayout().x) / 2;
  42832. center.y = (realRoot.children[0].getLayout().y + realRoot.children[length - 1].getLayout().y) / 2;
  42833. rad = Math.atan2(center.y - rootLayout.y, center.x - rootLayout.x);
  42834. if (rad < 0) {
  42835. rad = Math.PI * 2 + rad;
  42836. }
  42837. isLeft = center.x < rootLayout.x;
  42838. if (isLeft) {
  42839. rad = rad - Math.PI;
  42840. }
  42841. }
  42842. else {
  42843. rad = Math.atan2(targetLayout.y - rootLayout.y, targetLayout.x - rootLayout.x);
  42844. if (rad < 0) {
  42845. rad = Math.PI * 2 + rad;
  42846. }
  42847. if (node.children.length === 0 || (node.children.length !== 0 && node.isExpand === false)) {
  42848. isLeft = targetLayout.x < rootLayout.x;
  42849. if (isLeft) {
  42850. rad = rad - Math.PI;
  42851. }
  42852. }
  42853. else {
  42854. isLeft = targetLayout.x > rootLayout.x;
  42855. if (!isLeft) {
  42856. rad = rad - Math.PI;
  42857. }
  42858. }
  42859. }
  42860. var textPosition = isLeft ? 'left' : 'right';
  42861. symbolPath.setStyle({
  42862. textPosition: textPosition,
  42863. textRotation: -rad,
  42864. textOrigin: 'center',
  42865. verticalAlign: 'middle'
  42866. });
  42867. }
  42868. if (node.parentNode && node.parentNode !== virtualRoot) {
  42869. var edge = symbolEl.__edge;
  42870. if (!edge) {
  42871. edge = symbolEl.__edge = new BezierCurve({
  42872. shape: getEdgeShape(seriesScope, sourceOldLayout, sourceOldLayout),
  42873. style: defaults({opacity: 0, strokeNoScale: true}, seriesScope.lineStyle)
  42874. });
  42875. }
  42876. updateProps(edge, {
  42877. shape: getEdgeShape(seriesScope, sourceLayout, targetLayout),
  42878. style: {opacity: 1}
  42879. }, seriesModel);
  42880. group.add(edge);
  42881. }
  42882. }
  42883. function removeNode(data, dataIndex, symbolEl, group, seriesModel, seriesScope) {
  42884. var node = data.tree.getNodeByDataIndex(dataIndex);
  42885. var virtualRoot = data.tree.root;
  42886. var itemModel = node.getModel();
  42887. var seriesScope = getTreeNodeStyle(node, itemModel, seriesScope);
  42888. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  42889. var sourceLayout;
  42890. while (sourceLayout = source.getLayout(), sourceLayout == null) {
  42891. source = source.parentNode === virtualRoot ? source : source.parentNode || source;
  42892. }
  42893. updateProps(symbolEl, {
  42894. position: [sourceLayout.x + 1, sourceLayout.y + 1]
  42895. }, seriesModel, function () {
  42896. group.remove(symbolEl);
  42897. data.setItemGraphicEl(dataIndex, null);
  42898. });
  42899. symbolEl.fadeOut(null, {keepLabel: true});
  42900. var edge = symbolEl.__edge;
  42901. if (edge) {
  42902. updateProps(edge, {
  42903. shape: getEdgeShape(seriesScope, sourceLayout, sourceLayout),
  42904. style: {
  42905. opacity: 0
  42906. }
  42907. }, seriesModel, function () {
  42908. group.remove(edge);
  42909. });
  42910. }
  42911. }
  42912. function getEdgeShape(seriesScope, sourceLayout, targetLayout) {
  42913. var cpx1;
  42914. var cpy1;
  42915. var cpx2;
  42916. var cpy2;
  42917. var orient = seriesScope.orient;
  42918. var x1;
  42919. var x2;
  42920. var y1;
  42921. var y2;
  42922. if (seriesScope.layout === 'radial') {
  42923. x1 = sourceLayout.rawX;
  42924. y1 = sourceLayout.rawY;
  42925. x2 = targetLayout.rawX;
  42926. y2 = targetLayout.rawY;
  42927. var radialCoor1 = radialCoordinate(x1, y1);
  42928. var radialCoor2 = radialCoordinate(x1, y1 + (y2 - y1) * seriesScope.curvature);
  42929. var radialCoor3 = radialCoordinate(x2, y2 + (y1 - y2) * seriesScope.curvature);
  42930. var radialCoor4 = radialCoordinate(x2, y2);
  42931. return {
  42932. x1: radialCoor1.x,
  42933. y1: radialCoor1.y,
  42934. x2: radialCoor4.x,
  42935. y2: radialCoor4.y,
  42936. cpx1: radialCoor2.x,
  42937. cpy1: radialCoor2.y,
  42938. cpx2: radialCoor3.x,
  42939. cpy2: radialCoor3.y
  42940. };
  42941. }
  42942. else {
  42943. x1 = sourceLayout.x;
  42944. y1 = sourceLayout.y;
  42945. x2 = targetLayout.x;
  42946. y2 = targetLayout.y;
  42947. if (orient === 'LR' || orient === 'RL') {
  42948. cpx1 = x1 + (x2 - x1) * seriesScope.curvature;
  42949. cpy1 = y1;
  42950. cpx2 = x2 + (x1 - x2) * seriesScope.curvature;
  42951. cpy2 = y2;
  42952. }
  42953. if (orient === 'TB' || orient === 'BT') {
  42954. cpx1 = x1;
  42955. cpy1 = y1 + (y2 - y1) * seriesScope.curvature;
  42956. cpx2 = x2;
  42957. cpy2 = y2 + (y1 - y2) * seriesScope.curvature;
  42958. }
  42959. }
  42960. return {
  42961. x1: x1,
  42962. y1: y1,
  42963. x2: x2,
  42964. y2: y2,
  42965. cpx1: cpx1,
  42966. cpy1: cpy1,
  42967. cpx2: cpx2,
  42968. cpy2: cpy2
  42969. };
  42970. }
  42971. /*
  42972. * Licensed to the Apache Software Foundation (ASF) under one
  42973. * or more contributor license agreements. See the NOTICE file
  42974. * distributed with this work for additional information
  42975. * regarding copyright ownership. The ASF licenses this file
  42976. * to you under the Apache License, Version 2.0 (the
  42977. * "License"); you may not use this file except in compliance
  42978. * with the License. You may obtain a copy of the License at
  42979. *
  42980. * http://www.apache.org/licenses/LICENSE-2.0
  42981. *
  42982. * Unless required by applicable law or agreed to in writing,
  42983. * software distributed under the License is distributed on an
  42984. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42985. * KIND, either express or implied. See the License for the
  42986. * specific language governing permissions and limitations
  42987. * under the License.
  42988. */
  42989. /**
  42990. * @file Register the actions of the tree
  42991. * @author Deqing Li(annong035@gmail.com)
  42992. */
  42993. registerAction({
  42994. type: 'treeExpandAndCollapse',
  42995. event: 'treeExpandAndCollapse',
  42996. update: 'update'
  42997. }, function (payload, ecModel) {
  42998. ecModel.eachComponent({mainType: 'series', subType: 'tree', query: payload}, function (seriesModel) {
  42999. var dataIndex = payload.dataIndex;
  43000. var tree = seriesModel.getData().tree;
  43001. var node = tree.getNodeByDataIndex(dataIndex);
  43002. node.isExpand = !node.isExpand;
  43003. });
  43004. });
  43005. registerAction({
  43006. type: 'treeRoam',
  43007. event: 'treeRoam',
  43008. // Here we set 'none' instead of 'update', because roam action
  43009. // just need to update the transform matrix without having to recalculate
  43010. // the layout. So don't need to go through the whole update process, such
  43011. // as 'dataPrcocess', 'coordSystemUpdate', 'layout' and so on.
  43012. update: 'none'
  43013. }, function (payload, ecModel) {
  43014. ecModel.eachComponent({mainType: 'series', subType: 'tree', query: payload}, function (seriesModel) {
  43015. var coordSys = seriesModel.coordinateSystem;
  43016. var res = updateCenterAndZoom(coordSys, payload);
  43017. seriesModel.setCenter
  43018. && seriesModel.setCenter(res.center);
  43019. seriesModel.setZoom
  43020. && seriesModel.setZoom(res.zoom);
  43021. });
  43022. });
  43023. /*
  43024. * Licensed to the Apache Software Foundation (ASF) under one
  43025. * or more contributor license agreements. See the NOTICE file
  43026. * distributed with this work for additional information
  43027. * regarding copyright ownership. The ASF licenses this file
  43028. * to you under the Apache License, Version 2.0 (the
  43029. * "License"); you may not use this file except in compliance
  43030. * with the License. You may obtain a copy of the License at
  43031. *
  43032. * http://www.apache.org/licenses/LICENSE-2.0
  43033. *
  43034. * Unless required by applicable law or agreed to in writing,
  43035. * software distributed under the License is distributed on an
  43036. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43037. * KIND, either express or implied. See the License for the
  43038. * specific language governing permissions and limitations
  43039. * under the License.
  43040. */
  43041. /**
  43042. * Traverse the tree from bottom to top and do something
  43043. * @param {module:echarts/data/Tree~TreeNode} root The real root of the tree
  43044. * @param {Function} callback
  43045. */
  43046. function eachAfter(root, callback, separation) {
  43047. var nodes = [root];
  43048. var next = [];
  43049. var node;
  43050. while (node = nodes.pop()) { // jshint ignore:line
  43051. next.push(node);
  43052. if (node.isExpand) {
  43053. var children = node.children;
  43054. if (children.length) {
  43055. for (var i = 0; i < children.length; i++) {
  43056. nodes.push(children[i]);
  43057. }
  43058. }
  43059. }
  43060. }
  43061. while (node = next.pop()) { // jshint ignore:line
  43062. callback(node, separation);
  43063. }
  43064. }
  43065. /**
  43066. * Traverse the tree from top to bottom and do something
  43067. * @param {module:echarts/data/Tree~TreeNode} root The real root of the tree
  43068. * @param {Function} callback
  43069. */
  43070. function eachBefore(root, callback) {
  43071. var nodes = [root];
  43072. var node;
  43073. while (node = nodes.pop()) { // jshint ignore:line
  43074. callback(node);
  43075. if (node.isExpand) {
  43076. var children = node.children;
  43077. if (children.length) {
  43078. for (var i = children.length - 1; i >= 0; i--) {
  43079. nodes.push(children[i]);
  43080. }
  43081. }
  43082. }
  43083. }
  43084. }
  43085. /*
  43086. * Licensed to the Apache Software Foundation (ASF) under one
  43087. * or more contributor license agreements. See the NOTICE file
  43088. * distributed with this work for additional information
  43089. * regarding copyright ownership. The ASF licenses this file
  43090. * to you under the Apache License, Version 2.0 (the
  43091. * "License"); you may not use this file except in compliance
  43092. * with the License. You may obtain a copy of the License at
  43093. *
  43094. * http://www.apache.org/licenses/LICENSE-2.0
  43095. *
  43096. * Unless required by applicable law or agreed to in writing,
  43097. * software distributed under the License is distributed on an
  43098. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43099. * KIND, either express or implied. See the License for the
  43100. * specific language governing permissions and limitations
  43101. * under the License.
  43102. */
  43103. var treeLayout = function (ecModel, api) {
  43104. ecModel.eachSeriesByType('tree', function (seriesModel) {
  43105. commonLayout(seriesModel, api);
  43106. });
  43107. };
  43108. function commonLayout(seriesModel, api) {
  43109. var layoutInfo = getViewRect(seriesModel, api);
  43110. seriesModel.layoutInfo = layoutInfo;
  43111. var layout = seriesModel.get('layout');
  43112. var width = 0;
  43113. var height = 0;
  43114. var separation$$1 = null;
  43115. if (layout === 'radial') {
  43116. width = 2 * Math.PI;
  43117. height = Math.min(layoutInfo.height, layoutInfo.width) / 2;
  43118. separation$$1 = separation(function (node1, node2) {
  43119. return (node1.parentNode === node2.parentNode ? 1 : 2) / node1.depth;
  43120. });
  43121. }
  43122. else {
  43123. width = layoutInfo.width;
  43124. height = layoutInfo.height;
  43125. separation$$1 = separation();
  43126. }
  43127. var virtualRoot = seriesModel.getData().tree.root;
  43128. var realRoot = virtualRoot.children[0];
  43129. if (realRoot) {
  43130. init$2(virtualRoot);
  43131. eachAfter(realRoot, firstWalk, separation$$1);
  43132. virtualRoot.hierNode.modifier = -realRoot.hierNode.prelim;
  43133. eachBefore(realRoot, secondWalk);
  43134. var left = realRoot;
  43135. var right = realRoot;
  43136. var bottom = realRoot;
  43137. eachBefore(realRoot, function (node) {
  43138. var x = node.getLayout().x;
  43139. if (x < left.getLayout().x) {
  43140. left = node;
  43141. }
  43142. if (x > right.getLayout().x) {
  43143. right = node;
  43144. }
  43145. if (node.depth > bottom.depth) {
  43146. bottom = node;
  43147. }
  43148. });
  43149. var delta = left === right ? 1 : separation$$1(left, right) / 2;
  43150. var tx = delta - left.getLayout().x;
  43151. var kx = 0;
  43152. var ky = 0;
  43153. var coorX = 0;
  43154. var coorY = 0;
  43155. if (layout === 'radial') {
  43156. kx = width / (right.getLayout().x + delta + tx);
  43157. // here we use (node.depth - 1), bucause the real root's depth is 1
  43158. ky = height / ((bottom.depth - 1) || 1);
  43159. eachBefore(realRoot, function (node) {
  43160. coorX = (node.getLayout().x + tx) * kx;
  43161. coorY = (node.depth - 1) * ky;
  43162. var finalCoor = radialCoordinate(coorX, coorY);
  43163. node.setLayout({x: finalCoor.x, y: finalCoor.y, rawX: coorX, rawY: coorY}, true);
  43164. });
  43165. }
  43166. else {
  43167. var orient = seriesModel.getOrient();
  43168. if (orient === 'RL' || orient === 'LR') {
  43169. ky = height / (right.getLayout().x + delta + tx);
  43170. kx = width / ((bottom.depth - 1) || 1);
  43171. eachBefore(realRoot, function (node) {
  43172. coorY = (node.getLayout().x + tx) * ky;
  43173. coorX = orient === 'LR'
  43174. ? (node.depth - 1) * kx
  43175. : width - (node.depth - 1) * kx;
  43176. node.setLayout({x: coorX, y: coorY}, true);
  43177. });
  43178. }
  43179. else if (orient === 'TB' || orient === 'BT') {
  43180. kx = width / (right.getLayout().x + delta + tx);
  43181. ky = height / ((bottom.depth - 1) || 1);
  43182. eachBefore(realRoot, function (node) {
  43183. coorX = (node.getLayout().x + tx) * kx;
  43184. coorY = orient === 'TB'
  43185. ? (node.depth - 1) * ky
  43186. : height - (node.depth - 1) * ky;
  43187. node.setLayout({x: coorX, y: coorY}, true);
  43188. });
  43189. }
  43190. }
  43191. }
  43192. }
  43193. /*
  43194. * Licensed to the Apache Software Foundation (ASF) under one
  43195. * or more contributor license agreements. See the NOTICE file
  43196. * distributed with this work for additional information
  43197. * regarding copyright ownership. The ASF licenses this file
  43198. * to you under the Apache License, Version 2.0 (the
  43199. * "License"); you may not use this file except in compliance
  43200. * with the License. You may obtain a copy of the License at
  43201. *
  43202. * http://www.apache.org/licenses/LICENSE-2.0
  43203. *
  43204. * Unless required by applicable law or agreed to in writing,
  43205. * software distributed under the License is distributed on an
  43206. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43207. * KIND, either express or implied. See the License for the
  43208. * specific language governing permissions and limitations
  43209. * under the License.
  43210. */
  43211. registerVisual(visualSymbol('tree', 'circle'));
  43212. registerLayout(treeLayout);
  43213. /*
  43214. * Licensed to the Apache Software Foundation (ASF) under one
  43215. * or more contributor license agreements. See the NOTICE file
  43216. * distributed with this work for additional information
  43217. * regarding copyright ownership. The ASF licenses this file
  43218. * to you under the Apache License, Version 2.0 (the
  43219. * "License"); you may not use this file except in compliance
  43220. * with the License. You may obtain a copy of the License at
  43221. *
  43222. * http://www.apache.org/licenses/LICENSE-2.0
  43223. *
  43224. * Unless required by applicable law or agreed to in writing,
  43225. * software distributed under the License is distributed on an
  43226. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43227. * KIND, either express or implied. See the License for the
  43228. * specific language governing permissions and limitations
  43229. * under the License.
  43230. */
  43231. function retrieveTargetInfo(payload, validPayloadTypes, seriesModel) {
  43232. if (payload && indexOf(validPayloadTypes, payload.type) >= 0) {
  43233. var root = seriesModel.getData().tree.root;
  43234. var targetNode = payload.targetNode;
  43235. if (typeof targetNode === 'string') {
  43236. targetNode = root.getNodeById(targetNode);
  43237. }
  43238. if (targetNode && root.contains(targetNode)) {
  43239. return {node: targetNode};
  43240. }
  43241. var targetNodeId = payload.targetNodeId;
  43242. if (targetNodeId != null && (targetNode = root.getNodeById(targetNodeId))) {
  43243. return {node: targetNode};
  43244. }
  43245. }
  43246. }
  43247. // Not includes the given node at the last item.
  43248. function getPathToRoot(node) {
  43249. var path = [];
  43250. while (node) {
  43251. node = node.parentNode;
  43252. node && path.push(node);
  43253. }
  43254. return path.reverse();
  43255. }
  43256. function aboveViewRoot(viewRoot, node) {
  43257. var viewPath = getPathToRoot(viewRoot);
  43258. return indexOf(viewPath, node) >= 0;
  43259. }
  43260. // From root to the input node (the input node will be included).
  43261. function wrapTreePathInfo(node, seriesModel) {
  43262. var treePathInfo = [];
  43263. while (node) {
  43264. var nodeDataIndex = node.dataIndex;
  43265. treePathInfo.push({
  43266. name: node.name,
  43267. dataIndex: nodeDataIndex,
  43268. value: seriesModel.getRawValue(nodeDataIndex)
  43269. });
  43270. node = node.parentNode;
  43271. }
  43272. treePathInfo.reverse();
  43273. return treePathInfo;
  43274. }
  43275. /*
  43276. * Licensed to the Apache Software Foundation (ASF) under one
  43277. * or more contributor license agreements. See the NOTICE file
  43278. * distributed with this work for additional information
  43279. * regarding copyright ownership. The ASF licenses this file
  43280. * to you under the Apache License, Version 2.0 (the
  43281. * "License"); you may not use this file except in compliance
  43282. * with the License. You may obtain a copy of the License at
  43283. *
  43284. * http://www.apache.org/licenses/LICENSE-2.0
  43285. *
  43286. * Unless required by applicable law or agreed to in writing,
  43287. * software distributed under the License is distributed on an
  43288. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43289. * KIND, either express or implied. See the License for the
  43290. * specific language governing permissions and limitations
  43291. * under the License.
  43292. */
  43293. SeriesModel.extend({
  43294. type: 'series.treemap',
  43295. layoutMode: 'box',
  43296. dependencies: ['grid', 'polar'],
  43297. /**
  43298. * @type {module:echarts/data/Tree~Node}
  43299. */
  43300. _viewRoot: null,
  43301. defaultOption: {
  43302. // Disable progressive rendering
  43303. progressive: 0,
  43304. hoverLayerThreshold: Infinity,
  43305. // center: ['50%', '50%'], // not supported in ec3.
  43306. // size: ['80%', '80%'], // deprecated, compatible with ec2.
  43307. left: 'center',
  43308. top: 'middle',
  43309. right: null,
  43310. bottom: null,
  43311. width: '80%',
  43312. height: '80%',
  43313. sort: true, // Can be null or false or true
  43314. // (order by desc default, asc not supported yet (strange effect))
  43315. clipWindow: 'origin', // Size of clipped window when zooming. 'origin' or 'fullscreen'
  43316. squareRatio: 0.5 * (1 + Math.sqrt(5)), // golden ratio
  43317. leafDepth: null, // Nodes on depth from root are regarded as leaves.
  43318. // Count from zero (zero represents only view root).
  43319. drillDownIcon: '▶', // Use html character temporarily because it is complicated
  43320. // to align specialized icon. ▷▶❒❐▼✚
  43321. zoomToNodeRatio: 0.32 * 0.32, // Be effective when using zoomToNode. Specify the proportion of the
  43322. // target node area in the view area.
  43323. roam: true, // true, false, 'scale' or 'zoom', 'move'.
  43324. nodeClick: 'zoomToNode', // Leaf node click behaviour: 'zoomToNode', 'link', false.
  43325. // If leafDepth is set and clicking a node which has children but
  43326. // be on left depth, the behaviour would be changing root. Otherwise
  43327. // use behavious defined above.
  43328. animation: true,
  43329. animationDurationUpdate: 900,
  43330. animationEasing: 'quinticInOut',
  43331. breadcrumb: {
  43332. show: true,
  43333. height: 22,
  43334. left: 'center',
  43335. top: 'bottom',
  43336. // right
  43337. // bottom
  43338. emptyItemWidth: 25, // Width of empty node.
  43339. itemStyle: {
  43340. color: 'rgba(0,0,0,0.7)', //'#5793f3',
  43341. borderColor: 'rgba(255,255,255,0.7)',
  43342. borderWidth: 1,
  43343. shadowColor: 'rgba(150,150,150,1)',
  43344. shadowBlur: 3,
  43345. shadowOffsetX: 0,
  43346. shadowOffsetY: 0,
  43347. textStyle: {
  43348. color: '#fff'
  43349. }
  43350. },
  43351. emphasis: {
  43352. textStyle: {}
  43353. }
  43354. },
  43355. label: {
  43356. show: true,
  43357. // Do not use textDistance, for ellipsis rect just the same as treemap node rect.
  43358. distance: 0,
  43359. padding: 5,
  43360. position: 'inside', // Can be [5, '5%'] or position stirng like 'insideTopLeft', ...
  43361. // formatter: null,
  43362. color: '#fff',
  43363. ellipsis: true
  43364. // align
  43365. // verticalAlign
  43366. },
  43367. upperLabel: { // Label when node is parent.
  43368. show: false,
  43369. position: [0, '50%'],
  43370. height: 20,
  43371. // formatter: null,
  43372. color: '#fff',
  43373. ellipsis: true,
  43374. // align: null,
  43375. verticalAlign: 'middle'
  43376. },
  43377. itemStyle: {
  43378. color: null, // Can be 'none' if not necessary.
  43379. colorAlpha: null, // Can be 'none' if not necessary.
  43380. colorSaturation: null, // Can be 'none' if not necessary.
  43381. borderWidth: 0,
  43382. gapWidth: 0,
  43383. borderColor: '#fff',
  43384. borderColorSaturation: null // If specified, borderColor will be ineffective, and the
  43385. // border color is evaluated by color of current node and
  43386. // borderColorSaturation.
  43387. },
  43388. emphasis: {
  43389. upperLabel: {
  43390. show: true,
  43391. position: [0, '50%'],
  43392. color: '#fff',
  43393. ellipsis: true,
  43394. verticalAlign: 'middle'
  43395. }
  43396. },
  43397. visualDimension: 0, // Can be 0, 1, 2, 3.
  43398. visualMin: null,
  43399. visualMax: null,
  43400. color: [], // + treemapSeries.color should not be modified. Please only modified
  43401. // level[n].color (if necessary).
  43402. // + Specify color list of each level. level[0].color would be global
  43403. // color list if not specified. (see method `setDefault`).
  43404. // + But set as a empty array to forbid fetch color from global palette
  43405. // when using nodeModel.get('color'), otherwise nodes on deep level
  43406. // will always has color palette set and are not able to inherit color
  43407. // from parent node.
  43408. // + TreemapSeries.color can not be set as 'none', otherwise effect
  43409. // legend color fetching (see seriesColor.js).
  43410. colorAlpha: null, // Array. Specify color alpha range of each level, like [0.2, 0.8]
  43411. colorSaturation: null, // Array. Specify color saturation of each level, like [0.2, 0.5]
  43412. colorMappingBy: 'index', // 'value' or 'index' or 'id'.
  43413. visibleMin: 10, // If area less than this threshold (unit: pixel^2), node will not
  43414. // be rendered. Only works when sort is 'asc' or 'desc'.
  43415. childrenVisibleMin: null, // If area of a node less than this threshold (unit: pixel^2),
  43416. // grandchildren will not show.
  43417. // Why grandchildren? If not grandchildren but children,
  43418. // some siblings show children and some not,
  43419. // the appearance may be mess and not consistent,
  43420. levels: [] // Each item: {
  43421. // visibleMin, itemStyle, visualDimension, label
  43422. // }
  43423. // data: {
  43424. // value: [],
  43425. // children: [],
  43426. // link: 'http://xxx.xxx.xxx',
  43427. // target: 'blank' or 'self'
  43428. // }
  43429. },
  43430. /**
  43431. * @override
  43432. */
  43433. getInitialData: function (option, ecModel) {
  43434. // Create a virtual root.
  43435. var root = {name: option.name, children: option.data};
  43436. completeTreeValue(root);
  43437. var levels = option.levels || [];
  43438. levels = option.levels = setDefault(levels, ecModel);
  43439. var treeOption = {};
  43440. treeOption.levels = levels;
  43441. // Make sure always a new tree is created when setOption,
  43442. // in TreemapView, we check whether oldTree === newTree
  43443. // to choose mappings approach among old shapes and new shapes.
  43444. return Tree.createTree(root, this, treeOption).data;
  43445. },
  43446. optionUpdated: function () {
  43447. this.resetViewRoot();
  43448. },
  43449. /**
  43450. * @override
  43451. * @param {number} dataIndex
  43452. * @param {boolean} [mutipleSeries=false]
  43453. */
  43454. formatTooltip: function (dataIndex) {
  43455. var data = this.getData();
  43456. var value = this.getRawValue(dataIndex);
  43457. var formattedValue = isArray(value)
  43458. ? addCommas(value[0]) : addCommas(value);
  43459. var name = data.getName(dataIndex);
  43460. return encodeHTML(name + ': ' + formattedValue);
  43461. },
  43462. /**
  43463. * Add tree path to tooltip param
  43464. *
  43465. * @override
  43466. * @param {number} dataIndex
  43467. * @return {Object}
  43468. */
  43469. getDataParams: function (dataIndex) {
  43470. var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
  43471. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  43472. params.treePathInfo = wrapTreePathInfo(node, this);
  43473. return params;
  43474. },
  43475. /**
  43476. * @public
  43477. * @param {Object} layoutInfo {
  43478. * x: containerGroup x
  43479. * y: containerGroup y
  43480. * width: containerGroup width
  43481. * height: containerGroup height
  43482. * }
  43483. */
  43484. setLayoutInfo: function (layoutInfo) {
  43485. /**
  43486. * @readOnly
  43487. * @type {Object}
  43488. */
  43489. this.layoutInfo = this.layoutInfo || {};
  43490. extend(this.layoutInfo, layoutInfo);
  43491. },
  43492. /**
  43493. * @param {string} id
  43494. * @return {number} index
  43495. */
  43496. mapIdToIndex: function (id) {
  43497. // A feature is implemented:
  43498. // index is monotone increasing with the sequence of
  43499. // input id at the first time.
  43500. // This feature can make sure that each data item and its
  43501. // mapped color have the same index between data list and
  43502. // color list at the beginning, which is useful for user
  43503. // to adjust data-color mapping.
  43504. /**
  43505. * @private
  43506. * @type {Object}
  43507. */
  43508. var idIndexMap = this._idIndexMap;
  43509. if (!idIndexMap) {
  43510. idIndexMap = this._idIndexMap = createHashMap();
  43511. /**
  43512. * @private
  43513. * @type {number}
  43514. */
  43515. this._idIndexMapCount = 0;
  43516. }
  43517. var index = idIndexMap.get(id);
  43518. if (index == null) {
  43519. idIndexMap.set(id, index = this._idIndexMapCount++);
  43520. }
  43521. return index;
  43522. },
  43523. getViewRoot: function () {
  43524. return this._viewRoot;
  43525. },
  43526. /**
  43527. * @param {module:echarts/data/Tree~Node} [viewRoot]
  43528. */
  43529. resetViewRoot: function (viewRoot) {
  43530. viewRoot
  43531. ? (this._viewRoot = viewRoot)
  43532. : (viewRoot = this._viewRoot);
  43533. var root = this.getRawData().tree.root;
  43534. if (!viewRoot
  43535. || (viewRoot !== root && !root.contains(viewRoot))
  43536. ) {
  43537. this._viewRoot = root;
  43538. }
  43539. }
  43540. });
  43541. /**
  43542. * @param {Object} dataNode
  43543. */
  43544. function completeTreeValue(dataNode) {
  43545. // Postorder travel tree.
  43546. // If value of none-leaf node is not set,
  43547. // calculate it by suming up the value of all children.
  43548. var sum = 0;
  43549. each$1(dataNode.children, function (child) {
  43550. completeTreeValue(child);
  43551. var childValue = child.value;
  43552. isArray(childValue) && (childValue = childValue[0]);
  43553. sum += childValue;
  43554. });
  43555. var thisValue = dataNode.value;
  43556. if (isArray(thisValue)) {
  43557. thisValue = thisValue[0];
  43558. }
  43559. if (thisValue == null || isNaN(thisValue)) {
  43560. thisValue = sum;
  43561. }
  43562. // Value should not less than 0.
  43563. if (thisValue < 0) {
  43564. thisValue = 0;
  43565. }
  43566. isArray(dataNode.value)
  43567. ? (dataNode.value[0] = thisValue)
  43568. : (dataNode.value = thisValue);
  43569. }
  43570. /**
  43571. * set default to level configuration
  43572. */
  43573. function setDefault(levels, ecModel) {
  43574. var globalColorList = ecModel.get('color');
  43575. if (!globalColorList) {
  43576. return;
  43577. }
  43578. levels = levels || [];
  43579. var hasColorDefine;
  43580. each$1(levels, function (levelDefine) {
  43581. var model = new Model(levelDefine);
  43582. var modelColor = model.get('color');
  43583. if (model.get('itemStyle.color')
  43584. || (modelColor && modelColor !== 'none')
  43585. ) {
  43586. hasColorDefine = true;
  43587. }
  43588. });
  43589. if (!hasColorDefine) {
  43590. var level0 = levels[0] || (levels[0] = {});
  43591. level0.color = globalColorList.slice();
  43592. }
  43593. return levels;
  43594. }
  43595. /*
  43596. * Licensed to the Apache Software Foundation (ASF) under one
  43597. * or more contributor license agreements. See the NOTICE file
  43598. * distributed with this work for additional information
  43599. * regarding copyright ownership. The ASF licenses this file
  43600. * to you under the Apache License, Version 2.0 (the
  43601. * "License"); you may not use this file except in compliance
  43602. * with the License. You may obtain a copy of the License at
  43603. *
  43604. * http://www.apache.org/licenses/LICENSE-2.0
  43605. *
  43606. * Unless required by applicable law or agreed to in writing,
  43607. * software distributed under the License is distributed on an
  43608. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43609. * KIND, either express or implied. See the License for the
  43610. * specific language governing permissions and limitations
  43611. * under the License.
  43612. */
  43613. var TEXT_PADDING = 8;
  43614. var ITEM_GAP = 8;
  43615. var ARRAY_LENGTH = 5;
  43616. function Breadcrumb(containerGroup) {
  43617. /**
  43618. * @private
  43619. * @type {module:zrender/container/Group}
  43620. */
  43621. this.group = new Group();
  43622. containerGroup.add(this.group);
  43623. }
  43624. Breadcrumb.prototype = {
  43625. constructor: Breadcrumb,
  43626. render: function (seriesModel, api, targetNode, onSelect) {
  43627. var model = seriesModel.getModel('breadcrumb');
  43628. var thisGroup = this.group;
  43629. thisGroup.removeAll();
  43630. if (!model.get('show') || !targetNode) {
  43631. return;
  43632. }
  43633. var normalStyleModel = model.getModel('itemStyle');
  43634. // var emphasisStyleModel = model.getModel('emphasis.itemStyle');
  43635. var textStyleModel = normalStyleModel.getModel('textStyle');
  43636. var layoutParam = {
  43637. pos: {
  43638. left: model.get('left'),
  43639. right: model.get('right'),
  43640. top: model.get('top'),
  43641. bottom: model.get('bottom')
  43642. },
  43643. box: {
  43644. width: api.getWidth(),
  43645. height: api.getHeight()
  43646. },
  43647. emptyItemWidth: model.get('emptyItemWidth'),
  43648. totalWidth: 0,
  43649. renderList: []
  43650. };
  43651. this._prepare(targetNode, layoutParam, textStyleModel);
  43652. this._renderContent(seriesModel, layoutParam, normalStyleModel, textStyleModel, onSelect);
  43653. positionElement(thisGroup, layoutParam.pos, layoutParam.box);
  43654. },
  43655. /**
  43656. * Prepare render list and total width
  43657. * @private
  43658. */
  43659. _prepare: function (targetNode, layoutParam, textStyleModel) {
  43660. for (var node = targetNode; node; node = node.parentNode) {
  43661. var text = node.getModel().get('name');
  43662. var textRect = textStyleModel.getTextRect(text);
  43663. var itemWidth = Math.max(
  43664. textRect.width + TEXT_PADDING * 2,
  43665. layoutParam.emptyItemWidth
  43666. );
  43667. layoutParam.totalWidth += itemWidth + ITEM_GAP;
  43668. layoutParam.renderList.push({node: node, text: text, width: itemWidth});
  43669. }
  43670. },
  43671. /**
  43672. * @private
  43673. */
  43674. _renderContent: function (
  43675. seriesModel, layoutParam, normalStyleModel, textStyleModel, onSelect
  43676. ) {
  43677. // Start rendering.
  43678. var lastX = 0;
  43679. var emptyItemWidth = layoutParam.emptyItemWidth;
  43680. var height = seriesModel.get('breadcrumb.height');
  43681. var availableSize = getAvailableSize(layoutParam.pos, layoutParam.box);
  43682. var totalWidth = layoutParam.totalWidth;
  43683. var renderList = layoutParam.renderList;
  43684. for (var i = renderList.length - 1; i >= 0; i--) {
  43685. var item = renderList[i];
  43686. var itemNode = item.node;
  43687. var itemWidth = item.width;
  43688. var text = item.text;
  43689. // Hdie text and shorten width if necessary.
  43690. if (totalWidth > availableSize.width) {
  43691. totalWidth -= itemWidth - emptyItemWidth;
  43692. itemWidth = emptyItemWidth;
  43693. text = null;
  43694. }
  43695. var el = new Polygon({
  43696. shape: {
  43697. points: makeItemPoints(
  43698. lastX, 0, itemWidth, height,
  43699. i === renderList.length - 1, i === 0
  43700. )
  43701. },
  43702. style: defaults(
  43703. normalStyleModel.getItemStyle(),
  43704. {
  43705. lineJoin: 'bevel',
  43706. text: text,
  43707. textFill: textStyleModel.getTextColor(),
  43708. textFont: textStyleModel.getFont()
  43709. }
  43710. ),
  43711. z: 10,
  43712. onclick: curry(onSelect, itemNode)
  43713. });
  43714. this.group.add(el);
  43715. packEventData(el, seriesModel, itemNode);
  43716. lastX += itemWidth + ITEM_GAP;
  43717. }
  43718. },
  43719. /**
  43720. * @override
  43721. */
  43722. remove: function () {
  43723. this.group.removeAll();
  43724. }
  43725. };
  43726. function makeItemPoints(x, y, itemWidth, itemHeight, head, tail) {
  43727. var points = [
  43728. [head ? x : x - ARRAY_LENGTH, y],
  43729. [x + itemWidth, y],
  43730. [x + itemWidth, y + itemHeight],
  43731. [head ? x : x - ARRAY_LENGTH, y + itemHeight]
  43732. ];
  43733. !tail && points.splice(2, 0, [x + itemWidth + ARRAY_LENGTH, y + itemHeight / 2]);
  43734. !head && points.push([x, y + itemHeight / 2]);
  43735. return points;
  43736. }
  43737. // Package custom mouse event.
  43738. function packEventData(el, seriesModel, itemNode) {
  43739. el.eventData = {
  43740. componentType: 'series',
  43741. componentSubType: 'treemap',
  43742. componentIndex: seriesModel.componentIndex,
  43743. seriesIndex: seriesModel.componentIndex,
  43744. seriesName: seriesModel.name,
  43745. seriesType: 'treemap',
  43746. selfType: 'breadcrumb', // Distinguish with click event on treemap node.
  43747. nodeData: {
  43748. dataIndex: itemNode && itemNode.dataIndex,
  43749. name: itemNode && itemNode.name
  43750. },
  43751. treePathInfo: itemNode && wrapTreePathInfo(itemNode, seriesModel)
  43752. };
  43753. }
  43754. /*
  43755. * Licensed to the Apache Software Foundation (ASF) under one
  43756. * or more contributor license agreements. See the NOTICE file
  43757. * distributed with this work for additional information
  43758. * regarding copyright ownership. The ASF licenses this file
  43759. * to you under the Apache License, Version 2.0 (the
  43760. * "License"); you may not use this file except in compliance
  43761. * with the License. You may obtain a copy of the License at
  43762. *
  43763. * http://www.apache.org/licenses/LICENSE-2.0
  43764. *
  43765. * Unless required by applicable law or agreed to in writing,
  43766. * software distributed under the License is distributed on an
  43767. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43768. * KIND, either express or implied. See the License for the
  43769. * specific language governing permissions and limitations
  43770. * under the License.
  43771. */
  43772. /**
  43773. * @param {number} [time=500] Time in ms
  43774. * @param {string} [easing='linear']
  43775. * @param {number} [delay=0]
  43776. * @param {Function} [callback]
  43777. *
  43778. * @example
  43779. * // Animate position
  43780. * animation
  43781. * .createWrap()
  43782. * .add(el1, {position: [10, 10]})
  43783. * .add(el2, {shape: {width: 500}, style: {fill: 'red'}}, 400)
  43784. * .done(function () { // done })
  43785. * .start('cubicOut');
  43786. */
  43787. function createWrap() {
  43788. var storage = [];
  43789. var elExistsMap = {};
  43790. var doneCallback;
  43791. return {
  43792. /**
  43793. * Caution: a el can only be added once, otherwise 'done'
  43794. * might not be called. This method checks this (by el.id),
  43795. * suppresses adding and returns false when existing el found.
  43796. *
  43797. * @param {modele:zrender/Element} el
  43798. * @param {Object} target
  43799. * @param {number} [time=500]
  43800. * @param {number} [delay=0]
  43801. * @param {string} [easing='linear']
  43802. * @return {boolean} Whether adding succeeded.
  43803. *
  43804. * @example
  43805. * add(el, target, time, delay, easing);
  43806. * add(el, target, time, easing);
  43807. * add(el, target, time);
  43808. * add(el, target);
  43809. */
  43810. add: function (el, target, time, delay, easing) {
  43811. if (isString(delay)) {
  43812. easing = delay;
  43813. delay = 0;
  43814. }
  43815. if (elExistsMap[el.id]) {
  43816. return false;
  43817. }
  43818. elExistsMap[el.id] = 1;
  43819. storage.push(
  43820. {el: el, target: target, time: time, delay: delay, easing: easing}
  43821. );
  43822. return true;
  43823. },
  43824. /**
  43825. * Only execute when animation finished. Will not execute when any
  43826. * of 'stop' or 'stopAnimation' called.
  43827. *
  43828. * @param {Function} callback
  43829. */
  43830. done: function (callback) {
  43831. doneCallback = callback;
  43832. return this;
  43833. },
  43834. /**
  43835. * Will stop exist animation firstly.
  43836. */
  43837. start: function () {
  43838. var count = storage.length;
  43839. for (var i = 0, len = storage.length; i < len; i++) {
  43840. var item = storage[i];
  43841. item.el.animateTo(item.target, item.time, item.delay, item.easing, done);
  43842. }
  43843. return this;
  43844. function done() {
  43845. count--;
  43846. if (!count) {
  43847. storage.length = 0;
  43848. elExistsMap = {};
  43849. doneCallback && doneCallback();
  43850. }
  43851. }
  43852. }
  43853. };
  43854. }
  43855. /*
  43856. * Licensed to the Apache Software Foundation (ASF) under one
  43857. * or more contributor license agreements. See the NOTICE file
  43858. * distributed with this work for additional information
  43859. * regarding copyright ownership. The ASF licenses this file
  43860. * to you under the Apache License, Version 2.0 (the
  43861. * "License"); you may not use this file except in compliance
  43862. * with the License. You may obtain a copy of the License at
  43863. *
  43864. * http://www.apache.org/licenses/LICENSE-2.0
  43865. *
  43866. * Unless required by applicable law or agreed to in writing,
  43867. * software distributed under the License is distributed on an
  43868. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43869. * KIND, either express or implied. See the License for the
  43870. * specific language governing permissions and limitations
  43871. * under the License.
  43872. */
  43873. var bind$1 = bind;
  43874. var Group$2 = Group;
  43875. var Rect$1 = Rect;
  43876. var each$8 = each$1;
  43877. var DRAG_THRESHOLD = 3;
  43878. var PATH_LABEL_NOAMAL = ['label'];
  43879. var PATH_LABEL_EMPHASIS = ['emphasis', 'label'];
  43880. var PATH_UPPERLABEL_NORMAL = ['upperLabel'];
  43881. var PATH_UPPERLABEL_EMPHASIS = ['emphasis', 'upperLabel'];
  43882. var Z_BASE = 10; // Should bigger than every z.
  43883. var Z_BG = 1;
  43884. var Z_CONTENT = 2;
  43885. var getItemStyleEmphasis = makeStyleMapper([
  43886. ['fill', 'color'],
  43887. // `borderColor` and `borderWidth` has been occupied,
  43888. // so use `stroke` to indicate the stroke of the rect.
  43889. ['stroke', 'strokeColor'],
  43890. ['lineWidth', 'strokeWidth'],
  43891. ['shadowBlur'],
  43892. ['shadowOffsetX'],
  43893. ['shadowOffsetY'],
  43894. ['shadowColor']
  43895. ]);
  43896. var getItemStyleNormal = function (model) {
  43897. // Normal style props should include emphasis style props.
  43898. var itemStyle = getItemStyleEmphasis(model);
  43899. // Clear styles set by emphasis.
  43900. itemStyle.stroke = itemStyle.fill = itemStyle.lineWidth = null;
  43901. return itemStyle;
  43902. };
  43903. extendChartView({
  43904. type: 'treemap',
  43905. /**
  43906. * @override
  43907. */
  43908. init: function (o, api) {
  43909. /**
  43910. * @private
  43911. * @type {module:zrender/container/Group}
  43912. */
  43913. this._containerGroup;
  43914. /**
  43915. * @private
  43916. * @type {Object.<string, Array.<module:zrender/container/Group>>}
  43917. */
  43918. this._storage = createStorage();
  43919. /**
  43920. * @private
  43921. * @type {module:echarts/data/Tree}
  43922. */
  43923. this._oldTree;
  43924. /**
  43925. * @private
  43926. * @type {module:echarts/chart/treemap/Breadcrumb}
  43927. */
  43928. this._breadcrumb;
  43929. /**
  43930. * @private
  43931. * @type {module:echarts/component/helper/RoamController}
  43932. */
  43933. this._controller;
  43934. /**
  43935. * 'ready', 'animating'
  43936. * @private
  43937. */
  43938. this._state = 'ready';
  43939. },
  43940. /**
  43941. * @override
  43942. */
  43943. render: function (seriesModel, ecModel, api, payload) {
  43944. var models = ecModel.findComponents({
  43945. mainType: 'series', subType: 'treemap', query: payload
  43946. });
  43947. if (indexOf(models, seriesModel) < 0) {
  43948. return;
  43949. }
  43950. this.seriesModel = seriesModel;
  43951. this.api = api;
  43952. this.ecModel = ecModel;
  43953. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  43954. var targetInfo = retrieveTargetInfo(payload, types, seriesModel);
  43955. var payloadType = payload && payload.type;
  43956. var layoutInfo = seriesModel.layoutInfo;
  43957. var isInit = !this._oldTree;
  43958. var thisStorage = this._storage;
  43959. // Mark new root when action is treemapRootToNode.
  43960. var reRoot = (payloadType === 'treemapRootToNode' && targetInfo && thisStorage)
  43961. ? {
  43962. rootNodeGroup: thisStorage.nodeGroup[targetInfo.node.getRawIndex()],
  43963. direction: payload.direction
  43964. }
  43965. : null;
  43966. var containerGroup = this._giveContainerGroup(layoutInfo);
  43967. var renderResult = this._doRender(containerGroup, seriesModel, reRoot);
  43968. (
  43969. !isInit && (
  43970. !payloadType
  43971. || payloadType === 'treemapZoomToNode'
  43972. || payloadType === 'treemapRootToNode'
  43973. )
  43974. )
  43975. ? this._doAnimation(containerGroup, renderResult, seriesModel, reRoot)
  43976. : renderResult.renderFinally();
  43977. this._resetController(api);
  43978. this._renderBreadcrumb(seriesModel, api, targetInfo);
  43979. },
  43980. /**
  43981. * @private
  43982. */
  43983. _giveContainerGroup: function (layoutInfo) {
  43984. var containerGroup = this._containerGroup;
  43985. if (!containerGroup) {
  43986. // FIXME
  43987. // 加一层containerGroup是为了clip,但是现在clip功能并没有实现。
  43988. containerGroup = this._containerGroup = new Group$2();
  43989. this._initEvents(containerGroup);
  43990. this.group.add(containerGroup);
  43991. }
  43992. containerGroup.attr('position', [layoutInfo.x, layoutInfo.y]);
  43993. return containerGroup;
  43994. },
  43995. /**
  43996. * @private
  43997. */
  43998. _doRender: function (containerGroup, seriesModel, reRoot) {
  43999. var thisTree = seriesModel.getData().tree;
  44000. var oldTree = this._oldTree;
  44001. // Clear last shape records.
  44002. var lastsForAnimation = createStorage();
  44003. var thisStorage = createStorage();
  44004. var oldStorage = this._storage;
  44005. var willInvisibleEls = [];
  44006. var doRenderNode = curry(
  44007. renderNode, seriesModel,
  44008. thisStorage, oldStorage, reRoot,
  44009. lastsForAnimation, willInvisibleEls
  44010. );
  44011. // Notice: when thisTree and oldTree are the same tree (see list.cloneShallow),
  44012. // the oldTree is actually losted, so we can not find all of the old graphic
  44013. // elements from tree. So we use this stragegy: make element storage, move
  44014. // from old storage to new storage, clear old storage.
  44015. dualTravel(
  44016. thisTree.root ? [thisTree.root] : [],
  44017. (oldTree && oldTree.root) ? [oldTree.root] : [],
  44018. containerGroup,
  44019. thisTree === oldTree || !oldTree,
  44020. 0
  44021. );
  44022. // Process all removing.
  44023. var willDeleteEls = clearStorage(oldStorage);
  44024. this._oldTree = thisTree;
  44025. this._storage = thisStorage;
  44026. return {
  44027. lastsForAnimation: lastsForAnimation,
  44028. willDeleteEls: willDeleteEls,
  44029. renderFinally: renderFinally
  44030. };
  44031. function dualTravel(thisViewChildren, oldViewChildren, parentGroup, sameTree, depth) {
  44032. // When 'render' is triggered by action,
  44033. // 'this' and 'old' may be the same tree,
  44034. // we use rawIndex in that case.
  44035. if (sameTree) {
  44036. oldViewChildren = thisViewChildren;
  44037. each$8(thisViewChildren, function (child, index) {
  44038. !child.isRemoved() && processNode(index, index);
  44039. });
  44040. }
  44041. // Diff hierarchically (diff only in each subtree, but not whole).
  44042. // because, consistency of view is important.
  44043. else {
  44044. (new DataDiffer(oldViewChildren, thisViewChildren, getKey, getKey))
  44045. .add(processNode)
  44046. .update(processNode)
  44047. .remove(curry(processNode, null))
  44048. .execute();
  44049. }
  44050. function getKey(node) {
  44051. // Identify by name or raw index.
  44052. return node.getId();
  44053. }
  44054. function processNode(newIndex, oldIndex) {
  44055. var thisNode = newIndex != null ? thisViewChildren[newIndex] : null;
  44056. var oldNode = oldIndex != null ? oldViewChildren[oldIndex] : null;
  44057. var group = doRenderNode(thisNode, oldNode, parentGroup, depth);
  44058. group && dualTravel(
  44059. thisNode && thisNode.viewChildren || [],
  44060. oldNode && oldNode.viewChildren || [],
  44061. group,
  44062. sameTree,
  44063. depth + 1
  44064. );
  44065. }
  44066. }
  44067. function clearStorage(storage) {
  44068. var willDeleteEls = createStorage();
  44069. storage && each$8(storage, function (store, storageName) {
  44070. var delEls = willDeleteEls[storageName];
  44071. each$8(store, function (el) {
  44072. el && (delEls.push(el), el.__tmWillDelete = 1);
  44073. });
  44074. });
  44075. return willDeleteEls;
  44076. }
  44077. function renderFinally() {
  44078. each$8(willDeleteEls, function (els) {
  44079. each$8(els, function (el) {
  44080. el.parent && el.parent.remove(el);
  44081. });
  44082. });
  44083. each$8(willInvisibleEls, function (el) {
  44084. el.invisible = true;
  44085. // Setting invisible is for optimizing, so no need to set dirty,
  44086. // just mark as invisible.
  44087. el.dirty();
  44088. });
  44089. }
  44090. },
  44091. /**
  44092. * @private
  44093. */
  44094. _doAnimation: function (containerGroup, renderResult, seriesModel, reRoot) {
  44095. if (!seriesModel.get('animation')) {
  44096. return;
  44097. }
  44098. var duration = seriesModel.get('animationDurationUpdate');
  44099. var easing = seriesModel.get('animationEasing');
  44100. var animationWrap = createWrap();
  44101. // Make delete animations.
  44102. each$8(renderResult.willDeleteEls, function (store, storageName) {
  44103. each$8(store, function (el, rawIndex) {
  44104. if (el.invisible) {
  44105. return;
  44106. }
  44107. var parent = el.parent; // Always has parent, and parent is nodeGroup.
  44108. var target;
  44109. if (reRoot && reRoot.direction === 'drillDown') {
  44110. target = parent === reRoot.rootNodeGroup
  44111. // This is the content element of view root.
  44112. // Only `content` will enter this branch, because
  44113. // `background` and `nodeGroup` will not be deleted.
  44114. ? {
  44115. shape: {
  44116. x: 0,
  44117. y: 0,
  44118. width: parent.__tmNodeWidth,
  44119. height: parent.__tmNodeHeight
  44120. },
  44121. style: {
  44122. opacity: 0
  44123. }
  44124. }
  44125. // Others.
  44126. : {style: {opacity: 0}};
  44127. }
  44128. else {
  44129. var targetX = 0;
  44130. var targetY = 0;
  44131. if (!parent.__tmWillDelete) {
  44132. // Let node animate to right-bottom corner, cooperating with fadeout,
  44133. // which is appropriate for user understanding.
  44134. // Divided by 2 for reRoot rolling up effect.
  44135. targetX = parent.__tmNodeWidth / 2;
  44136. targetY = parent.__tmNodeHeight / 2;
  44137. }
  44138. target = storageName === 'nodeGroup'
  44139. ? {position: [targetX, targetY], style: {opacity: 0}}
  44140. : {
  44141. shape: {x: targetX, y: targetY, width: 0, height: 0},
  44142. style: {opacity: 0}
  44143. };
  44144. }
  44145. target && animationWrap.add(el, target, duration, easing);
  44146. });
  44147. });
  44148. // Make other animations
  44149. each$8(this._storage, function (store, storageName) {
  44150. each$8(store, function (el, rawIndex) {
  44151. var last = renderResult.lastsForAnimation[storageName][rawIndex];
  44152. var target = {};
  44153. if (!last) {
  44154. return;
  44155. }
  44156. if (storageName === 'nodeGroup') {
  44157. if (last.old) {
  44158. target.position = el.position.slice();
  44159. el.attr('position', last.old);
  44160. }
  44161. }
  44162. else {
  44163. if (last.old) {
  44164. target.shape = extend({}, el.shape);
  44165. el.setShape(last.old);
  44166. }
  44167. if (last.fadein) {
  44168. el.setStyle('opacity', 0);
  44169. target.style = {opacity: 1};
  44170. }
  44171. // When animation is stopped for succedent animation starting,
  44172. // el.style.opacity might not be 1
  44173. else if (el.style.opacity !== 1) {
  44174. target.style = {opacity: 1};
  44175. }
  44176. }
  44177. animationWrap.add(el, target, duration, easing);
  44178. });
  44179. }, this);
  44180. this._state = 'animating';
  44181. animationWrap
  44182. .done(bind$1(function () {
  44183. this._state = 'ready';
  44184. renderResult.renderFinally();
  44185. }, this))
  44186. .start();
  44187. },
  44188. /**
  44189. * @private
  44190. */
  44191. _resetController: function (api) {
  44192. var controller = this._controller;
  44193. // Init controller.
  44194. if (!controller) {
  44195. controller = this._controller = new RoamController(api.getZr());
  44196. controller.enable(this.seriesModel.get('roam'));
  44197. controller.on('pan', bind$1(this._onPan, this));
  44198. controller.on('zoom', bind$1(this._onZoom, this));
  44199. }
  44200. var rect = new BoundingRect(0, 0, api.getWidth(), api.getHeight());
  44201. controller.setPointerChecker(function (e, x, y) {
  44202. return rect.contain(x, y);
  44203. });
  44204. },
  44205. /**
  44206. * @private
  44207. */
  44208. _clearController: function () {
  44209. var controller = this._controller;
  44210. if (controller) {
  44211. controller.dispose();
  44212. controller = null;
  44213. }
  44214. },
  44215. /**
  44216. * @private
  44217. */
  44218. _onPan: function (e) {
  44219. if (this._state !== 'animating'
  44220. && (Math.abs(e.dx) > DRAG_THRESHOLD || Math.abs(e.dy) > DRAG_THRESHOLD)
  44221. ) {
  44222. // These param must not be cached.
  44223. var root = this.seriesModel.getData().tree.root;
  44224. if (!root) {
  44225. return;
  44226. }
  44227. var rootLayout = root.getLayout();
  44228. if (!rootLayout) {
  44229. return;
  44230. }
  44231. this.api.dispatchAction({
  44232. type: 'treemapMove',
  44233. from: this.uid,
  44234. seriesId: this.seriesModel.id,
  44235. rootRect: {
  44236. x: rootLayout.x + e.dx, y: rootLayout.y + e.dy,
  44237. width: rootLayout.width, height: rootLayout.height
  44238. }
  44239. });
  44240. }
  44241. },
  44242. /**
  44243. * @private
  44244. */
  44245. _onZoom: function (e) {
  44246. var mouseX = e.originX;
  44247. var mouseY = e.originY;
  44248. if (this._state !== 'animating') {
  44249. // These param must not be cached.
  44250. var root = this.seriesModel.getData().tree.root;
  44251. if (!root) {
  44252. return;
  44253. }
  44254. var rootLayout = root.getLayout();
  44255. if (!rootLayout) {
  44256. return;
  44257. }
  44258. var rect = new BoundingRect(
  44259. rootLayout.x, rootLayout.y, rootLayout.width, rootLayout.height
  44260. );
  44261. var layoutInfo = this.seriesModel.layoutInfo;
  44262. // Transform mouse coord from global to containerGroup.
  44263. mouseX -= layoutInfo.x;
  44264. mouseY -= layoutInfo.y;
  44265. // Scale root bounding rect.
  44266. var m = create$1();
  44267. translate(m, m, [-mouseX, -mouseY]);
  44268. scale$1(m, m, [e.scale, e.scale]);
  44269. translate(m, m, [mouseX, mouseY]);
  44270. rect.applyTransform(m);
  44271. this.api.dispatchAction({
  44272. type: 'treemapRender',
  44273. from: this.uid,
  44274. seriesId: this.seriesModel.id,
  44275. rootRect: {
  44276. x: rect.x, y: rect.y,
  44277. width: rect.width, height: rect.height
  44278. }
  44279. });
  44280. }
  44281. },
  44282. /**
  44283. * @private
  44284. */
  44285. _initEvents: function (containerGroup) {
  44286. containerGroup.on('click', function (e) {
  44287. if (this._state !== 'ready') {
  44288. return;
  44289. }
  44290. var nodeClick = this.seriesModel.get('nodeClick', true);
  44291. if (!nodeClick) {
  44292. return;
  44293. }
  44294. var targetInfo = this.findTarget(e.offsetX, e.offsetY);
  44295. if (!targetInfo) {
  44296. return;
  44297. }
  44298. var node = targetInfo.node;
  44299. if (node.getLayout().isLeafRoot) {
  44300. this._rootToNode(targetInfo);
  44301. }
  44302. else {
  44303. if (nodeClick === 'zoomToNode') {
  44304. this._zoomToNode(targetInfo);
  44305. }
  44306. else if (nodeClick === 'link') {
  44307. var itemModel = node.hostTree.data.getItemModel(node.dataIndex);
  44308. var link = itemModel.get('link', true);
  44309. var linkTarget = itemModel.get('target', true) || 'blank';
  44310. link && window.open(link, linkTarget);
  44311. }
  44312. }
  44313. }, this);
  44314. },
  44315. /**
  44316. * @private
  44317. */
  44318. _renderBreadcrumb: function (seriesModel, api, targetInfo) {
  44319. if (!targetInfo) {
  44320. targetInfo = seriesModel.get('leafDepth', true) != null
  44321. ? {node: seriesModel.getViewRoot()}
  44322. // FIXME
  44323. // better way?
  44324. // Find breadcrumb tail on center of containerGroup.
  44325. : this.findTarget(api.getWidth() / 2, api.getHeight() / 2);
  44326. if (!targetInfo) {
  44327. targetInfo = {node: seriesModel.getData().tree.root};
  44328. }
  44329. }
  44330. (this._breadcrumb || (this._breadcrumb = new Breadcrumb(this.group)))
  44331. .render(seriesModel, api, targetInfo.node, bind$1(onSelect, this));
  44332. function onSelect(node) {
  44333. if (this._state !== 'animating') {
  44334. aboveViewRoot(seriesModel.getViewRoot(), node)
  44335. ? this._rootToNode({node: node})
  44336. : this._zoomToNode({node: node});
  44337. }
  44338. }
  44339. },
  44340. /**
  44341. * @override
  44342. */
  44343. remove: function () {
  44344. this._clearController();
  44345. this._containerGroup && this._containerGroup.removeAll();
  44346. this._storage = createStorage();
  44347. this._state = 'ready';
  44348. this._breadcrumb && this._breadcrumb.remove();
  44349. },
  44350. dispose: function () {
  44351. this._clearController();
  44352. },
  44353. /**
  44354. * @private
  44355. */
  44356. _zoomToNode: function (targetInfo) {
  44357. this.api.dispatchAction({
  44358. type: 'treemapZoomToNode',
  44359. from: this.uid,
  44360. seriesId: this.seriesModel.id,
  44361. targetNode: targetInfo.node
  44362. });
  44363. },
  44364. /**
  44365. * @private
  44366. */
  44367. _rootToNode: function (targetInfo) {
  44368. this.api.dispatchAction({
  44369. type: 'treemapRootToNode',
  44370. from: this.uid,
  44371. seriesId: this.seriesModel.id,
  44372. targetNode: targetInfo.node
  44373. });
  44374. },
  44375. /**
  44376. * @public
  44377. * @param {number} x Global coord x.
  44378. * @param {number} y Global coord y.
  44379. * @return {Object} info If not found, return undefined;
  44380. * @return {number} info.node Target node.
  44381. * @return {number} info.offsetX x refer to target node.
  44382. * @return {number} info.offsetY y refer to target node.
  44383. */
  44384. findTarget: function (x, y) {
  44385. var targetInfo;
  44386. var viewRoot = this.seriesModel.getViewRoot();
  44387. viewRoot.eachNode({attr: 'viewChildren', order: 'preorder'}, function (node) {
  44388. var bgEl = this._storage.background[node.getRawIndex()];
  44389. // If invisible, there might be no element.
  44390. if (bgEl) {
  44391. var point = bgEl.transformCoordToLocal(x, y);
  44392. var shape = bgEl.shape;
  44393. // For performance consideration, dont use 'getBoundingRect'.
  44394. if (shape.x <= point[0]
  44395. && point[0] <= shape.x + shape.width
  44396. && shape.y <= point[1]
  44397. && point[1] <= shape.y + shape.height
  44398. ) {
  44399. targetInfo = {node: node, offsetX: point[0], offsetY: point[1]};
  44400. }
  44401. else {
  44402. return false; // Suppress visit subtree.
  44403. }
  44404. }
  44405. }, this);
  44406. return targetInfo;
  44407. }
  44408. });
  44409. /**
  44410. * @inner
  44411. */
  44412. function createStorage() {
  44413. return {nodeGroup: [], background: [], content: []};
  44414. }
  44415. /**
  44416. * @inner
  44417. * @return Return undefined means do not travel further.
  44418. */
  44419. function renderNode(
  44420. seriesModel, thisStorage, oldStorage, reRoot,
  44421. lastsForAnimation, willInvisibleEls,
  44422. thisNode, oldNode, parentGroup, depth
  44423. ) {
  44424. // Whether under viewRoot.
  44425. if (!thisNode) {
  44426. // Deleting nodes will be performed finally. This method just find
  44427. // element from old storage, or create new element, set them to new
  44428. // storage, and set styles.
  44429. return;
  44430. }
  44431. // -------------------------------------------------------------------
  44432. // Start of closure variables available in "Procedures in renderNode".
  44433. var thisLayout = thisNode.getLayout();
  44434. if (!thisLayout || !thisLayout.isInView) {
  44435. return;
  44436. }
  44437. var thisWidth = thisLayout.width;
  44438. var thisHeight = thisLayout.height;
  44439. var borderWidth = thisLayout.borderWidth;
  44440. var thisInvisible = thisLayout.invisible;
  44441. var thisRawIndex = thisNode.getRawIndex();
  44442. var oldRawIndex = oldNode && oldNode.getRawIndex();
  44443. var thisViewChildren = thisNode.viewChildren;
  44444. var upperHeight = thisLayout.upperHeight;
  44445. var isParent = thisViewChildren && thisViewChildren.length;
  44446. var itemStyleNormalModel = thisNode.getModel('itemStyle');
  44447. var itemStyleEmphasisModel = thisNode.getModel('emphasis.itemStyle');
  44448. // End of closure ariables available in "Procedures in renderNode".
  44449. // -----------------------------------------------------------------
  44450. // Node group
  44451. var group = giveGraphic('nodeGroup', Group$2);
  44452. if (!group) {
  44453. return;
  44454. }
  44455. parentGroup.add(group);
  44456. // x,y are not set when el is above view root.
  44457. group.attr('position', [thisLayout.x || 0, thisLayout.y || 0]);
  44458. group.__tmNodeWidth = thisWidth;
  44459. group.__tmNodeHeight = thisHeight;
  44460. if (thisLayout.isAboveViewRoot) {
  44461. return group;
  44462. }
  44463. // Background
  44464. var bg = giveGraphic('background', Rect$1, depth, Z_BG);
  44465. bg && renderBackground(group, bg, isParent && thisLayout.upperHeight);
  44466. // No children, render content.
  44467. if (!isParent) {
  44468. var content = giveGraphic('content', Rect$1, depth, Z_CONTENT);
  44469. content && renderContent(group, content);
  44470. }
  44471. return group;
  44472. // ----------------------------
  44473. // | Procedures in renderNode |
  44474. // ----------------------------
  44475. function renderBackground(group, bg, useUpperLabel) {
  44476. // For tooltip.
  44477. bg.dataIndex = thisNode.dataIndex;
  44478. bg.seriesIndex = seriesModel.seriesIndex;
  44479. bg.setShape({x: 0, y: 0, width: thisWidth, height: thisHeight});
  44480. var visualBorderColor = thisNode.getVisual('borderColor', true);
  44481. var emphasisBorderColor = itemStyleEmphasisModel.get('borderColor');
  44482. updateStyle(bg, function () {
  44483. var normalStyle = getItemStyleNormal(itemStyleNormalModel);
  44484. normalStyle.fill = visualBorderColor;
  44485. var emphasisStyle = getItemStyleEmphasis(itemStyleEmphasisModel);
  44486. emphasisStyle.fill = emphasisBorderColor;
  44487. if (useUpperLabel) {
  44488. var upperLabelWidth = thisWidth - 2 * borderWidth;
  44489. prepareText(
  44490. normalStyle, emphasisStyle, visualBorderColor, upperLabelWidth, upperHeight,
  44491. {x: borderWidth, y: 0, width: upperLabelWidth, height: upperHeight}
  44492. );
  44493. }
  44494. // For old bg.
  44495. else {
  44496. normalStyle.text = emphasisStyle.text = null;
  44497. }
  44498. bg.setStyle(normalStyle);
  44499. setHoverStyle(bg, emphasisStyle);
  44500. });
  44501. group.add(bg);
  44502. }
  44503. function renderContent(group, content) {
  44504. // For tooltip.
  44505. content.dataIndex = thisNode.dataIndex;
  44506. content.seriesIndex = seriesModel.seriesIndex;
  44507. var contentWidth = Math.max(thisWidth - 2 * borderWidth, 0);
  44508. var contentHeight = Math.max(thisHeight - 2 * borderWidth, 0);
  44509. content.culling = true;
  44510. content.setShape({
  44511. x: borderWidth,
  44512. y: borderWidth,
  44513. width: contentWidth,
  44514. height: contentHeight
  44515. });
  44516. var visualColor = thisNode.getVisual('color', true);
  44517. updateStyle(content, function () {
  44518. var normalStyle = getItemStyleNormal(itemStyleNormalModel);
  44519. normalStyle.fill = visualColor;
  44520. var emphasisStyle = getItemStyleEmphasis(itemStyleEmphasisModel);
  44521. prepareText(normalStyle, emphasisStyle, visualColor, contentWidth, contentHeight);
  44522. content.setStyle(normalStyle);
  44523. setHoverStyle(content, emphasisStyle);
  44524. });
  44525. group.add(content);
  44526. }
  44527. function updateStyle(element, cb) {
  44528. if (!thisInvisible) {
  44529. // If invisible, do not set visual, otherwise the element will
  44530. // change immediately before animation. We think it is OK to
  44531. // remain its origin color when moving out of the view window.
  44532. cb();
  44533. if (!element.__tmWillVisible) {
  44534. element.invisible = false;
  44535. }
  44536. }
  44537. else {
  44538. // Delay invisible setting utill animation finished,
  44539. // avoid element vanish suddenly before animation.
  44540. !element.invisible && willInvisibleEls.push(element);
  44541. }
  44542. }
  44543. function prepareText(normalStyle, emphasisStyle, visualColor, width, height, upperLabelRect) {
  44544. var nodeModel = thisNode.getModel();
  44545. var text = retrieve(
  44546. seriesModel.getFormattedLabel(
  44547. thisNode.dataIndex, 'normal', null, null, upperLabelRect ? 'upperLabel' : 'label'
  44548. ),
  44549. nodeModel.get('name')
  44550. );
  44551. if (!upperLabelRect && thisLayout.isLeafRoot) {
  44552. var iconChar = seriesModel.get('drillDownIcon', true);
  44553. text = iconChar ? iconChar + ' ' + text : text;
  44554. }
  44555. var normalLabelModel = nodeModel.getModel(
  44556. upperLabelRect ? PATH_UPPERLABEL_NORMAL : PATH_LABEL_NOAMAL
  44557. );
  44558. var emphasisLabelModel = nodeModel.getModel(
  44559. upperLabelRect ? PATH_UPPERLABEL_EMPHASIS : PATH_LABEL_EMPHASIS
  44560. );
  44561. var isShow = normalLabelModel.getShallow('show');
  44562. setLabelStyle(
  44563. normalStyle, emphasisStyle, normalLabelModel, emphasisLabelModel,
  44564. {
  44565. defaultText: isShow ? text : null,
  44566. autoColor: visualColor,
  44567. isRectText: true
  44568. }
  44569. );
  44570. upperLabelRect && (normalStyle.textRect = clone(upperLabelRect));
  44571. normalStyle.truncate = (isShow && normalLabelModel.get('ellipsis'))
  44572. ? {
  44573. outerWidth: width,
  44574. outerHeight: height,
  44575. minChar: 2
  44576. }
  44577. : null;
  44578. }
  44579. function giveGraphic(storageName, Ctor, depth, z) {
  44580. var element = oldRawIndex != null && oldStorage[storageName][oldRawIndex];
  44581. var lasts = lastsForAnimation[storageName];
  44582. if (element) {
  44583. // Remove from oldStorage
  44584. oldStorage[storageName][oldRawIndex] = null;
  44585. prepareAnimationWhenHasOld(lasts, element, storageName);
  44586. }
  44587. // If invisible and no old element, do not create new element (for optimizing).
  44588. else if (!thisInvisible) {
  44589. element = new Ctor({z: calculateZ(depth, z)});
  44590. element.__tmDepth = depth;
  44591. element.__tmStorageName = storageName;
  44592. prepareAnimationWhenNoOld(lasts, element, storageName);
  44593. }
  44594. // Set to thisStorage
  44595. return (thisStorage[storageName][thisRawIndex] = element);
  44596. }
  44597. function prepareAnimationWhenHasOld(lasts, element, storageName) {
  44598. var lastCfg = lasts[thisRawIndex] = {};
  44599. lastCfg.old = storageName === 'nodeGroup'
  44600. ? element.position.slice()
  44601. : extend({}, element.shape);
  44602. }
  44603. // If a element is new, we need to find the animation start point carefully,
  44604. // otherwise it will looks strange when 'zoomToNode'.
  44605. function prepareAnimationWhenNoOld(lasts, element, storageName) {
  44606. var lastCfg = lasts[thisRawIndex] = {};
  44607. var parentNode = thisNode.parentNode;
  44608. if (parentNode && (!reRoot || reRoot.direction === 'drillDown')) {
  44609. var parentOldX = 0;
  44610. var parentOldY = 0;
  44611. // New nodes appear from right-bottom corner in 'zoomToNode' animation.
  44612. // For convenience, get old bounding rect from background.
  44613. var parentOldBg = lastsForAnimation.background[parentNode.getRawIndex()];
  44614. if (!reRoot && parentOldBg && parentOldBg.old) {
  44615. parentOldX = parentOldBg.old.width;
  44616. parentOldY = parentOldBg.old.height;
  44617. }
  44618. // When no parent old shape found, its parent is new too,
  44619. // so we can just use {x:0, y:0}.
  44620. lastCfg.old = storageName === 'nodeGroup'
  44621. ? [0, parentOldY]
  44622. : {x: parentOldX, y: parentOldY, width: 0, height: 0};
  44623. }
  44624. // Fade in, user can be aware that these nodes are new.
  44625. lastCfg.fadein = storageName !== 'nodeGroup';
  44626. }
  44627. }
  44628. // We can not set all backgroud with the same z, Because the behaviour of
  44629. // drill down and roll up differ background creation sequence from tree
  44630. // hierarchy sequence, which cause that lowser background element overlap
  44631. // upper ones. So we calculate z based on depth.
  44632. // Moreover, we try to shrink down z interval to [0, 1] to avoid that
  44633. // treemap with large z overlaps other components.
  44634. function calculateZ(depth, zInLevel) {
  44635. var zb = depth * Z_BASE + zInLevel;
  44636. return (zb - 1) / zb;
  44637. }
  44638. /*
  44639. * Licensed to the Apache Software Foundation (ASF) under one
  44640. * or more contributor license agreements. See the NOTICE file
  44641. * distributed with this work for additional information
  44642. * regarding copyright ownership. The ASF licenses this file
  44643. * to you under the Apache License, Version 2.0 (the
  44644. * "License"); you may not use this file except in compliance
  44645. * with the License. You may obtain a copy of the License at
  44646. *
  44647. * http://www.apache.org/licenses/LICENSE-2.0
  44648. *
  44649. * Unless required by applicable law or agreed to in writing,
  44650. * software distributed under the License is distributed on an
  44651. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44652. * KIND, either express or implied. See the License for the
  44653. * specific language governing permissions and limitations
  44654. * under the License.
  44655. */
  44656. /**
  44657. * @file Treemap action
  44658. */
  44659. var noop$1 = function () {};
  44660. var actionTypes = [
  44661. 'treemapZoomToNode',
  44662. 'treemapRender',
  44663. 'treemapMove'
  44664. ];
  44665. for (var i$2 = 0; i$2 < actionTypes.length; i$2++) {
  44666. registerAction({type: actionTypes[i$2], update: 'updateView'}, noop$1);
  44667. }
  44668. registerAction(
  44669. {type: 'treemapRootToNode', update: 'updateView'},
  44670. function (payload, ecModel) {
  44671. ecModel.eachComponent(
  44672. {mainType: 'series', subType: 'treemap', query: payload},
  44673. handleRootToNode
  44674. );
  44675. function handleRootToNode(model, index) {
  44676. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  44677. var targetInfo = retrieveTargetInfo(payload, types, model);
  44678. if (targetInfo) {
  44679. var originViewRoot = model.getViewRoot();
  44680. if (originViewRoot) {
  44681. payload.direction = aboveViewRoot(originViewRoot, targetInfo.node)
  44682. ? 'rollUp' : 'drillDown';
  44683. }
  44684. model.resetViewRoot(targetInfo.node);
  44685. }
  44686. }
  44687. }
  44688. );
  44689. /*
  44690. * Licensed to the Apache Software Foundation (ASF) under one
  44691. * or more contributor license agreements. See the NOTICE file
  44692. * distributed with this work for additional information
  44693. * regarding copyright ownership. The ASF licenses this file
  44694. * to you under the Apache License, Version 2.0 (the
  44695. * "License"); you may not use this file except in compliance
  44696. * with the License. You may obtain a copy of the License at
  44697. *
  44698. * http://www.apache.org/licenses/LICENSE-2.0
  44699. *
  44700. * Unless required by applicable law or agreed to in writing,
  44701. * software distributed under the License is distributed on an
  44702. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44703. * KIND, either express or implied. See the License for the
  44704. * specific language governing permissions and limitations
  44705. * under the License.
  44706. */
  44707. var each$9 = each$1;
  44708. var isObject$5 = isObject$1;
  44709. var CATEGORY_DEFAULT_VISUAL_INDEX = -1;
  44710. /**
  44711. * @param {Object} option
  44712. * @param {string} [option.type] See visualHandlers.
  44713. * @param {string} [option.mappingMethod] 'linear' or 'piecewise' or 'category' or 'fixed'
  44714. * @param {Array.<number>=} [option.dataExtent] [minExtent, maxExtent],
  44715. * required when mappingMethod is 'linear'
  44716. * @param {Array.<Object>=} [option.pieceList] [
  44717. * {value: someValue},
  44718. * {interval: [min1, max1], visual: {...}},
  44719. * {interval: [min2, max2]}
  44720. * ],
  44721. * required when mappingMethod is 'piecewise'.
  44722. * Visual for only each piece can be specified.
  44723. * @param {Array.<string|Object>=} [option.categories] ['cate1', 'cate2']
  44724. * required when mappingMethod is 'category'.
  44725. * If no option.categories, categories is set
  44726. * as [0, 1, 2, ...].
  44727. * @param {boolean} [option.loop=false] Whether loop mapping when mappingMethod is 'category'.
  44728. * @param {(Array|Object|*)} [option.visual] Visual data.
  44729. * when mappingMethod is 'category',
  44730. * visual data can be array or object
  44731. * (like: {cate1: '#222', none: '#fff'})
  44732. * or primary types (which represents
  44733. * defualt category visual), otherwise visual
  44734. * can be array or primary (which will be
  44735. * normalized to array).
  44736. *
  44737. */
  44738. var VisualMapping = function (option) {
  44739. var mappingMethod = option.mappingMethod;
  44740. var visualType = option.type;
  44741. /**
  44742. * @readOnly
  44743. * @type {Object}
  44744. */
  44745. var thisOption = this.option = clone(option);
  44746. /**
  44747. * @readOnly
  44748. * @type {string}
  44749. */
  44750. this.type = visualType;
  44751. /**
  44752. * @readOnly
  44753. * @type {string}
  44754. */
  44755. this.mappingMethod = mappingMethod;
  44756. /**
  44757. * @private
  44758. * @type {Function}
  44759. */
  44760. this._normalizeData = normalizers[mappingMethod];
  44761. var visualHandler = visualHandlers[visualType];
  44762. /**
  44763. * @public
  44764. * @type {Function}
  44765. */
  44766. this.applyVisual = visualHandler.applyVisual;
  44767. /**
  44768. * @public
  44769. * @type {Function}
  44770. */
  44771. this.getColorMapper = visualHandler.getColorMapper;
  44772. /**
  44773. * @private
  44774. * @type {Function}
  44775. */
  44776. this._doMap = visualHandler._doMap[mappingMethod];
  44777. if (mappingMethod === 'piecewise') {
  44778. normalizeVisualRange(thisOption);
  44779. preprocessForPiecewise(thisOption);
  44780. }
  44781. else if (mappingMethod === 'category') {
  44782. thisOption.categories
  44783. ? preprocessForSpecifiedCategory(thisOption)
  44784. // categories is ordinal when thisOption.categories not specified,
  44785. // which need no more preprocess except normalize visual.
  44786. : normalizeVisualRange(thisOption, true);
  44787. }
  44788. else { // mappingMethod === 'linear' or 'fixed'
  44789. assert$1(mappingMethod !== 'linear' || thisOption.dataExtent);
  44790. normalizeVisualRange(thisOption);
  44791. }
  44792. };
  44793. VisualMapping.prototype = {
  44794. constructor: VisualMapping,
  44795. mapValueToVisual: function (value) {
  44796. var normalized = this._normalizeData(value);
  44797. return this._doMap(normalized, value);
  44798. },
  44799. getNormalizer: function () {
  44800. return bind(this._normalizeData, this);
  44801. }
  44802. };
  44803. var visualHandlers = VisualMapping.visualHandlers = {
  44804. color: {
  44805. applyVisual: makeApplyVisual('color'),
  44806. /**
  44807. * Create a mapper function
  44808. * @return {Function}
  44809. */
  44810. getColorMapper: function () {
  44811. var thisOption = this.option;
  44812. return bind(
  44813. thisOption.mappingMethod === 'category'
  44814. ? function (value, isNormalized) {
  44815. !isNormalized && (value = this._normalizeData(value));
  44816. return doMapCategory.call(this, value);
  44817. }
  44818. : function (value, isNormalized, out) {
  44819. // If output rgb array
  44820. // which will be much faster and useful in pixel manipulation
  44821. var returnRGBArray = !!out;
  44822. !isNormalized && (value = this._normalizeData(value));
  44823. out = fastLerp(value, thisOption.parsedVisual, out);
  44824. return returnRGBArray ? out : stringify(out, 'rgba');
  44825. },
  44826. this
  44827. );
  44828. },
  44829. _doMap: {
  44830. linear: function (normalized) {
  44831. return stringify(
  44832. fastLerp(normalized, this.option.parsedVisual),
  44833. 'rgba'
  44834. );
  44835. },
  44836. category: doMapCategory,
  44837. piecewise: function (normalized, value) {
  44838. var result = getSpecifiedVisual.call(this, value);
  44839. if (result == null) {
  44840. result = stringify(
  44841. fastLerp(normalized, this.option.parsedVisual),
  44842. 'rgba'
  44843. );
  44844. }
  44845. return result;
  44846. },
  44847. fixed: doMapFixed
  44848. }
  44849. },
  44850. colorHue: makePartialColorVisualHandler(function (color, value) {
  44851. return modifyHSL(color, value);
  44852. }),
  44853. colorSaturation: makePartialColorVisualHandler(function (color, value) {
  44854. return modifyHSL(color, null, value);
  44855. }),
  44856. colorLightness: makePartialColorVisualHandler(function (color, value) {
  44857. return modifyHSL(color, null, null, value);
  44858. }),
  44859. colorAlpha: makePartialColorVisualHandler(function (color, value) {
  44860. return modifyAlpha(color, value);
  44861. }),
  44862. opacity: {
  44863. applyVisual: makeApplyVisual('opacity'),
  44864. _doMap: makeDoMap([0, 1])
  44865. },
  44866. liftZ: {
  44867. applyVisual: makeApplyVisual('liftZ'),
  44868. _doMap: {
  44869. linear: doMapFixed,
  44870. category: doMapFixed,
  44871. piecewise: doMapFixed,
  44872. fixed: doMapFixed
  44873. }
  44874. },
  44875. symbol: {
  44876. applyVisual: function (value, getter, setter) {
  44877. var symbolCfg = this.mapValueToVisual(value);
  44878. if (isString(symbolCfg)) {
  44879. setter('symbol', symbolCfg);
  44880. }
  44881. else if (isObject$5(symbolCfg)) {
  44882. for (var name in symbolCfg) {
  44883. if (symbolCfg.hasOwnProperty(name)) {
  44884. setter(name, symbolCfg[name]);
  44885. }
  44886. }
  44887. }
  44888. },
  44889. _doMap: {
  44890. linear: doMapToArray,
  44891. category: doMapCategory,
  44892. piecewise: function (normalized, value) {
  44893. var result = getSpecifiedVisual.call(this, value);
  44894. if (result == null) {
  44895. result = doMapToArray.call(this, normalized);
  44896. }
  44897. return result;
  44898. },
  44899. fixed: doMapFixed
  44900. }
  44901. },
  44902. symbolSize: {
  44903. applyVisual: makeApplyVisual('symbolSize'),
  44904. _doMap: makeDoMap([0, 1])
  44905. }
  44906. };
  44907. function preprocessForPiecewise(thisOption) {
  44908. var pieceList = thisOption.pieceList;
  44909. thisOption.hasSpecialVisual = false;
  44910. each$1(pieceList, function (piece, index) {
  44911. piece.originIndex = index;
  44912. // piece.visual is "result visual value" but not
  44913. // a visual range, so it does not need to be normalized.
  44914. if (piece.visual != null) {
  44915. thisOption.hasSpecialVisual = true;
  44916. }
  44917. });
  44918. }
  44919. function preprocessForSpecifiedCategory(thisOption) {
  44920. // Hash categories.
  44921. var categories = thisOption.categories;
  44922. var visual = thisOption.visual;
  44923. var categoryMap = thisOption.categoryMap = {};
  44924. each$9(categories, function (cate, index) {
  44925. categoryMap[cate] = index;
  44926. });
  44927. // Process visual map input.
  44928. if (!isArray(visual)) {
  44929. var visualArr = [];
  44930. if (isObject$1(visual)) {
  44931. each$9(visual, function (v, cate) {
  44932. var index = categoryMap[cate];
  44933. visualArr[index != null ? index : CATEGORY_DEFAULT_VISUAL_INDEX] = v;
  44934. });
  44935. }
  44936. else { // Is primary type, represents default visual.
  44937. visualArr[CATEGORY_DEFAULT_VISUAL_INDEX] = visual;
  44938. }
  44939. visual = setVisualToOption(thisOption, visualArr);
  44940. }
  44941. // Remove categories that has no visual,
  44942. // then we can mapping them to CATEGORY_DEFAULT_VISUAL_INDEX.
  44943. for (var i = categories.length - 1; i >= 0; i--) {
  44944. if (visual[i] == null) {
  44945. delete categoryMap[categories[i]];
  44946. categories.pop();
  44947. }
  44948. }
  44949. }
  44950. function normalizeVisualRange(thisOption, isCategory) {
  44951. var visual = thisOption.visual;
  44952. var visualArr = [];
  44953. if (isObject$1(visual)) {
  44954. each$9(visual, function (v) {
  44955. visualArr.push(v);
  44956. });
  44957. }
  44958. else if (visual != null) {
  44959. visualArr.push(visual);
  44960. }
  44961. var doNotNeedPair = {color: 1, symbol: 1};
  44962. if (!isCategory
  44963. && visualArr.length === 1
  44964. && !doNotNeedPair.hasOwnProperty(thisOption.type)
  44965. ) {
  44966. // Do not care visualArr.length === 0, which is illegal.
  44967. visualArr[1] = visualArr[0];
  44968. }
  44969. setVisualToOption(thisOption, visualArr);
  44970. }
  44971. function makePartialColorVisualHandler(applyValue) {
  44972. return {
  44973. applyVisual: function (value, getter, setter) {
  44974. value = this.mapValueToVisual(value);
  44975. // Must not be array value
  44976. setter('color', applyValue(getter('color'), value));
  44977. },
  44978. _doMap: makeDoMap([0, 1])
  44979. };
  44980. }
  44981. function doMapToArray(normalized) {
  44982. var visual = this.option.visual;
  44983. return visual[
  44984. Math.round(linearMap(normalized, [0, 1], [0, visual.length - 1], true))
  44985. ] || {};
  44986. }
  44987. function makeApplyVisual(visualType) {
  44988. return function (value, getter, setter) {
  44989. setter(visualType, this.mapValueToVisual(value));
  44990. };
  44991. }
  44992. function doMapCategory(normalized) {
  44993. var visual = this.option.visual;
  44994. return visual[
  44995. (this.option.loop && normalized !== CATEGORY_DEFAULT_VISUAL_INDEX)
  44996. ? normalized % visual.length
  44997. : normalized
  44998. ];
  44999. }
  45000. function doMapFixed() {
  45001. return this.option.visual[0];
  45002. }
  45003. function makeDoMap(sourceExtent) {
  45004. return {
  45005. linear: function (normalized) {
  45006. return linearMap(normalized, sourceExtent, this.option.visual, true);
  45007. },
  45008. category: doMapCategory,
  45009. piecewise: function (normalized, value) {
  45010. var result = getSpecifiedVisual.call(this, value);
  45011. if (result == null) {
  45012. result = linearMap(normalized, sourceExtent, this.option.visual, true);
  45013. }
  45014. return result;
  45015. },
  45016. fixed: doMapFixed
  45017. };
  45018. }
  45019. function getSpecifiedVisual(value) {
  45020. var thisOption = this.option;
  45021. var pieceList = thisOption.pieceList;
  45022. if (thisOption.hasSpecialVisual) {
  45023. var pieceIndex = VisualMapping.findPieceIndex(value, pieceList);
  45024. var piece = pieceList[pieceIndex];
  45025. if (piece && piece.visual) {
  45026. return piece.visual[this.type];
  45027. }
  45028. }
  45029. }
  45030. function setVisualToOption(thisOption, visualArr) {
  45031. thisOption.visual = visualArr;
  45032. if (thisOption.type === 'color') {
  45033. thisOption.parsedVisual = map(visualArr, function (item) {
  45034. return parse(item);
  45035. });
  45036. }
  45037. return visualArr;
  45038. }
  45039. /**
  45040. * Normalizers by mapping methods.
  45041. */
  45042. var normalizers = {
  45043. linear: function (value) {
  45044. return linearMap(value, this.option.dataExtent, [0, 1], true);
  45045. },
  45046. piecewise: function (value) {
  45047. var pieceList = this.option.pieceList;
  45048. var pieceIndex = VisualMapping.findPieceIndex(value, pieceList, true);
  45049. if (pieceIndex != null) {
  45050. return linearMap(pieceIndex, [0, pieceList.length - 1], [0, 1], true);
  45051. }
  45052. },
  45053. category: function (value) {
  45054. var index = this.option.categories
  45055. ? this.option.categoryMap[value]
  45056. : value; // ordinal
  45057. return index == null ? CATEGORY_DEFAULT_VISUAL_INDEX : index;
  45058. },
  45059. fixed: noop
  45060. };
  45061. /**
  45062. * List available visual types.
  45063. *
  45064. * @public
  45065. * @return {Array.<string>}
  45066. */
  45067. VisualMapping.listVisualTypes = function () {
  45068. var visualTypes = [];
  45069. each$1(visualHandlers, function (handler, key) {
  45070. visualTypes.push(key);
  45071. });
  45072. return visualTypes;
  45073. };
  45074. /**
  45075. * @public
  45076. */
  45077. VisualMapping.addVisualHandler = function (name, handler) {
  45078. visualHandlers[name] = handler;
  45079. };
  45080. /**
  45081. * @public
  45082. */
  45083. VisualMapping.isValidType = function (visualType) {
  45084. return visualHandlers.hasOwnProperty(visualType);
  45085. };
  45086. /**
  45087. * Convinent method.
  45088. * Visual can be Object or Array or primary type.
  45089. *
  45090. * @public
  45091. */
  45092. VisualMapping.eachVisual = function (visual, callback, context) {
  45093. if (isObject$1(visual)) {
  45094. each$1(visual, callback, context);
  45095. }
  45096. else {
  45097. callback.call(context, visual);
  45098. }
  45099. };
  45100. VisualMapping.mapVisual = function (visual, callback, context) {
  45101. var isPrimary;
  45102. var newVisual = isArray(visual)
  45103. ? []
  45104. : isObject$1(visual)
  45105. ? {}
  45106. : (isPrimary = true, null);
  45107. VisualMapping.eachVisual(visual, function (v, key) {
  45108. var newVal = callback.call(context, v, key);
  45109. isPrimary ? (newVisual = newVal) : (newVisual[key] = newVal);
  45110. });
  45111. return newVisual;
  45112. };
  45113. /**
  45114. * @public
  45115. * @param {Object} obj
  45116. * @return {Object} new object containers visual values.
  45117. * If no visuals, return null.
  45118. */
  45119. VisualMapping.retrieveVisuals = function (obj) {
  45120. var ret = {};
  45121. var hasVisual;
  45122. obj && each$9(visualHandlers, function (h, visualType) {
  45123. if (obj.hasOwnProperty(visualType)) {
  45124. ret[visualType] = obj[visualType];
  45125. hasVisual = true;
  45126. }
  45127. });
  45128. return hasVisual ? ret : null;
  45129. };
  45130. /**
  45131. * Give order to visual types, considering colorSaturation, colorAlpha depends on color.
  45132. *
  45133. * @public
  45134. * @param {(Object|Array)} visualTypes If Object, like: {color: ..., colorSaturation: ...}
  45135. * IF Array, like: ['color', 'symbol', 'colorSaturation']
  45136. * @return {Array.<string>} Sorted visual types.
  45137. */
  45138. VisualMapping.prepareVisualTypes = function (visualTypes) {
  45139. if (isObject$5(visualTypes)) {
  45140. var types = [];
  45141. each$9(visualTypes, function (item, type) {
  45142. types.push(type);
  45143. });
  45144. visualTypes = types;
  45145. }
  45146. else if (isArray(visualTypes)) {
  45147. visualTypes = visualTypes.slice();
  45148. }
  45149. else {
  45150. return [];
  45151. }
  45152. visualTypes.sort(function (type1, type2) {
  45153. // color should be front of colorSaturation, colorAlpha, ...
  45154. // symbol and symbolSize do not matter.
  45155. return (type2 === 'color' && type1 !== 'color' && type1.indexOf('color') === 0)
  45156. ? 1 : -1;
  45157. });
  45158. return visualTypes;
  45159. };
  45160. /**
  45161. * 'color', 'colorSaturation', 'colorAlpha', ... are depends on 'color'.
  45162. * Other visuals are only depends on themself.
  45163. *
  45164. * @public
  45165. * @param {string} visualType1
  45166. * @param {string} visualType2
  45167. * @return {boolean}
  45168. */
  45169. VisualMapping.dependsOn = function (visualType1, visualType2) {
  45170. return visualType2 === 'color'
  45171. ? !!(visualType1 && visualType1.indexOf(visualType2) === 0)
  45172. : visualType1 === visualType2;
  45173. };
  45174. /**
  45175. * @param {number} value
  45176. * @param {Array.<Object>} pieceList [{value: ..., interval: [min, max]}, ...]
  45177. * Always from small to big.
  45178. * @param {boolean} [findClosestWhenOutside=false]
  45179. * @return {number} index
  45180. */
  45181. VisualMapping.findPieceIndex = function (value, pieceList, findClosestWhenOutside) {
  45182. var possibleI;
  45183. var abs = Infinity;
  45184. // value has the higher priority.
  45185. for (var i = 0, len = pieceList.length; i < len; i++) {
  45186. var pieceValue = pieceList[i].value;
  45187. if (pieceValue != null) {
  45188. if (pieceValue === value
  45189. // FIXME
  45190. // It is supposed to compare value according to value type of dimension,
  45191. // but currently value type can exactly be string or number.
  45192. // Compromise for numeric-like string (like '12'), especially
  45193. // in the case that visualMap.categories is ['22', '33'].
  45194. || (typeof pieceValue === 'string' && pieceValue === value + '')
  45195. ) {
  45196. return i;
  45197. }
  45198. findClosestWhenOutside && updatePossible(pieceValue, i);
  45199. }
  45200. }
  45201. for (var i = 0, len = pieceList.length; i < len; i++) {
  45202. var piece = pieceList[i];
  45203. var interval = piece.interval;
  45204. var close = piece.close;
  45205. if (interval) {
  45206. if (interval[0] === -Infinity) {
  45207. if (littleThan(close[1], value, interval[1])) {
  45208. return i;
  45209. }
  45210. }
  45211. else if (interval[1] === Infinity) {
  45212. if (littleThan(close[0], interval[0], value)) {
  45213. return i;
  45214. }
  45215. }
  45216. else if (
  45217. littleThan(close[0], interval[0], value)
  45218. && littleThan(close[1], value, interval[1])
  45219. ) {
  45220. return i;
  45221. }
  45222. findClosestWhenOutside && updatePossible(interval[0], i);
  45223. findClosestWhenOutside && updatePossible(interval[1], i);
  45224. }
  45225. }
  45226. if (findClosestWhenOutside) {
  45227. return value === Infinity
  45228. ? pieceList.length - 1
  45229. : value === -Infinity
  45230. ? 0
  45231. : possibleI;
  45232. }
  45233. function updatePossible(val, index) {
  45234. var newAbs = Math.abs(val - value);
  45235. if (newAbs < abs) {
  45236. abs = newAbs;
  45237. possibleI = index;
  45238. }
  45239. }
  45240. };
  45241. function littleThan(close, a, b) {
  45242. return close ? a <= b : a < b;
  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. var isArray$2 = isArray;
  45263. var ITEM_STYLE_NORMAL = 'itemStyle';
  45264. var treemapVisual = {
  45265. seriesType: 'treemap',
  45266. reset: function (seriesModel, ecModel, api, payload) {
  45267. var tree = seriesModel.getData().tree;
  45268. var root = tree.root;
  45269. var seriesItemStyleModel = seriesModel.getModel(ITEM_STYLE_NORMAL);
  45270. if (root.isRemoved()) {
  45271. return;
  45272. }
  45273. var levelItemStyles = map(tree.levelModels, function (levelModel) {
  45274. return levelModel ? levelModel.get(ITEM_STYLE_NORMAL) : null;
  45275. });
  45276. travelTree(
  45277. root, // Visual should calculate from tree root but not view root.
  45278. {},
  45279. levelItemStyles,
  45280. seriesItemStyleModel,
  45281. seriesModel.getViewRoot().getAncestors(),
  45282. seriesModel
  45283. );
  45284. }
  45285. };
  45286. function travelTree(
  45287. node, designatedVisual, levelItemStyles, seriesItemStyleModel,
  45288. viewRootAncestors, seriesModel
  45289. ) {
  45290. var nodeModel = node.getModel();
  45291. var nodeLayout = node.getLayout();
  45292. // Optimize
  45293. if (!nodeLayout || nodeLayout.invisible || !nodeLayout.isInView) {
  45294. return;
  45295. }
  45296. var nodeItemStyleModel = node.getModel(ITEM_STYLE_NORMAL);
  45297. var levelItemStyle = levelItemStyles[node.depth];
  45298. var visuals = buildVisuals(
  45299. nodeItemStyleModel, designatedVisual, levelItemStyle, seriesItemStyleModel
  45300. );
  45301. // calculate border color
  45302. var borderColor = nodeItemStyleModel.get('borderColor');
  45303. var borderColorSaturation = nodeItemStyleModel.get('borderColorSaturation');
  45304. var thisNodeColor;
  45305. if (borderColorSaturation != null) {
  45306. // For performance, do not always execute 'calculateColor'.
  45307. thisNodeColor = calculateColor(visuals, node);
  45308. borderColor = calculateBorderColor(borderColorSaturation, thisNodeColor);
  45309. }
  45310. node.setVisual('borderColor', borderColor);
  45311. var viewChildren = node.viewChildren;
  45312. if (!viewChildren || !viewChildren.length) {
  45313. thisNodeColor = calculateColor(visuals, node);
  45314. // Apply visual to this node.
  45315. node.setVisual('color', thisNodeColor);
  45316. }
  45317. else {
  45318. var mapping = buildVisualMapping(
  45319. node, nodeModel, nodeLayout, nodeItemStyleModel, visuals, viewChildren
  45320. );
  45321. // Designate visual to children.
  45322. each$1(viewChildren, function (child, index) {
  45323. // If higher than viewRoot, only ancestors of viewRoot is needed to visit.
  45324. if (child.depth >= viewRootAncestors.length
  45325. || child === viewRootAncestors[child.depth]
  45326. ) {
  45327. var childVisual = mapVisual$1(
  45328. nodeModel, visuals, child, index, mapping, seriesModel
  45329. );
  45330. travelTree(
  45331. child, childVisual, levelItemStyles, seriesItemStyleModel,
  45332. viewRootAncestors, seriesModel
  45333. );
  45334. }
  45335. });
  45336. }
  45337. }
  45338. function buildVisuals(
  45339. nodeItemStyleModel, designatedVisual, levelItemStyle, seriesItemStyleModel
  45340. ) {
  45341. var visuals = extend({}, designatedVisual);
  45342. each$1(['color', 'colorAlpha', 'colorSaturation'], function (visualName) {
  45343. // Priority: thisNode > thisLevel > parentNodeDesignated > seriesModel
  45344. var val = nodeItemStyleModel.get(visualName, true); // Ignore parent
  45345. val == null && levelItemStyle && (val = levelItemStyle[visualName]);
  45346. val == null && (val = designatedVisual[visualName]);
  45347. val == null && (val = seriesItemStyleModel.get(visualName));
  45348. val != null && (visuals[visualName] = val);
  45349. });
  45350. return visuals;
  45351. }
  45352. function calculateColor(visuals) {
  45353. var color = getValueVisualDefine(visuals, 'color');
  45354. if (color) {
  45355. var colorAlpha = getValueVisualDefine(visuals, 'colorAlpha');
  45356. var colorSaturation = getValueVisualDefine(visuals, 'colorSaturation');
  45357. if (colorSaturation) {
  45358. color = modifyHSL(color, null, null, colorSaturation);
  45359. }
  45360. if (colorAlpha) {
  45361. color = modifyAlpha(color, colorAlpha);
  45362. }
  45363. return color;
  45364. }
  45365. }
  45366. function calculateBorderColor(borderColorSaturation, thisNodeColor) {
  45367. return thisNodeColor != null
  45368. ? modifyHSL(thisNodeColor, null, null, borderColorSaturation)
  45369. : null;
  45370. }
  45371. function getValueVisualDefine(visuals, name) {
  45372. var value = visuals[name];
  45373. if (value != null && value !== 'none') {
  45374. return value;
  45375. }
  45376. }
  45377. function buildVisualMapping(
  45378. node, nodeModel, nodeLayout, nodeItemStyleModel, visuals, viewChildren
  45379. ) {
  45380. if (!viewChildren || !viewChildren.length) {
  45381. return;
  45382. }
  45383. var rangeVisual = getRangeVisual(nodeModel, 'color')
  45384. || (
  45385. visuals.color != null
  45386. && visuals.color !== 'none'
  45387. && (
  45388. getRangeVisual(nodeModel, 'colorAlpha')
  45389. || getRangeVisual(nodeModel, 'colorSaturation')
  45390. )
  45391. );
  45392. if (!rangeVisual) {
  45393. return;
  45394. }
  45395. var visualMin = nodeModel.get('visualMin');
  45396. var visualMax = nodeModel.get('visualMax');
  45397. var dataExtent = nodeLayout.dataExtent.slice();
  45398. visualMin != null && visualMin < dataExtent[0] && (dataExtent[0] = visualMin);
  45399. visualMax != null && visualMax > dataExtent[1] && (dataExtent[1] = visualMax);
  45400. var colorMappingBy = nodeModel.get('colorMappingBy');
  45401. var opt = {
  45402. type: rangeVisual.name,
  45403. dataExtent: dataExtent,
  45404. visual: rangeVisual.range
  45405. };
  45406. if (opt.type === 'color'
  45407. && (colorMappingBy === 'index' || colorMappingBy === 'id')
  45408. ) {
  45409. opt.mappingMethod = 'category';
  45410. opt.loop = true;
  45411. // categories is ordinal, so do not set opt.categories.
  45412. }
  45413. else {
  45414. opt.mappingMethod = 'linear';
  45415. }
  45416. var mapping = new VisualMapping(opt);
  45417. mapping.__drColorMappingBy = colorMappingBy;
  45418. return mapping;
  45419. }
  45420. // Notice: If we dont have the attribute 'colorRange', but only use
  45421. // attribute 'color' to represent both concepts of 'colorRange' and 'color',
  45422. // (It means 'colorRange' when 'color' is Array, means 'color' when not array),
  45423. // this problem will be encountered:
  45424. // If a level-1 node dont have children, and its siblings has children,
  45425. // and colorRange is set on level-1, then the node can not be colored.
  45426. // So we separate 'colorRange' and 'color' to different attributes.
  45427. function getRangeVisual(nodeModel, name) {
  45428. // 'colorRange', 'colorARange', 'colorSRange'.
  45429. // If not exsits on this node, fetch from levels and series.
  45430. var range = nodeModel.get(name);
  45431. return (isArray$2(range) && range.length) ? {name: name, range: range} : null;
  45432. }
  45433. function mapVisual$1(nodeModel, visuals, child, index, mapping, seriesModel) {
  45434. var childVisuals = extend({}, visuals);
  45435. if (mapping) {
  45436. var mappingType = mapping.type;
  45437. var colorMappingBy = mappingType === 'color' && mapping.__drColorMappingBy;
  45438. var value = colorMappingBy === 'index'
  45439. ? index
  45440. : colorMappingBy === 'id'
  45441. ? seriesModel.mapIdToIndex(child.getId())
  45442. : child.getValue(nodeModel.get('visualDimension'));
  45443. childVisuals[mappingType] = mapping.mapValueToVisual(value);
  45444. }
  45445. return childVisuals;
  45446. }
  45447. /*
  45448. * Licensed to the Apache Software Foundation (ASF) under one
  45449. * or more contributor license agreements. See the NOTICE file
  45450. * distributed with this work for additional information
  45451. * regarding copyright ownership. The ASF licenses this file
  45452. * to you under the Apache License, Version 2.0 (the
  45453. * "License"); you may not use this file except in compliance
  45454. * with the License. You may obtain a copy of the License at
  45455. *
  45456. * http://www.apache.org/licenses/LICENSE-2.0
  45457. *
  45458. * Unless required by applicable law or agreed to in writing,
  45459. * software distributed under the License is distributed on an
  45460. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45461. * KIND, either express or implied. See the License for the
  45462. * specific language governing permissions and limitations
  45463. * under the License.
  45464. */
  45465. /*
  45466. * A third-party license is embeded for some of the code in this file:
  45467. * The treemap layout implementation was originally copied from
  45468. * "d3.js" with some modifications made for this project.
  45469. * (See more details in the comment of the method "squarify" below.)
  45470. * The use of the source code of this file is also subject to the terms
  45471. * and consitions of the license of "d3.js" (BSD-3Clause, see
  45472. * </licenses/LICENSE-d3>).
  45473. */
  45474. var mathMax$4 = Math.max;
  45475. var mathMin$4 = Math.min;
  45476. var retrieveValue = retrieve;
  45477. var each$10 = each$1;
  45478. var PATH_BORDER_WIDTH = ['itemStyle', 'borderWidth'];
  45479. var PATH_GAP_WIDTH = ['itemStyle', 'gapWidth'];
  45480. var PATH_UPPER_LABEL_SHOW = ['upperLabel', 'show'];
  45481. var PATH_UPPER_LABEL_HEIGHT = ['upperLabel', 'height'];
  45482. /**
  45483. * @public
  45484. */
  45485. var treemapLayout = {
  45486. seriesType: 'treemap',
  45487. reset: function (seriesModel, ecModel, api, payload) {
  45488. // Layout result in each node:
  45489. // {x, y, width, height, area, borderWidth}
  45490. var ecWidth = api.getWidth();
  45491. var ecHeight = api.getHeight();
  45492. var seriesOption = seriesModel.option;
  45493. var layoutInfo = getLayoutRect(
  45494. seriesModel.getBoxLayoutParams(),
  45495. {
  45496. width: api.getWidth(),
  45497. height: api.getHeight()
  45498. }
  45499. );
  45500. var size = seriesOption.size || []; // Compatible with ec2.
  45501. var containerWidth = parsePercent$1(
  45502. retrieveValue(layoutInfo.width, size[0]),
  45503. ecWidth
  45504. );
  45505. var containerHeight = parsePercent$1(
  45506. retrieveValue(layoutInfo.height, size[1]),
  45507. ecHeight
  45508. );
  45509. // Fetch payload info.
  45510. var payloadType = payload && payload.type;
  45511. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  45512. var targetInfo = retrieveTargetInfo(payload, types, seriesModel);
  45513. var rootRect = (payloadType === 'treemapRender' || payloadType === 'treemapMove')
  45514. ? payload.rootRect : null;
  45515. var viewRoot = seriesModel.getViewRoot();
  45516. var viewAbovePath = getPathToRoot(viewRoot);
  45517. if (payloadType !== 'treemapMove') {
  45518. var rootSize = payloadType === 'treemapZoomToNode'
  45519. ? estimateRootSize(
  45520. seriesModel, targetInfo, viewRoot, containerWidth, containerHeight
  45521. )
  45522. : rootRect
  45523. ? [rootRect.width, rootRect.height]
  45524. : [containerWidth, containerHeight];
  45525. var sort = seriesOption.sort;
  45526. if (sort && sort !== 'asc' && sort !== 'desc') {
  45527. sort = 'desc';
  45528. }
  45529. var options = {
  45530. squareRatio: seriesOption.squareRatio,
  45531. sort: sort,
  45532. leafDepth: seriesOption.leafDepth
  45533. };
  45534. // layout should be cleared because using updateView but not update.
  45535. viewRoot.hostTree.clearLayouts();
  45536. // TODO
  45537. // optimize: if out of view clip, do not layout.
  45538. // But take care that if do not render node out of view clip,
  45539. // how to calculate start po
  45540. var viewRootLayout = {
  45541. x: 0, y: 0,
  45542. width: rootSize[0], height: rootSize[1],
  45543. area: rootSize[0] * rootSize[1]
  45544. };
  45545. viewRoot.setLayout(viewRootLayout);
  45546. squarify(viewRoot, options, false, 0);
  45547. // Supplement layout.
  45548. var viewRootLayout = viewRoot.getLayout();
  45549. each$10(viewAbovePath, function (node, index) {
  45550. var childValue = (viewAbovePath[index + 1] || viewRoot).getValue();
  45551. node.setLayout(extend(
  45552. {dataExtent: [childValue, childValue], borderWidth: 0, upperHeight: 0},
  45553. viewRootLayout
  45554. ));
  45555. });
  45556. }
  45557. var treeRoot = seriesModel.getData().tree.root;
  45558. treeRoot.setLayout(
  45559. calculateRootPosition(layoutInfo, rootRect, targetInfo),
  45560. true
  45561. );
  45562. seriesModel.setLayoutInfo(layoutInfo);
  45563. // FIXME
  45564. // 现在没有clip功能,暂时取ec高宽。
  45565. prunning(
  45566. treeRoot,
  45567. // Transform to base element coordinate system.
  45568. new BoundingRect(-layoutInfo.x, -layoutInfo.y, ecWidth, ecHeight),
  45569. viewAbovePath,
  45570. viewRoot,
  45571. 0
  45572. );
  45573. }
  45574. };
  45575. /**
  45576. * Layout treemap with squarify algorithm.
  45577. * The original presentation of this algorithm
  45578. * was made by Mark Bruls, Kees Huizing, and Jarke J. van Wijk
  45579. * <https://graphics.ethz.ch/teaching/scivis_common/Literature/squarifiedTreeMaps.pdf>.
  45580. * The implementation of this algorithm was originally copied from "d3.js"
  45581. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/layout/treemap.js>
  45582. * with some modifications made for this program.
  45583. * See the license statement at the head of this file.
  45584. *
  45585. * @protected
  45586. * @param {module:echarts/data/Tree~TreeNode} node
  45587. * @param {Object} options
  45588. * @param {string} options.sort 'asc' or 'desc'
  45589. * @param {number} options.squareRatio
  45590. * @param {boolean} hideChildren
  45591. * @param {number} depth
  45592. */
  45593. function squarify(node, options, hideChildren, depth) {
  45594. var width;
  45595. var height;
  45596. if (node.isRemoved()) {
  45597. return;
  45598. }
  45599. var thisLayout = node.getLayout();
  45600. width = thisLayout.width;
  45601. height = thisLayout.height;
  45602. // Considering border and gap
  45603. var nodeModel = node.getModel();
  45604. var borderWidth = nodeModel.get(PATH_BORDER_WIDTH);
  45605. var halfGapWidth = nodeModel.get(PATH_GAP_WIDTH) / 2;
  45606. var upperLabelHeight = getUpperLabelHeight(nodeModel);
  45607. var upperHeight = Math.max(borderWidth, upperLabelHeight);
  45608. var layoutOffset = borderWidth - halfGapWidth;
  45609. var layoutOffsetUpper = upperHeight - halfGapWidth;
  45610. var nodeModel = node.getModel();
  45611. node.setLayout({
  45612. borderWidth: borderWidth,
  45613. upperHeight: upperHeight,
  45614. upperLabelHeight: upperLabelHeight
  45615. }, true);
  45616. width = mathMax$4(width - 2 * layoutOffset, 0);
  45617. height = mathMax$4(height - layoutOffset - layoutOffsetUpper, 0);
  45618. var totalArea = width * height;
  45619. var viewChildren = initChildren(
  45620. node, nodeModel, totalArea, options, hideChildren, depth
  45621. );
  45622. if (!viewChildren.length) {
  45623. return;
  45624. }
  45625. var rect = {x: layoutOffset, y: layoutOffsetUpper, width: width, height: height};
  45626. var rowFixedLength = mathMin$4(width, height);
  45627. var best = Infinity; // the best row score so far
  45628. var row = [];
  45629. row.area = 0;
  45630. for (var i = 0, len = viewChildren.length; i < len;) {
  45631. var child = viewChildren[i];
  45632. row.push(child);
  45633. row.area += child.getLayout().area;
  45634. var score = worst(row, rowFixedLength, options.squareRatio);
  45635. // continue with this orientation
  45636. if (score <= best) {
  45637. i++;
  45638. best = score;
  45639. }
  45640. // abort, and try a different orientation
  45641. else {
  45642. row.area -= row.pop().getLayout().area;
  45643. position(row, rowFixedLength, rect, halfGapWidth, false);
  45644. rowFixedLength = mathMin$4(rect.width, rect.height);
  45645. row.length = row.area = 0;
  45646. best = Infinity;
  45647. }
  45648. }
  45649. if (row.length) {
  45650. position(row, rowFixedLength, rect, halfGapWidth, true);
  45651. }
  45652. if (!hideChildren) {
  45653. var childrenVisibleMin = nodeModel.get('childrenVisibleMin');
  45654. if (childrenVisibleMin != null && totalArea < childrenVisibleMin) {
  45655. hideChildren = true;
  45656. }
  45657. }
  45658. for (var i = 0, len = viewChildren.length; i < len; i++) {
  45659. squarify(viewChildren[i], options, hideChildren, depth + 1);
  45660. }
  45661. }
  45662. /**
  45663. * Set area to each child, and calculate data extent for visual coding.
  45664. */
  45665. function initChildren(node, nodeModel, totalArea, options, hideChildren, depth) {
  45666. var viewChildren = node.children || [];
  45667. var orderBy = options.sort;
  45668. orderBy !== 'asc' && orderBy !== 'desc' && (orderBy = null);
  45669. var overLeafDepth = options.leafDepth != null && options.leafDepth <= depth;
  45670. // leafDepth has higher priority.
  45671. if (hideChildren && !overLeafDepth) {
  45672. return (node.viewChildren = []);
  45673. }
  45674. // Sort children, order by desc.
  45675. viewChildren = filter(viewChildren, function (child) {
  45676. return !child.isRemoved();
  45677. });
  45678. sort$1(viewChildren, orderBy);
  45679. var info = statistic(nodeModel, viewChildren, orderBy);
  45680. if (info.sum === 0) {
  45681. return (node.viewChildren = []);
  45682. }
  45683. info.sum = filterByThreshold(nodeModel, totalArea, info.sum, orderBy, viewChildren);
  45684. if (info.sum === 0) {
  45685. return (node.viewChildren = []);
  45686. }
  45687. // Set area to each child.
  45688. for (var i = 0, len = viewChildren.length; i < len; i++) {
  45689. var area = viewChildren[i].getValue() / info.sum * totalArea;
  45690. // Do not use setLayout({...}, true), because it is needed to clear last layout.
  45691. viewChildren[i].setLayout({area: area});
  45692. }
  45693. if (overLeafDepth) {
  45694. viewChildren.length && node.setLayout({isLeafRoot: true}, true);
  45695. viewChildren.length = 0;
  45696. }
  45697. node.viewChildren = viewChildren;
  45698. node.setLayout({dataExtent: info.dataExtent}, true);
  45699. return viewChildren;
  45700. }
  45701. /**
  45702. * Consider 'visibleMin'. Modify viewChildren and get new sum.
  45703. */
  45704. function filterByThreshold(nodeModel, totalArea, sum, orderBy, orderedChildren) {
  45705. // visibleMin is not supported yet when no option.sort.
  45706. if (!orderBy) {
  45707. return sum;
  45708. }
  45709. var visibleMin = nodeModel.get('visibleMin');
  45710. var len = orderedChildren.length;
  45711. var deletePoint = len;
  45712. // Always travel from little value to big value.
  45713. for (var i = len - 1; i >= 0; i--) {
  45714. var value = orderedChildren[
  45715. orderBy === 'asc' ? len - i - 1 : i
  45716. ].getValue();
  45717. if (value / sum * totalArea < visibleMin) {
  45718. deletePoint = i;
  45719. sum -= value;
  45720. }
  45721. }
  45722. orderBy === 'asc'
  45723. ? orderedChildren.splice(0, len - deletePoint)
  45724. : orderedChildren.splice(deletePoint, len - deletePoint);
  45725. return sum;
  45726. }
  45727. /**
  45728. * Sort
  45729. */
  45730. function sort$1(viewChildren, orderBy) {
  45731. if (orderBy) {
  45732. viewChildren.sort(function (a, b) {
  45733. var diff = orderBy === 'asc'
  45734. ? a.getValue() - b.getValue() : b.getValue() - a.getValue();
  45735. return diff === 0
  45736. ? (orderBy === 'asc'
  45737. ? a.dataIndex - b.dataIndex : b.dataIndex - a.dataIndex
  45738. )
  45739. : diff;
  45740. });
  45741. }
  45742. return viewChildren;
  45743. }
  45744. /**
  45745. * Statistic
  45746. */
  45747. function statistic(nodeModel, children, orderBy) {
  45748. // Calculate sum.
  45749. var sum = 0;
  45750. for (var i = 0, len = children.length; i < len; i++) {
  45751. sum += children[i].getValue();
  45752. }
  45753. // Statistic data extent for latter visual coding.
  45754. // Notice: data extent should be calculate based on raw children
  45755. // but not filtered view children, otherwise visual mapping will not
  45756. // be stable when zoom (where children is filtered by visibleMin).
  45757. var dimension = nodeModel.get('visualDimension');
  45758. var dataExtent;
  45759. // The same as area dimension.
  45760. if (!children || !children.length) {
  45761. dataExtent = [NaN, NaN];
  45762. }
  45763. else if (dimension === 'value' && orderBy) {
  45764. dataExtent = [
  45765. children[children.length - 1].getValue(),
  45766. children[0].getValue()
  45767. ];
  45768. orderBy === 'asc' && dataExtent.reverse();
  45769. }
  45770. // Other dimension.
  45771. else {
  45772. var dataExtent = [Infinity, -Infinity];
  45773. each$10(children, function (child) {
  45774. var value = child.getValue(dimension);
  45775. value < dataExtent[0] && (dataExtent[0] = value);
  45776. value > dataExtent[1] && (dataExtent[1] = value);
  45777. });
  45778. }
  45779. return {sum: sum, dataExtent: dataExtent};
  45780. }
  45781. /**
  45782. * Computes the score for the specified row,
  45783. * as the worst aspect ratio.
  45784. */
  45785. function worst(row, rowFixedLength, ratio) {
  45786. var areaMax = 0;
  45787. var areaMin = Infinity;
  45788. for (var i = 0, area, len = row.length; i < len; i++) {
  45789. area = row[i].getLayout().area;
  45790. if (area) {
  45791. area < areaMin && (areaMin = area);
  45792. area > areaMax && (areaMax = area);
  45793. }
  45794. }
  45795. var squareArea = row.area * row.area;
  45796. var f = rowFixedLength * rowFixedLength * ratio;
  45797. return squareArea
  45798. ? mathMax$4(
  45799. (f * areaMax) / squareArea,
  45800. squareArea / (f * areaMin)
  45801. )
  45802. : Infinity;
  45803. }
  45804. /**
  45805. * Positions the specified row of nodes. Modifies `rect`.
  45806. */
  45807. function position(row, rowFixedLength, rect, halfGapWidth, flush) {
  45808. // When rowFixedLength === rect.width,
  45809. // it is horizontal subdivision,
  45810. // rowFixedLength is the width of the subdivision,
  45811. // rowOtherLength is the height of the subdivision,
  45812. // and nodes will be positioned from left to right.
  45813. // wh[idx0WhenH] means: when horizontal,
  45814. // wh[idx0WhenH] => wh[0] => 'width'.
  45815. // xy[idx1WhenH] => xy[1] => 'y'.
  45816. var idx0WhenH = rowFixedLength === rect.width ? 0 : 1;
  45817. var idx1WhenH = 1 - idx0WhenH;
  45818. var xy = ['x', 'y'];
  45819. var wh = ['width', 'height'];
  45820. var last = rect[xy[idx0WhenH]];
  45821. var rowOtherLength = rowFixedLength
  45822. ? row.area / rowFixedLength : 0;
  45823. if (flush || rowOtherLength > rect[wh[idx1WhenH]]) {
  45824. rowOtherLength = rect[wh[idx1WhenH]]; // over+underflow
  45825. }
  45826. for (var i = 0, rowLen = row.length; i < rowLen; i++) {
  45827. var node = row[i];
  45828. var nodeLayout = {};
  45829. var step = rowOtherLength
  45830. ? node.getLayout().area / rowOtherLength : 0;
  45831. var wh1 = nodeLayout[wh[idx1WhenH]] = mathMax$4(rowOtherLength - 2 * halfGapWidth, 0);
  45832. // We use Math.max/min to avoid negative width/height when considering gap width.
  45833. var remain = rect[xy[idx0WhenH]] + rect[wh[idx0WhenH]] - last;
  45834. var modWH = (i === rowLen - 1 || remain < step) ? remain : step;
  45835. var wh0 = nodeLayout[wh[idx0WhenH]] = mathMax$4(modWH - 2 * halfGapWidth, 0);
  45836. nodeLayout[xy[idx1WhenH]] = rect[xy[idx1WhenH]] + mathMin$4(halfGapWidth, wh1 / 2);
  45837. nodeLayout[xy[idx0WhenH]] = last + mathMin$4(halfGapWidth, wh0 / 2);
  45838. last += modWH;
  45839. node.setLayout(nodeLayout, true);
  45840. }
  45841. rect[xy[idx1WhenH]] += rowOtherLength;
  45842. rect[wh[idx1WhenH]] -= rowOtherLength;
  45843. }
  45844. // Return [containerWidth, containerHeight] as defualt.
  45845. function estimateRootSize(seriesModel, targetInfo, viewRoot, containerWidth, containerHeight) {
  45846. // If targetInfo.node exists, we zoom to the node,
  45847. // so estimate whold width and heigth by target node.
  45848. var currNode = (targetInfo || {}).node;
  45849. var defaultSize = [containerWidth, containerHeight];
  45850. if (!currNode || currNode === viewRoot) {
  45851. return defaultSize;
  45852. }
  45853. var parent;
  45854. var viewArea = containerWidth * containerHeight;
  45855. var area = viewArea * seriesModel.option.zoomToNodeRatio;
  45856. while (parent = currNode.parentNode) { // jshint ignore:line
  45857. var sum = 0;
  45858. var siblings = parent.children;
  45859. for (var i = 0, len = siblings.length; i < len; i++) {
  45860. sum += siblings[i].getValue();
  45861. }
  45862. var currNodeValue = currNode.getValue();
  45863. if (currNodeValue === 0) {
  45864. return defaultSize;
  45865. }
  45866. area *= sum / currNodeValue;
  45867. // Considering border, suppose aspect ratio is 1.
  45868. var parentModel = parent.getModel();
  45869. var borderWidth = parentModel.get(PATH_BORDER_WIDTH);
  45870. var upperHeight = Math.max(borderWidth, getUpperLabelHeight(parentModel, borderWidth));
  45871. area += 4 * borderWidth * borderWidth
  45872. + (3 * borderWidth + upperHeight) * Math.pow(area, 0.5);
  45873. area > MAX_SAFE_INTEGER && (area = MAX_SAFE_INTEGER);
  45874. currNode = parent;
  45875. }
  45876. area < viewArea && (area = viewArea);
  45877. var scale = Math.pow(area / viewArea, 0.5);
  45878. return [containerWidth * scale, containerHeight * scale];
  45879. }
  45880. // Root postion base on coord of containerGroup
  45881. function calculateRootPosition(layoutInfo, rootRect, targetInfo) {
  45882. if (rootRect) {
  45883. return {x: rootRect.x, y: rootRect.y};
  45884. }
  45885. var defaultPosition = {x: 0, y: 0};
  45886. if (!targetInfo) {
  45887. return defaultPosition;
  45888. }
  45889. // If targetInfo is fetched by 'retrieveTargetInfo',
  45890. // old tree and new tree are the same tree,
  45891. // so the node still exists and we can visit it.
  45892. var targetNode = targetInfo.node;
  45893. var layout = targetNode.getLayout();
  45894. if (!layout) {
  45895. return defaultPosition;
  45896. }
  45897. // Transform coord from local to container.
  45898. var targetCenter = [layout.width / 2, layout.height / 2];
  45899. var node = targetNode;
  45900. while (node) {
  45901. var nodeLayout = node.getLayout();
  45902. targetCenter[0] += nodeLayout.x;
  45903. targetCenter[1] += nodeLayout.y;
  45904. node = node.parentNode;
  45905. }
  45906. return {
  45907. x: layoutInfo.width / 2 - targetCenter[0],
  45908. y: layoutInfo.height / 2 - targetCenter[1]
  45909. };
  45910. }
  45911. // Mark nodes visible for prunning when visual coding and rendering.
  45912. // Prunning depends on layout and root position, so we have to do it after layout.
  45913. function prunning(node, clipRect, viewAbovePath, viewRoot, depth) {
  45914. var nodeLayout = node.getLayout();
  45915. var nodeInViewAbovePath = viewAbovePath[depth];
  45916. var isAboveViewRoot = nodeInViewAbovePath && nodeInViewAbovePath === node;
  45917. if (
  45918. (nodeInViewAbovePath && !isAboveViewRoot)
  45919. || (depth === viewAbovePath.length && node !== viewRoot)
  45920. ) {
  45921. return;
  45922. }
  45923. node.setLayout({
  45924. // isInView means: viewRoot sub tree + viewAbovePath
  45925. isInView: true,
  45926. // invisible only means: outside view clip so that the node can not
  45927. // see but still layout for animation preparation but not render.
  45928. invisible: !isAboveViewRoot && !clipRect.intersect(nodeLayout),
  45929. isAboveViewRoot: isAboveViewRoot
  45930. }, true);
  45931. // Transform to child coordinate.
  45932. var childClipRect = new BoundingRect(
  45933. clipRect.x - nodeLayout.x,
  45934. clipRect.y - nodeLayout.y,
  45935. clipRect.width,
  45936. clipRect.height
  45937. );
  45938. each$10(node.viewChildren || [], function (child) {
  45939. prunning(child, childClipRect, viewAbovePath, viewRoot, depth + 1);
  45940. });
  45941. }
  45942. function getUpperLabelHeight(model) {
  45943. return model.get(PATH_UPPER_LABEL_SHOW) ? model.get(PATH_UPPER_LABEL_HEIGHT) : 0;
  45944. }
  45945. /*
  45946. * Licensed to the Apache Software Foundation (ASF) under one
  45947. * or more contributor license agreements. See the NOTICE file
  45948. * distributed with this work for additional information
  45949. * regarding copyright ownership. The ASF licenses this file
  45950. * to you under the Apache License, Version 2.0 (the
  45951. * "License"); you may not use this file except in compliance
  45952. * with the License. You may obtain a copy of the License at
  45953. *
  45954. * http://www.apache.org/licenses/LICENSE-2.0
  45955. *
  45956. * Unless required by applicable law or agreed to in writing,
  45957. * software distributed under the License is distributed on an
  45958. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45959. * KIND, either express or implied. See the License for the
  45960. * specific language governing permissions and limitations
  45961. * under the License.
  45962. */
  45963. registerVisual(treemapVisual);
  45964. registerLayout(treemapLayout);
  45965. /*
  45966. * Licensed to the Apache Software Foundation (ASF) under one
  45967. * or more contributor license agreements. See the NOTICE file
  45968. * distributed with this work for additional information
  45969. * regarding copyright ownership. The ASF licenses this file
  45970. * to you under the Apache License, Version 2.0 (the
  45971. * "License"); you may not use this file except in compliance
  45972. * with the License. You may obtain a copy of the License at
  45973. *
  45974. * http://www.apache.org/licenses/LICENSE-2.0
  45975. *
  45976. * Unless required by applicable law or agreed to in writing,
  45977. * software distributed under the License is distributed on an
  45978. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45979. * KIND, either express or implied. See the License for the
  45980. * specific language governing permissions and limitations
  45981. * under the License.
  45982. */
  45983. /**
  45984. * Graph data structure
  45985. *
  45986. * @module echarts/data/Graph
  45987. * @author Yi Shen(https://www.github.com/pissang)
  45988. */
  45989. // id may be function name of Object, add a prefix to avoid this problem.
  45990. function generateNodeKey(id) {
  45991. return '_EC_' + id;
  45992. }
  45993. /**
  45994. * @alias module:echarts/data/Graph
  45995. * @constructor
  45996. * @param {boolean} directed
  45997. */
  45998. var Graph = function (directed) {
  45999. /**
  46000. * 是否是有向图
  46001. * @type {boolean}
  46002. * @private
  46003. */
  46004. this._directed = directed || false;
  46005. /**
  46006. * @type {Array.<module:echarts/data/Graph.Node>}
  46007. * @readOnly
  46008. */
  46009. this.nodes = [];
  46010. /**
  46011. * @type {Array.<module:echarts/data/Graph.Edge>}
  46012. * @readOnly
  46013. */
  46014. this.edges = [];
  46015. /**
  46016. * @type {Object.<string, module:echarts/data/Graph.Node>}
  46017. * @private
  46018. */
  46019. this._nodesMap = {};
  46020. /**
  46021. * @type {Object.<string, module:echarts/data/Graph.Edge>}
  46022. * @private
  46023. */
  46024. this._edgesMap = {};
  46025. /**
  46026. * @type {module:echarts/data/List}
  46027. * @readOnly
  46028. */
  46029. this.data;
  46030. /**
  46031. * @type {module:echarts/data/List}
  46032. * @readOnly
  46033. */
  46034. this.edgeData;
  46035. };
  46036. var graphProto = Graph.prototype;
  46037. /**
  46038. * @type {string}
  46039. */
  46040. graphProto.type = 'graph';
  46041. /**
  46042. * If is directed graph
  46043. * @return {boolean}
  46044. */
  46045. graphProto.isDirected = function () {
  46046. return this._directed;
  46047. };
  46048. /**
  46049. * Add a new node
  46050. * @param {string} id
  46051. * @param {number} [dataIndex]
  46052. */
  46053. graphProto.addNode = function (id, dataIndex) {
  46054. id = id || ('' + dataIndex);
  46055. var nodesMap = this._nodesMap;
  46056. if (nodesMap[generateNodeKey(id)]) {
  46057. if (__DEV__) {
  46058. console.error('Graph nodes have duplicate name or id');
  46059. }
  46060. return;
  46061. }
  46062. var node = new Node(id, dataIndex);
  46063. node.hostGraph = this;
  46064. this.nodes.push(node);
  46065. nodesMap[generateNodeKey(id)] = node;
  46066. return node;
  46067. };
  46068. /**
  46069. * Get node by data index
  46070. * @param {number} dataIndex
  46071. * @return {module:echarts/data/Graph~Node}
  46072. */
  46073. graphProto.getNodeByIndex = function (dataIndex) {
  46074. var rawIdx = this.data.getRawIndex(dataIndex);
  46075. return this.nodes[rawIdx];
  46076. };
  46077. /**
  46078. * Get node by id
  46079. * @param {string} id
  46080. * @return {module:echarts/data/Graph.Node}
  46081. */
  46082. graphProto.getNodeById = function (id) {
  46083. return this._nodesMap[generateNodeKey(id)];
  46084. };
  46085. /**
  46086. * Add a new edge
  46087. * @param {number|string|module:echarts/data/Graph.Node} n1
  46088. * @param {number|string|module:echarts/data/Graph.Node} n2
  46089. * @param {number} [dataIndex=-1]
  46090. * @return {module:echarts/data/Graph.Edge}
  46091. */
  46092. graphProto.addEdge = function (n1, n2, dataIndex) {
  46093. var nodesMap = this._nodesMap;
  46094. var edgesMap = this._edgesMap;
  46095. // PNEDING
  46096. if (typeof n1 === 'number') {
  46097. n1 = this.nodes[n1];
  46098. }
  46099. if (typeof n2 === 'number') {
  46100. n2 = this.nodes[n2];
  46101. }
  46102. if (!Node.isInstance(n1)) {
  46103. n1 = nodesMap[generateNodeKey(n1)];
  46104. }
  46105. if (!Node.isInstance(n2)) {
  46106. n2 = nodesMap[generateNodeKey(n2)];
  46107. }
  46108. if (!n1 || !n2) {
  46109. return;
  46110. }
  46111. var key = n1.id + '-' + n2.id;
  46112. // PENDING
  46113. if (edgesMap[key]) {
  46114. return;
  46115. }
  46116. var edge = new Edge(n1, n2, dataIndex);
  46117. edge.hostGraph = this;
  46118. if (this._directed) {
  46119. n1.outEdges.push(edge);
  46120. n2.inEdges.push(edge);
  46121. }
  46122. n1.edges.push(edge);
  46123. if (n1 !== n2) {
  46124. n2.edges.push(edge);
  46125. }
  46126. this.edges.push(edge);
  46127. edgesMap[key] = edge;
  46128. return edge;
  46129. };
  46130. /**
  46131. * Get edge by data index
  46132. * @param {number} dataIndex
  46133. * @return {module:echarts/data/Graph~Node}
  46134. */
  46135. graphProto.getEdgeByIndex = function (dataIndex) {
  46136. var rawIdx = this.edgeData.getRawIndex(dataIndex);
  46137. return this.edges[rawIdx];
  46138. };
  46139. /**
  46140. * Get edge by two linked nodes
  46141. * @param {module:echarts/data/Graph.Node|string} n1
  46142. * @param {module:echarts/data/Graph.Node|string} n2
  46143. * @return {module:echarts/data/Graph.Edge}
  46144. */
  46145. graphProto.getEdge = function (n1, n2) {
  46146. if (Node.isInstance(n1)) {
  46147. n1 = n1.id;
  46148. }
  46149. if (Node.isInstance(n2)) {
  46150. n2 = n2.id;
  46151. }
  46152. var edgesMap = this._edgesMap;
  46153. if (this._directed) {
  46154. return edgesMap[n1 + '-' + n2];
  46155. }
  46156. else {
  46157. return edgesMap[n1 + '-' + n2]
  46158. || edgesMap[n2 + '-' + n1];
  46159. }
  46160. };
  46161. /**
  46162. * Iterate all nodes
  46163. * @param {Function} cb
  46164. * @param {*} [context]
  46165. */
  46166. graphProto.eachNode = function (cb, context) {
  46167. var nodes = this.nodes;
  46168. var len = nodes.length;
  46169. for (var i = 0; i < len; i++) {
  46170. if (nodes[i].dataIndex >= 0) {
  46171. cb.call(context, nodes[i], i);
  46172. }
  46173. }
  46174. };
  46175. /**
  46176. * Iterate all edges
  46177. * @param {Function} cb
  46178. * @param {*} [context]
  46179. */
  46180. graphProto.eachEdge = function (cb, context) {
  46181. var edges = this.edges;
  46182. var len = edges.length;
  46183. for (var i = 0; i < len; i++) {
  46184. if (edges[i].dataIndex >= 0
  46185. && edges[i].node1.dataIndex >= 0
  46186. && edges[i].node2.dataIndex >= 0
  46187. ) {
  46188. cb.call(context, edges[i], i);
  46189. }
  46190. }
  46191. };
  46192. /**
  46193. * Breadth first traverse
  46194. * @param {Function} cb
  46195. * @param {module:echarts/data/Graph.Node} startNode
  46196. * @param {string} [direction='none'] 'none'|'in'|'out'
  46197. * @param {*} [context]
  46198. */
  46199. graphProto.breadthFirstTraverse = function (
  46200. cb, startNode, direction, context
  46201. ) {
  46202. if (!Node.isInstance(startNode)) {
  46203. startNode = this._nodesMap[generateNodeKey(startNode)];
  46204. }
  46205. if (!startNode) {
  46206. return;
  46207. }
  46208. var edgeType = direction === 'out'
  46209. ? 'outEdges' : (direction === 'in' ? 'inEdges' : 'edges');
  46210. for (var i = 0; i < this.nodes.length; i++) {
  46211. this.nodes[i].__visited = false;
  46212. }
  46213. if (cb.call(context, startNode, null)) {
  46214. return;
  46215. }
  46216. var queue = [startNode];
  46217. while (queue.length) {
  46218. var currentNode = queue.shift();
  46219. var edges = currentNode[edgeType];
  46220. for (var i = 0; i < edges.length; i++) {
  46221. var e = edges[i];
  46222. var otherNode = e.node1 === currentNode
  46223. ? e.node2 : e.node1;
  46224. if (!otherNode.__visited) {
  46225. if (cb.call(context, otherNode, currentNode)) {
  46226. // Stop traversing
  46227. return;
  46228. }
  46229. queue.push(otherNode);
  46230. otherNode.__visited = true;
  46231. }
  46232. }
  46233. }
  46234. };
  46235. // TODO
  46236. // graphProto.depthFirstTraverse = function (
  46237. // cb, startNode, direction, context
  46238. // ) {
  46239. // };
  46240. // Filter update
  46241. graphProto.update = function () {
  46242. var data = this.data;
  46243. var edgeData = this.edgeData;
  46244. var nodes = this.nodes;
  46245. var edges = this.edges;
  46246. for (var i = 0, len = nodes.length; i < len; i++) {
  46247. nodes[i].dataIndex = -1;
  46248. }
  46249. for (var i = 0, len = data.count(); i < len; i++) {
  46250. nodes[data.getRawIndex(i)].dataIndex = i;
  46251. }
  46252. edgeData.filterSelf(function (idx) {
  46253. var edge = edges[edgeData.getRawIndex(idx)];
  46254. return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
  46255. });
  46256. // Update edge
  46257. for (var i = 0, len = edges.length; i < len; i++) {
  46258. edges[i].dataIndex = -1;
  46259. }
  46260. for (var i = 0, len = edgeData.count(); i < len; i++) {
  46261. edges[edgeData.getRawIndex(i)].dataIndex = i;
  46262. }
  46263. };
  46264. /**
  46265. * @return {module:echarts/data/Graph}
  46266. */
  46267. graphProto.clone = function () {
  46268. var graph = new Graph(this._directed);
  46269. var nodes = this.nodes;
  46270. var edges = this.edges;
  46271. for (var i = 0; i < nodes.length; i++) {
  46272. graph.addNode(nodes[i].id, nodes[i].dataIndex);
  46273. }
  46274. for (var i = 0; i < edges.length; i++) {
  46275. var e = edges[i];
  46276. graph.addEdge(e.node1.id, e.node2.id, e.dataIndex);
  46277. }
  46278. return graph;
  46279. };
  46280. /**
  46281. * @alias module:echarts/data/Graph.Node
  46282. */
  46283. function Node(id, dataIndex) {
  46284. /**
  46285. * @type {string}
  46286. */
  46287. this.id = id == null ? '' : id;
  46288. /**
  46289. * @type {Array.<module:echarts/data/Graph.Edge>}
  46290. */
  46291. this.inEdges = [];
  46292. /**
  46293. * @type {Array.<module:echarts/data/Graph.Edge>}
  46294. */
  46295. this.outEdges = [];
  46296. /**
  46297. * @type {Array.<module:echarts/data/Graph.Edge>}
  46298. */
  46299. this.edges = [];
  46300. /**
  46301. * @type {module:echarts/data/Graph}
  46302. */
  46303. this.hostGraph;
  46304. /**
  46305. * @type {number}
  46306. */
  46307. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  46308. }
  46309. Node.prototype = {
  46310. constructor: Node,
  46311. /**
  46312. * @return {number}
  46313. */
  46314. degree: function () {
  46315. return this.edges.length;
  46316. },
  46317. /**
  46318. * @return {number}
  46319. */
  46320. inDegree: function () {
  46321. return this.inEdges.length;
  46322. },
  46323. /**
  46324. * @return {number}
  46325. */
  46326. outDegree: function () {
  46327. return this.outEdges.length;
  46328. },
  46329. /**
  46330. * @param {string} [path]
  46331. * @return {module:echarts/model/Model}
  46332. */
  46333. getModel: function (path) {
  46334. if (this.dataIndex < 0) {
  46335. return;
  46336. }
  46337. var graph = this.hostGraph;
  46338. var itemModel = graph.data.getItemModel(this.dataIndex);
  46339. return itemModel.getModel(path);
  46340. }
  46341. };
  46342. /**
  46343. * 图边
  46344. * @alias module:echarts/data/Graph.Edge
  46345. * @param {module:echarts/data/Graph.Node} n1
  46346. * @param {module:echarts/data/Graph.Node} n2
  46347. * @param {number} [dataIndex=-1]
  46348. */
  46349. function Edge(n1, n2, dataIndex) {
  46350. /**
  46351. * 节点1,如果是有向图则为源节点
  46352. * @type {module:echarts/data/Graph.Node}
  46353. */
  46354. this.node1 = n1;
  46355. /**
  46356. * 节点2,如果是有向图则为目标节点
  46357. * @type {module:echarts/data/Graph.Node}
  46358. */
  46359. this.node2 = n2;
  46360. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  46361. }
  46362. /**
  46363. * @param {string} [path]
  46364. * @return {module:echarts/model/Model}
  46365. */
  46366. Edge.prototype.getModel = function (path) {
  46367. if (this.dataIndex < 0) {
  46368. return;
  46369. }
  46370. var graph = this.hostGraph;
  46371. var itemModel = graph.edgeData.getItemModel(this.dataIndex);
  46372. return itemModel.getModel(path);
  46373. };
  46374. var createGraphDataProxyMixin = function (hostName, dataName) {
  46375. return {
  46376. /**
  46377. * @param {string=} [dimension='value'] Default 'value'. can be 'a', 'b', 'c', 'd', 'e'.
  46378. * @return {number}
  46379. */
  46380. getValue: function (dimension) {
  46381. var data = this[hostName][dataName];
  46382. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  46383. },
  46384. /**
  46385. * @param {Object|string} key
  46386. * @param {*} [value]
  46387. */
  46388. setVisual: function (key, value) {
  46389. this.dataIndex >= 0
  46390. && this[hostName][dataName].setItemVisual(this.dataIndex, key, value);
  46391. },
  46392. /**
  46393. * @param {string} key
  46394. * @return {boolean}
  46395. */
  46396. getVisual: function (key, ignoreParent) {
  46397. return this[hostName][dataName].getItemVisual(this.dataIndex, key, ignoreParent);
  46398. },
  46399. /**
  46400. * @param {Object} layout
  46401. * @return {boolean} [merge=false]
  46402. */
  46403. setLayout: function (layout, merge$$1) {
  46404. this.dataIndex >= 0
  46405. && this[hostName][dataName].setItemLayout(this.dataIndex, layout, merge$$1);
  46406. },
  46407. /**
  46408. * @return {Object}
  46409. */
  46410. getLayout: function () {
  46411. return this[hostName][dataName].getItemLayout(this.dataIndex);
  46412. },
  46413. /**
  46414. * @return {module:zrender/Element}
  46415. */
  46416. getGraphicEl: function () {
  46417. return this[hostName][dataName].getItemGraphicEl(this.dataIndex);
  46418. },
  46419. /**
  46420. * @return {number}
  46421. */
  46422. getRawIndex: function () {
  46423. return this[hostName][dataName].getRawIndex(this.dataIndex);
  46424. }
  46425. };
  46426. };
  46427. mixin(Node, createGraphDataProxyMixin('hostGraph', 'data'));
  46428. mixin(Edge, createGraphDataProxyMixin('hostGraph', 'edgeData'));
  46429. Graph.Node = Node;
  46430. Graph.Edge = Edge;
  46431. enableClassCheck(Node);
  46432. enableClassCheck(Edge);
  46433. /*
  46434. * Licensed to the Apache Software Foundation (ASF) under one
  46435. * or more contributor license agreements. See the NOTICE file
  46436. * distributed with this work for additional information
  46437. * regarding copyright ownership. The ASF licenses this file
  46438. * to you under the Apache License, Version 2.0 (the
  46439. * "License"); you may not use this file except in compliance
  46440. * with the License. You may obtain a copy of the License at
  46441. *
  46442. * http://www.apache.org/licenses/LICENSE-2.0
  46443. *
  46444. * Unless required by applicable law or agreed to in writing,
  46445. * software distributed under the License is distributed on an
  46446. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46447. * KIND, either express or implied. See the License for the
  46448. * specific language governing permissions and limitations
  46449. * under the License.
  46450. */
  46451. var createGraphFromNodeEdge = function (nodes, edges, seriesModel, directed, beforeLink) {
  46452. // ??? TODO
  46453. // support dataset?
  46454. var graph = new Graph(directed);
  46455. for (var i = 0; i < nodes.length; i++) {
  46456. graph.addNode(retrieve(
  46457. // Id, name, dataIndex
  46458. nodes[i].id, nodes[i].name, i
  46459. ), i);
  46460. }
  46461. var linkNameList = [];
  46462. var validEdges = [];
  46463. var linkCount = 0;
  46464. for (var i = 0; i < edges.length; i++) {
  46465. var link = edges[i];
  46466. var source = link.source;
  46467. var target = link.target;
  46468. // addEdge may fail when source or target not exists
  46469. if (graph.addEdge(source, target, linkCount)) {
  46470. validEdges.push(link);
  46471. linkNameList.push(retrieve(link.id, source + ' > ' + target));
  46472. linkCount++;
  46473. }
  46474. }
  46475. var coordSys = seriesModel.get('coordinateSystem');
  46476. var nodeData;
  46477. if (coordSys === 'cartesian2d' || coordSys === 'polar') {
  46478. nodeData = createListFromArray(nodes, seriesModel);
  46479. }
  46480. else {
  46481. var coordSysCtor = CoordinateSystemManager.get(coordSys);
  46482. var coordDimensions = (coordSysCtor && coordSysCtor.type !== 'view')
  46483. ? (coordSysCtor.dimensions || []) : [];
  46484. // FIXME: Some geo do not need `value` dimenson, whereas `calendar` needs
  46485. // `value` dimension, but graph need `value` dimension. It's better to
  46486. // uniform this behavior.
  46487. if (indexOf(coordDimensions, 'value') < 0) {
  46488. coordDimensions.concat(['value']);
  46489. }
  46490. var dimensionNames = createDimensions(nodes, {
  46491. coordDimensions: coordDimensions
  46492. });
  46493. nodeData = new List(dimensionNames, seriesModel);
  46494. nodeData.initData(nodes);
  46495. }
  46496. var edgeData = new List(['value'], seriesModel);
  46497. edgeData.initData(validEdges, linkNameList);
  46498. beforeLink && beforeLink(nodeData, edgeData);
  46499. linkList({
  46500. mainData: nodeData,
  46501. struct: graph,
  46502. structAttr: 'graph',
  46503. datas: {node: nodeData, edge: edgeData},
  46504. datasAttr: {node: 'data', edge: 'edgeData'}
  46505. });
  46506. // Update dataIndex of nodes and edges because invalid edge may be removed
  46507. graph.update();
  46508. return graph;
  46509. };
  46510. /*
  46511. * Licensed to the Apache Software Foundation (ASF) under one
  46512. * or more contributor license agreements. See the NOTICE file
  46513. * distributed with this work for additional information
  46514. * regarding copyright ownership. The ASF licenses this file
  46515. * to you under the Apache License, Version 2.0 (the
  46516. * "License"); you may not use this file except in compliance
  46517. * with the License. You may obtain a copy of the License at
  46518. *
  46519. * http://www.apache.org/licenses/LICENSE-2.0
  46520. *
  46521. * Unless required by applicable law or agreed to in writing,
  46522. * software distributed under the License is distributed on an
  46523. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46524. * KIND, either express or implied. See the License for the
  46525. * specific language governing permissions and limitations
  46526. * under the License.
  46527. */
  46528. var GraphSeries = extendSeriesModel({
  46529. type: 'series.graph',
  46530. init: function (option) {
  46531. GraphSeries.superApply(this, 'init', arguments);
  46532. // Provide data for legend select
  46533. this.legendDataProvider = function () {
  46534. return this._categoriesData;
  46535. };
  46536. this.fillDataTextStyle(option.edges || option.links);
  46537. this._updateCategoriesData();
  46538. },
  46539. mergeOption: function (option) {
  46540. GraphSeries.superApply(this, 'mergeOption', arguments);
  46541. this.fillDataTextStyle(option.edges || option.links);
  46542. this._updateCategoriesData();
  46543. },
  46544. mergeDefaultAndTheme: function (option) {
  46545. GraphSeries.superApply(this, 'mergeDefaultAndTheme', arguments);
  46546. defaultEmphasis(option, ['edgeLabel'], ['show']);
  46547. },
  46548. getInitialData: function (option, ecModel) {
  46549. var edges = option.edges || option.links || [];
  46550. var nodes = option.data || option.nodes || [];
  46551. var self = this;
  46552. if (nodes && edges) {
  46553. return createGraphFromNodeEdge(nodes, edges, this, true, beforeLink).data;
  46554. }
  46555. function beforeLink(nodeData, edgeData) {
  46556. // Overwrite nodeData.getItemModel to
  46557. nodeData.wrapMethod('getItemModel', function (model) {
  46558. var categoriesModels = self._categoriesModels;
  46559. var categoryIdx = model.getShallow('category');
  46560. var categoryModel = categoriesModels[categoryIdx];
  46561. if (categoryModel) {
  46562. categoryModel.parentModel = model.parentModel;
  46563. model.parentModel = categoryModel;
  46564. }
  46565. return model;
  46566. });
  46567. var edgeLabelModel = self.getModel('edgeLabel');
  46568. // For option `edgeLabel` can be found by label.xxx.xxx on item mode.
  46569. var fakeSeriesModel = new Model(
  46570. {label: edgeLabelModel.option},
  46571. edgeLabelModel.parentModel,
  46572. ecModel
  46573. );
  46574. var emphasisEdgeLabelModel = self.getModel('emphasis.edgeLabel');
  46575. var emphasisFakeSeriesModel = new Model(
  46576. {emphasis: {label: emphasisEdgeLabelModel.option}},
  46577. emphasisEdgeLabelModel.parentModel,
  46578. ecModel
  46579. );
  46580. edgeData.wrapMethod('getItemModel', function (model) {
  46581. model.customizeGetParent(edgeGetParent);
  46582. return model;
  46583. });
  46584. function edgeGetParent(path) {
  46585. path = this.parsePath(path);
  46586. return (path && path[0] === 'label')
  46587. ? fakeSeriesModel
  46588. : (path && path[0] === 'emphasis' && path[1] === 'label')
  46589. ? emphasisFakeSeriesModel
  46590. : this.parentModel;
  46591. }
  46592. }
  46593. },
  46594. /**
  46595. * @return {module:echarts/data/Graph}
  46596. */
  46597. getGraph: function () {
  46598. return this.getData().graph;
  46599. },
  46600. /**
  46601. * @return {module:echarts/data/List}
  46602. */
  46603. getEdgeData: function () {
  46604. return this.getGraph().edgeData;
  46605. },
  46606. /**
  46607. * @return {module:echarts/data/List}
  46608. */
  46609. getCategoriesData: function () {
  46610. return this._categoriesData;
  46611. },
  46612. /**
  46613. * @override
  46614. */
  46615. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  46616. if (dataType === 'edge') {
  46617. var nodeData = this.getData();
  46618. var params = this.getDataParams(dataIndex, dataType);
  46619. var edge = nodeData.graph.getEdgeByIndex(dataIndex);
  46620. var sourceName = nodeData.getName(edge.node1.dataIndex);
  46621. var targetName = nodeData.getName(edge.node2.dataIndex);
  46622. var html = [];
  46623. sourceName != null && html.push(sourceName);
  46624. targetName != null && html.push(targetName);
  46625. html = encodeHTML(html.join(' > '));
  46626. if (params.value) {
  46627. html += ' : ' + encodeHTML(params.value);
  46628. }
  46629. return html;
  46630. }
  46631. else { // dataType === 'node' or empty
  46632. return GraphSeries.superApply(this, 'formatTooltip', arguments);
  46633. }
  46634. },
  46635. _updateCategoriesData: function () {
  46636. var categories = map(this.option.categories || [], function (category) {
  46637. // Data must has value
  46638. return category.value != null ? category : extend({
  46639. value: 0
  46640. }, category);
  46641. });
  46642. var categoriesData = new List(['value'], this);
  46643. categoriesData.initData(categories);
  46644. this._categoriesData = categoriesData;
  46645. this._categoriesModels = categoriesData.mapArray(function (idx) {
  46646. return categoriesData.getItemModel(idx, true);
  46647. });
  46648. },
  46649. setZoom: function (zoom) {
  46650. this.option.zoom = zoom;
  46651. },
  46652. setCenter: function (center) {
  46653. this.option.center = center;
  46654. },
  46655. isAnimationEnabled: function () {
  46656. return GraphSeries.superCall(this, 'isAnimationEnabled')
  46657. // Not enable animation when do force layout
  46658. && !(this.get('layout') === 'force' && this.get('force.layoutAnimation'));
  46659. },
  46660. defaultOption: {
  46661. zlevel: 0,
  46662. z: 2,
  46663. coordinateSystem: 'view',
  46664. // Default option for all coordinate systems
  46665. // xAxisIndex: 0,
  46666. // yAxisIndex: 0,
  46667. // polarIndex: 0,
  46668. // geoIndex: 0,
  46669. legendHoverLink: true,
  46670. hoverAnimation: true,
  46671. layout: null,
  46672. focusNodeAdjacency: false,
  46673. // Configuration of circular layout
  46674. circular: {
  46675. rotateLabel: false
  46676. },
  46677. // Configuration of force directed layout
  46678. force: {
  46679. initLayout: null,
  46680. // Node repulsion. Can be an array to represent range.
  46681. repulsion: [0, 50],
  46682. gravity: 0.1,
  46683. // Edge length. Can be an array to represent range.
  46684. edgeLength: 30,
  46685. layoutAnimation: true
  46686. },
  46687. left: 'center',
  46688. top: 'center',
  46689. // right: null,
  46690. // bottom: null,
  46691. // width: '80%',
  46692. // height: '80%',
  46693. symbol: 'circle',
  46694. symbolSize: 10,
  46695. edgeSymbol: ['none', 'none'],
  46696. edgeSymbolSize: 10,
  46697. edgeLabel: {
  46698. position: 'middle'
  46699. },
  46700. draggable: false,
  46701. roam: false,
  46702. // Default on center of graph
  46703. center: null,
  46704. zoom: 1,
  46705. // Symbol size scale ratio in roam
  46706. nodeScaleRatio: 0.6,
  46707. // cursor: null,
  46708. // categories: [],
  46709. // data: []
  46710. // Or
  46711. // nodes: []
  46712. //
  46713. // links: []
  46714. // Or
  46715. // edges: []
  46716. label: {
  46717. show: false,
  46718. formatter: '{b}'
  46719. },
  46720. itemStyle: {},
  46721. lineStyle: {
  46722. color: '#aaa',
  46723. width: 1,
  46724. curveness: 0,
  46725. opacity: 0.5
  46726. },
  46727. emphasis: {
  46728. label: {
  46729. show: true
  46730. }
  46731. }
  46732. }
  46733. });
  46734. /*
  46735. * Licensed to the Apache Software Foundation (ASF) under one
  46736. * or more contributor license agreements. See the NOTICE file
  46737. * distributed with this work for additional information
  46738. * regarding copyright ownership. The ASF licenses this file
  46739. * to you under the Apache License, Version 2.0 (the
  46740. * "License"); you may not use this file except in compliance
  46741. * with the License. You may obtain a copy of the License at
  46742. *
  46743. * http://www.apache.org/licenses/LICENSE-2.0
  46744. *
  46745. * Unless required by applicable law or agreed to in writing,
  46746. * software distributed under the License is distributed on an
  46747. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46748. * KIND, either express or implied. See the License for the
  46749. * specific language governing permissions and limitations
  46750. * under the License.
  46751. */
  46752. /**
  46753. * Line path for bezier and straight line draw
  46754. */
  46755. var straightLineProto = Line.prototype;
  46756. var bezierCurveProto = BezierCurve.prototype;
  46757. function isLine(shape) {
  46758. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  46759. }
  46760. var LinePath = extendShape({
  46761. type: 'ec-line',
  46762. style: {
  46763. stroke: '#000',
  46764. fill: null
  46765. },
  46766. shape: {
  46767. x1: 0,
  46768. y1: 0,
  46769. x2: 0,
  46770. y2: 0,
  46771. percent: 1,
  46772. cpx1: null,
  46773. cpy1: null
  46774. },
  46775. buildPath: function (ctx, shape) {
  46776. (isLine(shape) ? straightLineProto : bezierCurveProto).buildPath(ctx, shape);
  46777. },
  46778. pointAt: function (t) {
  46779. return isLine(this.shape)
  46780. ? straightLineProto.pointAt.call(this, t)
  46781. : bezierCurveProto.pointAt.call(this, t);
  46782. },
  46783. tangentAt: function (t) {
  46784. var shape = this.shape;
  46785. var p = isLine(shape)
  46786. ? [shape.x2 - shape.x1, shape.y2 - shape.y1]
  46787. : bezierCurveProto.tangentAt.call(this, t);
  46788. return normalize(p, p);
  46789. }
  46790. });
  46791. /*
  46792. * Licensed to the Apache Software Foundation (ASF) under one
  46793. * or more contributor license agreements. See the NOTICE file
  46794. * distributed with this work for additional information
  46795. * regarding copyright ownership. The ASF licenses this file
  46796. * to you under the Apache License, Version 2.0 (the
  46797. * "License"); you may not use this file except in compliance
  46798. * with the License. You may obtain a copy of the License at
  46799. *
  46800. * http://www.apache.org/licenses/LICENSE-2.0
  46801. *
  46802. * Unless required by applicable law or agreed to in writing,
  46803. * software distributed under the License is distributed on an
  46804. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46805. * KIND, either express or implied. See the License for the
  46806. * specific language governing permissions and limitations
  46807. * under the License.
  46808. */
  46809. /**
  46810. * @module echarts/chart/helper/Line
  46811. */
  46812. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  46813. function makeSymbolTypeKey(symbolCategory) {
  46814. return '_' + symbolCategory + 'Type';
  46815. }
  46816. /**
  46817. * @inner
  46818. */
  46819. function createSymbol$1(name, lineData, idx) {
  46820. var color = lineData.getItemVisual(idx, 'color');
  46821. var symbolType = lineData.getItemVisual(idx, name);
  46822. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  46823. if (!symbolType || symbolType === 'none') {
  46824. return;
  46825. }
  46826. if (!isArray(symbolSize)) {
  46827. symbolSize = [symbolSize, symbolSize];
  46828. }
  46829. var symbolPath = createSymbol(
  46830. symbolType, -symbolSize[0] / 2, -symbolSize[1] / 2,
  46831. symbolSize[0], symbolSize[1], color
  46832. );
  46833. symbolPath.name = name;
  46834. return symbolPath;
  46835. }
  46836. function createLine(points) {
  46837. var line = new LinePath({
  46838. name: 'line'
  46839. });
  46840. setLinePoints(line.shape, points);
  46841. return line;
  46842. }
  46843. function setLinePoints(targetShape, points) {
  46844. var p1 = points[0];
  46845. var p2 = points[1];
  46846. var cp1 = points[2];
  46847. targetShape.x1 = p1[0];
  46848. targetShape.y1 = p1[1];
  46849. targetShape.x2 = p2[0];
  46850. targetShape.y2 = p2[1];
  46851. targetShape.percent = 1;
  46852. if (cp1) {
  46853. targetShape.cpx1 = cp1[0];
  46854. targetShape.cpy1 = cp1[1];
  46855. }
  46856. else {
  46857. targetShape.cpx1 = NaN;
  46858. targetShape.cpy1 = NaN;
  46859. }
  46860. }
  46861. function updateSymbolAndLabelBeforeLineUpdate() {
  46862. var lineGroup = this;
  46863. var symbolFrom = lineGroup.childOfName('fromSymbol');
  46864. var symbolTo = lineGroup.childOfName('toSymbol');
  46865. var label = lineGroup.childOfName('label');
  46866. // Quick reject
  46867. if (!symbolFrom && !symbolTo && label.ignore) {
  46868. return;
  46869. }
  46870. var invScale = 1;
  46871. var parentNode = this.parent;
  46872. while (parentNode) {
  46873. if (parentNode.scale) {
  46874. invScale /= parentNode.scale[0];
  46875. }
  46876. parentNode = parentNode.parent;
  46877. }
  46878. var line = lineGroup.childOfName('line');
  46879. // If line not changed
  46880. // FIXME Parent scale changed
  46881. if (!this.__dirty && !line.__dirty) {
  46882. return;
  46883. }
  46884. var percent = line.shape.percent;
  46885. var fromPos = line.pointAt(0);
  46886. var toPos = line.pointAt(percent);
  46887. var d = sub([], toPos, fromPos);
  46888. normalize(d, d);
  46889. if (symbolFrom) {
  46890. symbolFrom.attr('position', fromPos);
  46891. var tangent = line.tangentAt(0);
  46892. symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(
  46893. tangent[1], tangent[0]
  46894. ));
  46895. symbolFrom.attr('scale', [invScale * percent, invScale * percent]);
  46896. }
  46897. if (symbolTo) {
  46898. symbolTo.attr('position', toPos);
  46899. var tangent = line.tangentAt(1);
  46900. symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
  46901. tangent[1], tangent[0]
  46902. ));
  46903. symbolTo.attr('scale', [invScale * percent, invScale * percent]);
  46904. }
  46905. if (!label.ignore) {
  46906. label.attr('position', toPos);
  46907. var textPosition;
  46908. var textAlign;
  46909. var textVerticalAlign;
  46910. var distance$$1 = 5 * invScale;
  46911. // End
  46912. if (label.__position === 'end') {
  46913. textPosition = [d[0] * distance$$1 + toPos[0], d[1] * distance$$1 + toPos[1]];
  46914. textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center');
  46915. textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle');
  46916. }
  46917. // Middle
  46918. else if (label.__position === 'middle') {
  46919. var halfPercent = percent / 2;
  46920. var tangent = line.tangentAt(halfPercent);
  46921. var n = [tangent[1], -tangent[0]];
  46922. var cp = line.pointAt(halfPercent);
  46923. if (n[1] > 0) {
  46924. n[0] = -n[0];
  46925. n[1] = -n[1];
  46926. }
  46927. textPosition = [cp[0] + n[0] * distance$$1, cp[1] + n[1] * distance$$1];
  46928. textAlign = 'center';
  46929. textVerticalAlign = 'bottom';
  46930. var rotation = -Math.atan2(tangent[1], tangent[0]);
  46931. if (toPos[0] < fromPos[0]) {
  46932. rotation = Math.PI + rotation;
  46933. }
  46934. label.attr('rotation', rotation);
  46935. }
  46936. // Start
  46937. else {
  46938. textPosition = [-d[0] * distance$$1 + fromPos[0], -d[1] * distance$$1 + fromPos[1]];
  46939. textAlign = d[0] > 0.8 ? 'right' : (d[0] < -0.8 ? 'left' : 'center');
  46940. textVerticalAlign = d[1] > 0.8 ? 'bottom' : (d[1] < -0.8 ? 'top' : 'middle');
  46941. }
  46942. label.attr({
  46943. style: {
  46944. // Use the user specified text align and baseline first
  46945. textVerticalAlign: label.__verticalAlign || textVerticalAlign,
  46946. textAlign: label.__textAlign || textAlign
  46947. },
  46948. position: textPosition,
  46949. scale: [invScale, invScale]
  46950. });
  46951. }
  46952. }
  46953. /**
  46954. * @constructor
  46955. * @extends {module:zrender/graphic/Group}
  46956. * @alias {module:echarts/chart/helper/Line}
  46957. */
  46958. function Line$1(lineData, idx, seriesScope) {
  46959. Group.call(this);
  46960. this._createLine(lineData, idx, seriesScope);
  46961. }
  46962. var lineProto = Line$1.prototype;
  46963. // Update symbol position and rotation
  46964. lineProto.beforeUpdate = updateSymbolAndLabelBeforeLineUpdate;
  46965. lineProto._createLine = function (lineData, idx, seriesScope) {
  46966. var seriesModel = lineData.hostModel;
  46967. var linePoints = lineData.getItemLayout(idx);
  46968. var line = createLine(linePoints);
  46969. line.shape.percent = 0;
  46970. initProps(line, {
  46971. shape: {
  46972. percent: 1
  46973. }
  46974. }, seriesModel, idx);
  46975. this.add(line);
  46976. var label = new Text({
  46977. name: 'label',
  46978. // FIXME
  46979. // Temporary solution for `focusNodeAdjacency`.
  46980. // line label do not use the opacity of lineStyle.
  46981. lineLabelOriginalOpacity: 1
  46982. });
  46983. this.add(label);
  46984. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  46985. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  46986. // symbols must added after line to make sure
  46987. // it will be updated after line#update.
  46988. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  46989. this.add(symbol);
  46990. this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
  46991. }, this);
  46992. this._updateCommonStl(lineData, idx, seriesScope);
  46993. };
  46994. lineProto.updateData = function (lineData, idx, seriesScope) {
  46995. var seriesModel = lineData.hostModel;
  46996. var line = this.childOfName('line');
  46997. var linePoints = lineData.getItemLayout(idx);
  46998. var target = {
  46999. shape: {}
  47000. };
  47001. setLinePoints(target.shape, linePoints);
  47002. updateProps(line, target, seriesModel, idx);
  47003. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  47004. var symbolType = lineData.getItemVisual(idx, symbolCategory);
  47005. var key = makeSymbolTypeKey(symbolCategory);
  47006. // Symbol changed
  47007. if (this[key] !== symbolType) {
  47008. this.remove(this.childOfName(symbolCategory));
  47009. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  47010. this.add(symbol);
  47011. }
  47012. this[key] = symbolType;
  47013. }, this);
  47014. this._updateCommonStl(lineData, idx, seriesScope);
  47015. };
  47016. lineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  47017. var seriesModel = lineData.hostModel;
  47018. var line = this.childOfName('line');
  47019. var lineStyle = seriesScope && seriesScope.lineStyle;
  47020. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  47021. var labelModel = seriesScope && seriesScope.labelModel;
  47022. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  47023. // Optimization for large dataset
  47024. if (!seriesScope || lineData.hasItemOption) {
  47025. var itemModel = lineData.getItemModel(idx);
  47026. lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  47027. hoverLineStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
  47028. labelModel = itemModel.getModel('label');
  47029. hoverLabelModel = itemModel.getModel('emphasis.label');
  47030. }
  47031. var visualColor = lineData.getItemVisual(idx, 'color');
  47032. var visualOpacity = retrieve3(
  47033. lineData.getItemVisual(idx, 'opacity'),
  47034. lineStyle.opacity,
  47035. 1
  47036. );
  47037. line.useStyle(defaults(
  47038. {
  47039. strokeNoScale: true,
  47040. fill: 'none',
  47041. stroke: visualColor,
  47042. opacity: visualOpacity
  47043. },
  47044. lineStyle
  47045. ));
  47046. line.hoverStyle = hoverLineStyle;
  47047. // Update symbol
  47048. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  47049. var symbol = this.childOfName(symbolCategory);
  47050. if (symbol) {
  47051. symbol.setColor(visualColor);
  47052. symbol.setStyle({
  47053. opacity: visualOpacity
  47054. });
  47055. }
  47056. }, this);
  47057. var showLabel = labelModel.getShallow('show');
  47058. var hoverShowLabel = hoverLabelModel.getShallow('show');
  47059. var label = this.childOfName('label');
  47060. var defaultLabelColor;
  47061. var baseText;
  47062. // FIXME: the logic below probably should be merged to `graphic.setLabelStyle`.
  47063. if (showLabel || hoverShowLabel) {
  47064. defaultLabelColor = visualColor || '#000';
  47065. baseText = seriesModel.getFormattedLabel(idx, 'normal', lineData.dataType);
  47066. if (baseText == null) {
  47067. var rawVal = seriesModel.getRawValue(idx);
  47068. baseText = rawVal == null
  47069. ? lineData.getName(idx)
  47070. : isFinite(rawVal)
  47071. ? round$2(rawVal)
  47072. : rawVal;
  47073. }
  47074. }
  47075. var normalText = showLabel ? baseText : null;
  47076. var emphasisText = hoverShowLabel
  47077. ? retrieve2(
  47078. seriesModel.getFormattedLabel(idx, 'emphasis', lineData.dataType),
  47079. baseText
  47080. )
  47081. : null;
  47082. var labelStyle = label.style;
  47083. // Always set `textStyle` even if `normalStyle.text` is null, because default
  47084. // values have to be set on `normalStyle`.
  47085. if (normalText != null || emphasisText != null) {
  47086. setTextStyle(label.style, labelModel, {
  47087. text: normalText
  47088. }, {
  47089. autoColor: defaultLabelColor
  47090. });
  47091. label.__textAlign = labelStyle.textAlign;
  47092. label.__verticalAlign = labelStyle.textVerticalAlign;
  47093. // 'start', 'middle', 'end'
  47094. label.__position = labelModel.get('position') || 'middle';
  47095. }
  47096. if (emphasisText != null) {
  47097. // Only these properties supported in this emphasis style here.
  47098. label.hoverStyle = {
  47099. text: emphasisText,
  47100. textFill: hoverLabelModel.getTextColor(true),
  47101. // For merging hover style to normal style, do not use
  47102. // `hoverLabelModel.getFont()` here.
  47103. fontStyle: hoverLabelModel.getShallow('fontStyle'),
  47104. fontWeight: hoverLabelModel.getShallow('fontWeight'),
  47105. fontSize: hoverLabelModel.getShallow('fontSize'),
  47106. fontFamily: hoverLabelModel.getShallow('fontFamily')
  47107. };
  47108. }
  47109. else {
  47110. label.hoverStyle = {
  47111. text: null
  47112. };
  47113. }
  47114. label.ignore = !showLabel && !hoverShowLabel;
  47115. setHoverStyle(this);
  47116. };
  47117. lineProto.highlight = function () {
  47118. this.trigger('emphasis');
  47119. };
  47120. lineProto.downplay = function () {
  47121. this.trigger('normal');
  47122. };
  47123. lineProto.updateLayout = function (lineData, idx) {
  47124. this.setLinePoints(lineData.getItemLayout(idx));
  47125. };
  47126. lineProto.setLinePoints = function (points) {
  47127. var linePath = this.childOfName('line');
  47128. setLinePoints(linePath.shape, points);
  47129. linePath.dirty();
  47130. };
  47131. inherits(Line$1, Group);
  47132. /*
  47133. * Licensed to the Apache Software Foundation (ASF) under one
  47134. * or more contributor license agreements. See the NOTICE file
  47135. * distributed with this work for additional information
  47136. * regarding copyright ownership. The ASF licenses this file
  47137. * to you under the Apache License, Version 2.0 (the
  47138. * "License"); you may not use this file except in compliance
  47139. * with the License. You may obtain a copy of the License at
  47140. *
  47141. * http://www.apache.org/licenses/LICENSE-2.0
  47142. *
  47143. * Unless required by applicable law or agreed to in writing,
  47144. * software distributed under the License is distributed on an
  47145. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47146. * KIND, either express or implied. See the License for the
  47147. * specific language governing permissions and limitations
  47148. * under the License.
  47149. */
  47150. /**
  47151. * @module echarts/chart/helper/LineDraw
  47152. */
  47153. // import IncrementalDisplayable from 'zrender/src/graphic/IncrementalDisplayable';
  47154. /**
  47155. * @alias module:echarts/component/marker/LineDraw
  47156. * @constructor
  47157. */
  47158. function LineDraw(ctor) {
  47159. this._ctor = ctor || Line$1;
  47160. this.group = new Group();
  47161. }
  47162. var lineDrawProto = LineDraw.prototype;
  47163. lineDrawProto.isPersistent = function () {
  47164. return true;
  47165. };
  47166. /**
  47167. * @param {module:echarts/data/List} lineData
  47168. */
  47169. lineDrawProto.updateData = function (lineData) {
  47170. var lineDraw = this;
  47171. var group = lineDraw.group;
  47172. var oldLineData = lineDraw._lineData;
  47173. lineDraw._lineData = lineData;
  47174. // There is no oldLineData only when first rendering or switching from
  47175. // stream mode to normal mode, where previous elements should be removed.
  47176. if (!oldLineData) {
  47177. group.removeAll();
  47178. }
  47179. var seriesScope = makeSeriesScope$1(lineData);
  47180. lineData.diff(oldLineData)
  47181. .add(function (idx) {
  47182. doAdd(lineDraw, lineData, idx, seriesScope);
  47183. })
  47184. .update(function (newIdx, oldIdx) {
  47185. doUpdate(lineDraw, oldLineData, lineData, oldIdx, newIdx, seriesScope);
  47186. })
  47187. .remove(function (idx) {
  47188. group.remove(oldLineData.getItemGraphicEl(idx));
  47189. })
  47190. .execute();
  47191. };
  47192. function doAdd(lineDraw, lineData, idx, seriesScope) {
  47193. var itemLayout = lineData.getItemLayout(idx);
  47194. if (!lineNeedsDraw(itemLayout)) {
  47195. return;
  47196. }
  47197. var el = new lineDraw._ctor(lineData, idx, seriesScope);
  47198. lineData.setItemGraphicEl(idx, el);
  47199. lineDraw.group.add(el);
  47200. }
  47201. function doUpdate(lineDraw, oldLineData, newLineData, oldIdx, newIdx, seriesScope) {
  47202. var itemEl = oldLineData.getItemGraphicEl(oldIdx);
  47203. if (!lineNeedsDraw(newLineData.getItemLayout(newIdx))) {
  47204. lineDraw.group.remove(itemEl);
  47205. return;
  47206. }
  47207. if (!itemEl) {
  47208. itemEl = new lineDraw._ctor(newLineData, newIdx, seriesScope);
  47209. }
  47210. else {
  47211. itemEl.updateData(newLineData, newIdx, seriesScope);
  47212. }
  47213. newLineData.setItemGraphicEl(newIdx, itemEl);
  47214. lineDraw.group.add(itemEl);
  47215. }
  47216. lineDrawProto.updateLayout = function () {
  47217. var lineData = this._lineData;
  47218. // Do not support update layout in incremental mode.
  47219. if (!lineData) {
  47220. return;
  47221. }
  47222. lineData.eachItemGraphicEl(function (el, idx) {
  47223. el.updateLayout(lineData, idx);
  47224. }, this);
  47225. };
  47226. lineDrawProto.incrementalPrepareUpdate = function (lineData) {
  47227. this._seriesScope = makeSeriesScope$1(lineData);
  47228. this._lineData = null;
  47229. this.group.removeAll();
  47230. };
  47231. lineDrawProto.incrementalUpdate = function (taskParams, lineData) {
  47232. function updateIncrementalAndHover(el) {
  47233. if (!el.isGroup) {
  47234. el.incremental = el.useHoverLayer = true;
  47235. }
  47236. }
  47237. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  47238. var itemLayout = lineData.getItemLayout(idx);
  47239. if (lineNeedsDraw(itemLayout)) {
  47240. var el = new this._ctor(lineData, idx, this._seriesScope);
  47241. el.traverse(updateIncrementalAndHover);
  47242. this.group.add(el);
  47243. lineData.setItemGraphicEl(idx, el);
  47244. }
  47245. }
  47246. };
  47247. function makeSeriesScope$1(lineData) {
  47248. var hostModel = lineData.hostModel;
  47249. return {
  47250. lineStyle: hostModel.getModel('lineStyle').getLineStyle(),
  47251. hoverLineStyle: hostModel.getModel('emphasis.lineStyle').getLineStyle(),
  47252. labelModel: hostModel.getModel('label'),
  47253. hoverLabelModel: hostModel.getModel('emphasis.label')
  47254. };
  47255. }
  47256. lineDrawProto.remove = function () {
  47257. this._clearIncremental();
  47258. this._incremental = null;
  47259. this.group.removeAll();
  47260. };
  47261. lineDrawProto._clearIncremental = function () {
  47262. var incremental = this._incremental;
  47263. if (incremental) {
  47264. incremental.clearDisplaybles();
  47265. }
  47266. };
  47267. function isPointNaN(pt) {
  47268. return isNaN(pt[0]) || isNaN(pt[1]);
  47269. }
  47270. function lineNeedsDraw(pts) {
  47271. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  47272. }
  47273. /*
  47274. * Licensed to the Apache Software Foundation (ASF) under one
  47275. * or more contributor license agreements. See the NOTICE file
  47276. * distributed with this work for additional information
  47277. * regarding copyright ownership. The ASF licenses this file
  47278. * to you under the Apache License, Version 2.0 (the
  47279. * "License"); you may not use this file except in compliance
  47280. * with the License. You may obtain a copy of the License at
  47281. *
  47282. * http://www.apache.org/licenses/LICENSE-2.0
  47283. *
  47284. * Unless required by applicable law or agreed to in writing,
  47285. * software distributed under the License is distributed on an
  47286. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47287. * KIND, either express or implied. See the License for the
  47288. * specific language governing permissions and limitations
  47289. * under the License.
  47290. */
  47291. var v1 = [];
  47292. var v2 = [];
  47293. var v3 = [];
  47294. var quadraticAt$1 = quadraticAt;
  47295. var v2DistSquare = distSquare;
  47296. var mathAbs$1 = Math.abs;
  47297. function intersectCurveCircle(curvePoints, center, radius) {
  47298. var p0 = curvePoints[0];
  47299. var p1 = curvePoints[1];
  47300. var p2 = curvePoints[2];
  47301. var d = Infinity;
  47302. var t;
  47303. var radiusSquare = radius * radius;
  47304. var interval = 0.1;
  47305. for (var _t = 0.1; _t <= 0.9; _t += 0.1) {
  47306. v1[0] = quadraticAt$1(p0[0], p1[0], p2[0], _t);
  47307. v1[1] = quadraticAt$1(p0[1], p1[1], p2[1], _t);
  47308. var diff = mathAbs$1(v2DistSquare(v1, center) - radiusSquare);
  47309. if (diff < d) {
  47310. d = diff;
  47311. t = _t;
  47312. }
  47313. }
  47314. // Assume the segment is monotone,Find root through Bisection method
  47315. // At most 32 iteration
  47316. for (var i = 0; i < 32; i++) {
  47317. // var prev = t - interval;
  47318. var next = t + interval;
  47319. // v1[0] = quadraticAt(p0[0], p1[0], p2[0], prev);
  47320. // v1[1] = quadraticAt(p0[1], p1[1], p2[1], prev);
  47321. v2[0] = quadraticAt$1(p0[0], p1[0], p2[0], t);
  47322. v2[1] = quadraticAt$1(p0[1], p1[1], p2[1], t);
  47323. v3[0] = quadraticAt$1(p0[0], p1[0], p2[0], next);
  47324. v3[1] = quadraticAt$1(p0[1], p1[1], p2[1], next);
  47325. var diff = v2DistSquare(v2, center) - radiusSquare;
  47326. if (mathAbs$1(diff) < 1e-2) {
  47327. break;
  47328. }
  47329. // var prevDiff = v2DistSquare(v1, center) - radiusSquare;
  47330. var nextDiff = v2DistSquare(v3, center) - radiusSquare;
  47331. interval /= 2;
  47332. if (diff < 0) {
  47333. if (nextDiff >= 0) {
  47334. t = t + interval;
  47335. }
  47336. else {
  47337. t = t - interval;
  47338. }
  47339. }
  47340. else {
  47341. if (nextDiff >= 0) {
  47342. t = t - interval;
  47343. }
  47344. else {
  47345. t = t + interval;
  47346. }
  47347. }
  47348. }
  47349. return t;
  47350. }
  47351. // Adjust edge to avoid
  47352. var adjustEdge = function (graph, scale$$1) {
  47353. var tmp0 = [];
  47354. var quadraticSubdivide$$1 = quadraticSubdivide;
  47355. var pts = [[], [], []];
  47356. var pts2 = [[], []];
  47357. var v = [];
  47358. scale$$1 /= 2;
  47359. function getSymbolSize(node) {
  47360. var symbolSize = node.getVisual('symbolSize');
  47361. if (symbolSize instanceof Array) {
  47362. symbolSize = (symbolSize[0] + symbolSize[1]) / 2;
  47363. }
  47364. return symbolSize;
  47365. }
  47366. graph.eachEdge(function (edge, idx) {
  47367. var linePoints = edge.getLayout();
  47368. var fromSymbol = edge.getVisual('fromSymbol');
  47369. var toSymbol = edge.getVisual('toSymbol');
  47370. if (!linePoints.__original) {
  47371. linePoints.__original = [
  47372. clone$1(linePoints[0]),
  47373. clone$1(linePoints[1])
  47374. ];
  47375. if (linePoints[2]) {
  47376. linePoints.__original.push(clone$1(linePoints[2]));
  47377. }
  47378. }
  47379. var originalPoints = linePoints.__original;
  47380. // Quadratic curve
  47381. if (linePoints[2] != null) {
  47382. copy(pts[0], originalPoints[0]);
  47383. copy(pts[1], originalPoints[2]);
  47384. copy(pts[2], originalPoints[1]);
  47385. if (fromSymbol && fromSymbol !== 'none') {
  47386. var symbolSize = getSymbolSize(edge.node1);
  47387. var t = intersectCurveCircle(pts, originalPoints[0], symbolSize * scale$$1);
  47388. // Subdivide and get the second
  47389. quadraticSubdivide$$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  47390. pts[0][0] = tmp0[3];
  47391. pts[1][0] = tmp0[4];
  47392. quadraticSubdivide$$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  47393. pts[0][1] = tmp0[3];
  47394. pts[1][1] = tmp0[4];
  47395. }
  47396. if (toSymbol && toSymbol !== 'none') {
  47397. var symbolSize = getSymbolSize(edge.node2);
  47398. var t = intersectCurveCircle(pts, originalPoints[1], symbolSize * scale$$1);
  47399. // Subdivide and get the first
  47400. quadraticSubdivide$$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  47401. pts[1][0] = tmp0[1];
  47402. pts[2][0] = tmp0[2];
  47403. quadraticSubdivide$$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  47404. pts[1][1] = tmp0[1];
  47405. pts[2][1] = tmp0[2];
  47406. }
  47407. // Copy back to layout
  47408. copy(linePoints[0], pts[0]);
  47409. copy(linePoints[1], pts[2]);
  47410. copy(linePoints[2], pts[1]);
  47411. }
  47412. // Line
  47413. else {
  47414. copy(pts2[0], originalPoints[0]);
  47415. copy(pts2[1], originalPoints[1]);
  47416. sub(v, pts2[1], pts2[0]);
  47417. normalize(v, v);
  47418. if (fromSymbol && fromSymbol !== 'none') {
  47419. var symbolSize = getSymbolSize(edge.node1);
  47420. scaleAndAdd(pts2[0], pts2[0], v, symbolSize * scale$$1);
  47421. }
  47422. if (toSymbol && toSymbol !== 'none') {
  47423. var symbolSize = getSymbolSize(edge.node2);
  47424. scaleAndAdd(pts2[1], pts2[1], v, -symbolSize * scale$$1);
  47425. }
  47426. copy(linePoints[0], pts2[0]);
  47427. copy(linePoints[1], pts2[1]);
  47428. }
  47429. });
  47430. };
  47431. /*
  47432. * Licensed to the Apache Software Foundation (ASF) under one
  47433. * or more contributor license agreements. See the NOTICE file
  47434. * distributed with this work for additional information
  47435. * regarding copyright ownership. The ASF licenses this file
  47436. * to you under the Apache License, Version 2.0 (the
  47437. * "License"); you may not use this file except in compliance
  47438. * with the License. You may obtain a copy of the License at
  47439. *
  47440. * http://www.apache.org/licenses/LICENSE-2.0
  47441. *
  47442. * Unless required by applicable law or agreed to in writing,
  47443. * software distributed under the License is distributed on an
  47444. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47445. * KIND, either express or implied. See the License for the
  47446. * specific language governing permissions and limitations
  47447. * under the License.
  47448. */
  47449. var FOCUS_ADJACENCY = '__focusNodeAdjacency';
  47450. var UNFOCUS_ADJACENCY = '__unfocusNodeAdjacency';
  47451. var nodeOpacityPath = ['itemStyle', 'opacity'];
  47452. var lineOpacityPath = ['lineStyle', 'opacity'];
  47453. function getItemOpacity(item, opacityPath) {
  47454. return item.getVisual('opacity') || item.getModel().get(opacityPath);
  47455. }
  47456. function fadeOutItem(item, opacityPath, opacityRatio) {
  47457. var el = item.getGraphicEl();
  47458. var opacity = getItemOpacity(item, opacityPath);
  47459. if (opacityRatio != null) {
  47460. opacity == null && (opacity = 1);
  47461. opacity *= opacityRatio;
  47462. }
  47463. el.downplay && el.downplay();
  47464. el.traverse(function (child) {
  47465. if (child.type !== 'group') {
  47466. var opct = child.lineLabelOriginalOpacity;
  47467. if (opct == null || opacityRatio != null) {
  47468. opct = opacity;
  47469. }
  47470. child.setStyle('opacity', opct);
  47471. }
  47472. });
  47473. }
  47474. function fadeInItem(item, opacityPath) {
  47475. var opacity = getItemOpacity(item, opacityPath);
  47476. var el = item.getGraphicEl();
  47477. el.highlight && el.highlight();
  47478. el.traverse(function (child) {
  47479. if (child.type !== 'group') {
  47480. child.setStyle('opacity', opacity);
  47481. }
  47482. });
  47483. }
  47484. extendChartView({
  47485. type: 'graph',
  47486. init: function (ecModel, api) {
  47487. var symbolDraw = new SymbolDraw();
  47488. var lineDraw = new LineDraw();
  47489. var group = this.group;
  47490. this._controller = new RoamController(api.getZr());
  47491. this._controllerHost = {target: group};
  47492. group.add(symbolDraw.group);
  47493. group.add(lineDraw.group);
  47494. this._symbolDraw = symbolDraw;
  47495. this._lineDraw = lineDraw;
  47496. this._firstRender = true;
  47497. },
  47498. render: function (seriesModel, ecModel, api) {
  47499. var coordSys = seriesModel.coordinateSystem;
  47500. this._model = seriesModel;
  47501. this._nodeScaleRatio = seriesModel.get('nodeScaleRatio');
  47502. var symbolDraw = this._symbolDraw;
  47503. var lineDraw = this._lineDraw;
  47504. var group = this.group;
  47505. if (coordSys.type === 'view') {
  47506. var groupNewProp = {
  47507. position: coordSys.position,
  47508. scale: coordSys.scale
  47509. };
  47510. if (this._firstRender) {
  47511. group.attr(groupNewProp);
  47512. }
  47513. else {
  47514. updateProps(group, groupNewProp, seriesModel);
  47515. }
  47516. }
  47517. // Fix edge contact point with node
  47518. adjustEdge(seriesModel.getGraph(), this._getNodeGlobalScale(seriesModel));
  47519. var data = seriesModel.getData();
  47520. symbolDraw.updateData(data);
  47521. var edgeData = seriesModel.getEdgeData();
  47522. lineDraw.updateData(edgeData);
  47523. this._updateNodeAndLinkScale();
  47524. this._updateController(seriesModel, ecModel, api);
  47525. clearTimeout(this._layoutTimeout);
  47526. var forceLayout = seriesModel.forceLayout;
  47527. var layoutAnimation = seriesModel.get('force.layoutAnimation');
  47528. if (forceLayout) {
  47529. this._startForceLayoutIteration(forceLayout, layoutAnimation);
  47530. }
  47531. data.eachItemGraphicEl(function (el, idx) {
  47532. var itemModel = data.getItemModel(idx);
  47533. // Update draggable
  47534. el.off('drag').off('dragend');
  47535. var draggable = itemModel.get('draggable');
  47536. if (draggable) {
  47537. el.on('drag', function () {
  47538. if (forceLayout) {
  47539. forceLayout.warmUp();
  47540. !this._layouting
  47541. && this._startForceLayoutIteration(forceLayout, layoutAnimation);
  47542. forceLayout.setFixed(idx);
  47543. // Write position back to layout
  47544. data.setItemLayout(idx, el.position);
  47545. }
  47546. }, this).on('dragend', function () {
  47547. if (forceLayout) {
  47548. forceLayout.setUnfixed(idx);
  47549. }
  47550. }, this);
  47551. }
  47552. el.setDraggable(draggable && forceLayout);
  47553. el[FOCUS_ADJACENCY] && el.off('mouseover', el[FOCUS_ADJACENCY]);
  47554. el[UNFOCUS_ADJACENCY] && el.off('mouseout', el[UNFOCUS_ADJACENCY]);
  47555. if (itemModel.get('focusNodeAdjacency')) {
  47556. el.on('mouseover', el[FOCUS_ADJACENCY] = function () {
  47557. api.dispatchAction({
  47558. type: 'focusNodeAdjacency',
  47559. seriesId: seriesModel.id,
  47560. dataIndex: el.dataIndex
  47561. });
  47562. });
  47563. el.on('mouseout', el[UNFOCUS_ADJACENCY] = function () {
  47564. api.dispatchAction({
  47565. type: 'unfocusNodeAdjacency',
  47566. seriesId: seriesModel.id
  47567. });
  47568. });
  47569. }
  47570. }, this);
  47571. data.graph.eachEdge(function (edge) {
  47572. var el = edge.getGraphicEl();
  47573. el[FOCUS_ADJACENCY] && el.off('mouseover', el[FOCUS_ADJACENCY]);
  47574. el[UNFOCUS_ADJACENCY] && el.off('mouseout', el[UNFOCUS_ADJACENCY]);
  47575. if (edge.getModel().get('focusNodeAdjacency')) {
  47576. el.on('mouseover', el[FOCUS_ADJACENCY] = function () {
  47577. api.dispatchAction({
  47578. type: 'focusNodeAdjacency',
  47579. seriesId: seriesModel.id,
  47580. edgeDataIndex: edge.dataIndex
  47581. });
  47582. });
  47583. el.on('mouseout', el[UNFOCUS_ADJACENCY] = function () {
  47584. api.dispatchAction({
  47585. type: 'unfocusNodeAdjacency',
  47586. seriesId: seriesModel.id
  47587. });
  47588. });
  47589. }
  47590. });
  47591. var circularRotateLabel = seriesModel.get('layout') === 'circular'
  47592. && seriesModel.get('circular.rotateLabel');
  47593. var cx = data.getLayout('cx');
  47594. var cy = data.getLayout('cy');
  47595. data.eachItemGraphicEl(function (el, idx) {
  47596. var symbolPath = el.getSymbolPath();
  47597. if (circularRotateLabel) {
  47598. var pos = data.getItemLayout(idx);
  47599. var rad = Math.atan2(pos[1] - cy, pos[0] - cx);
  47600. if (rad < 0) {
  47601. rad = Math.PI * 2 + rad;
  47602. }
  47603. var isLeft = pos[0] < cx;
  47604. if (isLeft) {
  47605. rad = rad - Math.PI;
  47606. }
  47607. var textPosition = isLeft ? 'left' : 'right';
  47608. symbolPath.setStyle({
  47609. textRotation: -rad,
  47610. textPosition: textPosition,
  47611. textOrigin: 'center'
  47612. });
  47613. symbolPath.hoverStyle && (symbolPath.hoverStyle.textPosition = textPosition);
  47614. }
  47615. else {
  47616. symbolPath.setStyle({
  47617. textRotation: 0
  47618. });
  47619. }
  47620. });
  47621. this._firstRender = false;
  47622. },
  47623. dispose: function () {
  47624. this._controller && this._controller.dispose();
  47625. this._controllerHost = {};
  47626. },
  47627. focusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  47628. var data = this._model.getData();
  47629. var graph = data.graph;
  47630. var dataIndex = payload.dataIndex;
  47631. var edgeDataIndex = payload.edgeDataIndex;
  47632. var node = graph.getNodeByIndex(dataIndex);
  47633. var edge = graph.getEdgeByIndex(edgeDataIndex);
  47634. if (!node && !edge) {
  47635. return;
  47636. }
  47637. graph.eachNode(function (node) {
  47638. fadeOutItem(node, nodeOpacityPath, 0.1);
  47639. });
  47640. graph.eachEdge(function (edge) {
  47641. fadeOutItem(edge, lineOpacityPath, 0.1);
  47642. });
  47643. if (node) {
  47644. fadeInItem(node, nodeOpacityPath);
  47645. each$1(node.edges, function (adjacentEdge) {
  47646. if (adjacentEdge.dataIndex < 0) {
  47647. return;
  47648. }
  47649. fadeInItem(adjacentEdge, lineOpacityPath);
  47650. fadeInItem(adjacentEdge.node1, nodeOpacityPath);
  47651. fadeInItem(adjacentEdge.node2, nodeOpacityPath);
  47652. });
  47653. }
  47654. if (edge) {
  47655. fadeInItem(edge, lineOpacityPath);
  47656. fadeInItem(edge.node1, nodeOpacityPath);
  47657. fadeInItem(edge.node2, nodeOpacityPath);
  47658. }
  47659. },
  47660. unfocusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  47661. var graph = this._model.getData().graph;
  47662. graph.eachNode(function (node) {
  47663. fadeOutItem(node, nodeOpacityPath);
  47664. });
  47665. graph.eachEdge(function (edge) {
  47666. fadeOutItem(edge, lineOpacityPath);
  47667. });
  47668. },
  47669. _startForceLayoutIteration: function (forceLayout, layoutAnimation) {
  47670. var self = this;
  47671. (function step() {
  47672. forceLayout.step(function (stopped) {
  47673. self.updateLayout(self._model);
  47674. (self._layouting = !stopped) && (
  47675. layoutAnimation
  47676. ? (self._layoutTimeout = setTimeout(step, 16))
  47677. : step()
  47678. );
  47679. });
  47680. })();
  47681. },
  47682. _updateController: function (seriesModel, ecModel, api) {
  47683. var controller = this._controller;
  47684. var controllerHost = this._controllerHost;
  47685. var group = this.group;
  47686. controller.setPointerChecker(function (e, x, y) {
  47687. var rect = group.getBoundingRect();
  47688. rect.applyTransform(group.transform);
  47689. return rect.contain(x, y)
  47690. && !onIrrelevantElement(e, api, seriesModel);
  47691. });
  47692. if (seriesModel.coordinateSystem.type !== 'view') {
  47693. controller.disable();
  47694. return;
  47695. }
  47696. controller.enable(seriesModel.get('roam'));
  47697. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  47698. controllerHost.zoom = seriesModel.coordinateSystem.getZoom();
  47699. controller
  47700. .off('pan')
  47701. .off('zoom')
  47702. .on('pan', function (e) {
  47703. updateViewOnPan(controllerHost, e.dx, e.dy);
  47704. api.dispatchAction({
  47705. seriesId: seriesModel.id,
  47706. type: 'graphRoam',
  47707. dx: e.dx,
  47708. dy: e.dy
  47709. });
  47710. })
  47711. .on('zoom', function (e) {
  47712. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  47713. api.dispatchAction({
  47714. seriesId: seriesModel.id,
  47715. type: 'graphRoam',
  47716. zoom: e.scale,
  47717. originX: e.originX,
  47718. originY: e.originY
  47719. });
  47720. this._updateNodeAndLinkScale();
  47721. adjustEdge(seriesModel.getGraph(), this._getNodeGlobalScale(seriesModel));
  47722. this._lineDraw.updateLayout();
  47723. }, this);
  47724. },
  47725. _updateNodeAndLinkScale: function () {
  47726. var seriesModel = this._model;
  47727. var data = seriesModel.getData();
  47728. var nodeScale = this._getNodeGlobalScale(seriesModel);
  47729. var invScale = [nodeScale, nodeScale];
  47730. data.eachItemGraphicEl(function (el, idx) {
  47731. el.attr('scale', invScale);
  47732. });
  47733. },
  47734. _getNodeGlobalScale: function (seriesModel) {
  47735. var coordSys = seriesModel.coordinateSystem;
  47736. if (coordSys.type !== 'view') {
  47737. return 1;
  47738. }
  47739. var nodeScaleRatio = this._nodeScaleRatio;
  47740. var groupScale = coordSys.scale;
  47741. var groupZoom = (groupScale && groupScale[0]) || 1;
  47742. // Scale node when zoom changes
  47743. var roamZoom = coordSys.getZoom();
  47744. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  47745. return nodeScale / groupZoom;
  47746. },
  47747. updateLayout: function (seriesModel) {
  47748. adjustEdge(seriesModel.getGraph(), this._getNodeGlobalScale(seriesModel));
  47749. this._symbolDraw.updateLayout();
  47750. this._lineDraw.updateLayout();
  47751. },
  47752. remove: function (ecModel, api) {
  47753. this._symbolDraw && this._symbolDraw.remove();
  47754. this._lineDraw && this._lineDraw.remove();
  47755. }
  47756. });
  47757. /*
  47758. * Licensed to the Apache Software Foundation (ASF) under one
  47759. * or more contributor license agreements. See the NOTICE file
  47760. * distributed with this work for additional information
  47761. * regarding copyright ownership. The ASF licenses this file
  47762. * to you under the Apache License, Version 2.0 (the
  47763. * "License"); you may not use this file except in compliance
  47764. * with the License. You may obtain a copy of the License at
  47765. *
  47766. * http://www.apache.org/licenses/LICENSE-2.0
  47767. *
  47768. * Unless required by applicable law or agreed to in writing,
  47769. * software distributed under the License is distributed on an
  47770. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47771. * KIND, either express or implied. See the License for the
  47772. * specific language governing permissions and limitations
  47773. * under the License.
  47774. */
  47775. /**
  47776. * @payload
  47777. * @property {number} [seriesIndex]
  47778. * @property {string} [seriesId]
  47779. * @property {string} [seriesName]
  47780. * @property {number} [dataIndex]
  47781. */
  47782. registerAction({
  47783. type: 'focusNodeAdjacency',
  47784. event: 'focusNodeAdjacency',
  47785. update: 'series:focusNodeAdjacency'
  47786. }, function () {});
  47787. /**
  47788. * @payload
  47789. * @property {number} [seriesIndex]
  47790. * @property {string} [seriesId]
  47791. * @property {string} [seriesName]
  47792. */
  47793. registerAction({
  47794. type: 'unfocusNodeAdjacency',
  47795. event: 'unfocusNodeAdjacency',
  47796. update: 'series:unfocusNodeAdjacency'
  47797. }, function () {});
  47798. /*
  47799. * Licensed to the Apache Software Foundation (ASF) under one
  47800. * or more contributor license agreements. See the NOTICE file
  47801. * distributed with this work for additional information
  47802. * regarding copyright ownership. The ASF licenses this file
  47803. * to you under the Apache License, Version 2.0 (the
  47804. * "License"); you may not use this file except in compliance
  47805. * with the License. You may obtain a copy of the License at
  47806. *
  47807. * http://www.apache.org/licenses/LICENSE-2.0
  47808. *
  47809. * Unless required by applicable law or agreed to in writing,
  47810. * software distributed under the License is distributed on an
  47811. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47812. * KIND, either express or implied. See the License for the
  47813. * specific language governing permissions and limitations
  47814. * under the License.
  47815. */
  47816. var actionInfo = {
  47817. type: 'graphRoam',
  47818. event: 'graphRoam',
  47819. update: 'none'
  47820. };
  47821. /**
  47822. * @payload
  47823. * @property {string} name Series name
  47824. * @property {number} [dx]
  47825. * @property {number} [dy]
  47826. * @property {number} [zoom]
  47827. * @property {number} [originX]
  47828. * @property {number} [originY]
  47829. */
  47830. registerAction(actionInfo, function (payload, ecModel) {
  47831. ecModel.eachComponent({mainType: 'series', query: payload}, function (seriesModel) {
  47832. var coordSys = seriesModel.coordinateSystem;
  47833. var res = updateCenterAndZoom(coordSys, payload);
  47834. seriesModel.setCenter
  47835. && seriesModel.setCenter(res.center);
  47836. seriesModel.setZoom
  47837. && seriesModel.setZoom(res.zoom);
  47838. });
  47839. });
  47840. /*
  47841. * Licensed to the Apache Software Foundation (ASF) under one
  47842. * or more contributor license agreements. See the NOTICE file
  47843. * distributed with this work for additional information
  47844. * regarding copyright ownership. The ASF licenses this file
  47845. * to you under the Apache License, Version 2.0 (the
  47846. * "License"); you may not use this file except in compliance
  47847. * with the License. You may obtain a copy of the License at
  47848. *
  47849. * http://www.apache.org/licenses/LICENSE-2.0
  47850. *
  47851. * Unless required by applicable law or agreed to in writing,
  47852. * software distributed under the License is distributed on an
  47853. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47854. * KIND, either express or implied. See the License for the
  47855. * specific language governing permissions and limitations
  47856. * under the License.
  47857. */
  47858. var categoryFilter = function (ecModel) {
  47859. var legendModels = ecModel.findComponents({
  47860. mainType: 'legend'
  47861. });
  47862. if (!legendModels || !legendModels.length) {
  47863. return;
  47864. }
  47865. ecModel.eachSeriesByType('graph', function (graphSeries) {
  47866. var categoriesData = graphSeries.getCategoriesData();
  47867. var graph = graphSeries.getGraph();
  47868. var data = graph.data;
  47869. var categoryNames = categoriesData.mapArray(categoriesData.getName);
  47870. data.filterSelf(function (idx) {
  47871. var model = data.getItemModel(idx);
  47872. var category = model.getShallow('category');
  47873. if (category != null) {
  47874. if (typeof category === 'number') {
  47875. category = categoryNames[category];
  47876. }
  47877. // If in any legend component the status is not selected.
  47878. for (var i = 0; i < legendModels.length; i++) {
  47879. if (!legendModels[i].isSelected(category)) {
  47880. return false;
  47881. }
  47882. }
  47883. }
  47884. return true;
  47885. });
  47886. }, this);
  47887. };
  47888. /*
  47889. * Licensed to the Apache Software Foundation (ASF) under one
  47890. * or more contributor license agreements. See the NOTICE file
  47891. * distributed with this work for additional information
  47892. * regarding copyright ownership. The ASF licenses this file
  47893. * to you under the Apache License, Version 2.0 (the
  47894. * "License"); you may not use this file except in compliance
  47895. * with the License. You may obtain a copy of the License at
  47896. *
  47897. * http://www.apache.org/licenses/LICENSE-2.0
  47898. *
  47899. * Unless required by applicable law or agreed to in writing,
  47900. * software distributed under the License is distributed on an
  47901. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47902. * KIND, either express or implied. See the License for the
  47903. * specific language governing permissions and limitations
  47904. * under the License.
  47905. */
  47906. var categoryVisual = function (ecModel) {
  47907. var paletteScope = {};
  47908. ecModel.eachSeriesByType('graph', function (seriesModel) {
  47909. var categoriesData = seriesModel.getCategoriesData();
  47910. var data = seriesModel.getData();
  47911. var categoryNameIdxMap = {};
  47912. categoriesData.each(function (idx) {
  47913. var name = categoriesData.getName(idx);
  47914. // Add prefix to avoid conflict with Object.prototype.
  47915. categoryNameIdxMap['ec-' + name] = idx;
  47916. var itemModel = categoriesData.getItemModel(idx);
  47917. var color = itemModel.get('itemStyle.color')
  47918. || seriesModel.getColorFromPalette(name, paletteScope);
  47919. categoriesData.setItemVisual(idx, 'color', color);
  47920. });
  47921. // Assign category color to visual
  47922. if (categoriesData.count()) {
  47923. data.each(function (idx) {
  47924. var model = data.getItemModel(idx);
  47925. var category = model.getShallow('category');
  47926. if (category != null) {
  47927. if (typeof category === 'string') {
  47928. category = categoryNameIdxMap['ec-' + category];
  47929. }
  47930. if (!data.getItemVisual(idx, 'color', true)) {
  47931. data.setItemVisual(
  47932. idx, 'color',
  47933. categoriesData.getItemVisual(category, 'color')
  47934. );
  47935. }
  47936. }
  47937. });
  47938. }
  47939. });
  47940. };
  47941. /*
  47942. * Licensed to the Apache Software Foundation (ASF) under one
  47943. * or more contributor license agreements. See the NOTICE file
  47944. * distributed with this work for additional information
  47945. * regarding copyright ownership. The ASF licenses this file
  47946. * to you under the Apache License, Version 2.0 (the
  47947. * "License"); you may not use this file except in compliance
  47948. * with the License. You may obtain a copy of the License at
  47949. *
  47950. * http://www.apache.org/licenses/LICENSE-2.0
  47951. *
  47952. * Unless required by applicable law or agreed to in writing,
  47953. * software distributed under the License is distributed on an
  47954. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47955. * KIND, either express or implied. See the License for the
  47956. * specific language governing permissions and limitations
  47957. * under the License.
  47958. */
  47959. function normalize$1(a) {
  47960. if (!(a instanceof Array)) {
  47961. a = [a, a];
  47962. }
  47963. return a;
  47964. }
  47965. var edgeVisual = function (ecModel) {
  47966. ecModel.eachSeriesByType('graph', function (seriesModel) {
  47967. var graph = seriesModel.getGraph();
  47968. var edgeData = seriesModel.getEdgeData();
  47969. var symbolType = normalize$1(seriesModel.get('edgeSymbol'));
  47970. var symbolSize = normalize$1(seriesModel.get('edgeSymbolSize'));
  47971. var colorQuery = 'lineStyle.color'.split('.');
  47972. var opacityQuery = 'lineStyle.opacity'.split('.');
  47973. edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
  47974. edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
  47975. edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  47976. edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  47977. edgeData.setVisual('color', seriesModel.get(colorQuery));
  47978. edgeData.setVisual('opacity', seriesModel.get(opacityQuery));
  47979. edgeData.each(function (idx) {
  47980. var itemModel = edgeData.getItemModel(idx);
  47981. var edge = graph.getEdgeByIndex(idx);
  47982. var symbolType = normalize$1(itemModel.getShallow('symbol', true));
  47983. var symbolSize = normalize$1(itemModel.getShallow('symbolSize', true));
  47984. // Edge visual must after node visual
  47985. var color = itemModel.get(colorQuery);
  47986. var opacity = itemModel.get(opacityQuery);
  47987. switch (color) {
  47988. case 'source':
  47989. color = edge.node1.getVisual('color');
  47990. break;
  47991. case 'target':
  47992. color = edge.node2.getVisual('color');
  47993. break;
  47994. }
  47995. symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
  47996. symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
  47997. symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
  47998. symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
  47999. edge.setVisual('color', color);
  48000. edge.setVisual('opacity', opacity);
  48001. });
  48002. });
  48003. };
  48004. /*
  48005. * Licensed to the Apache Software Foundation (ASF) under one
  48006. * or more contributor license agreements. See the NOTICE file
  48007. * distributed with this work for additional information
  48008. * regarding copyright ownership. The ASF licenses this file
  48009. * to you under the Apache License, Version 2.0 (the
  48010. * "License"); you may not use this file except in compliance
  48011. * with the License. You may obtain a copy of the License at
  48012. *
  48013. * http://www.apache.org/licenses/LICENSE-2.0
  48014. *
  48015. * Unless required by applicable law or agreed to in writing,
  48016. * software distributed under the License is distributed on an
  48017. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48018. * KIND, either express or implied. See the License for the
  48019. * specific language governing permissions and limitations
  48020. * under the License.
  48021. */
  48022. function simpleLayout$1(seriesModel) {
  48023. var coordSys = seriesModel.coordinateSystem;
  48024. if (coordSys && coordSys.type !== 'view') {
  48025. return;
  48026. }
  48027. var graph = seriesModel.getGraph();
  48028. graph.eachNode(function (node) {
  48029. var model = node.getModel();
  48030. node.setLayout([+model.get('x'), +model.get('y')]);
  48031. });
  48032. simpleLayoutEdge(graph);
  48033. }
  48034. function simpleLayoutEdge(graph) {
  48035. graph.eachEdge(function (edge) {
  48036. var curveness = edge.getModel().get('lineStyle.curveness') || 0;
  48037. var p1 = clone$1(edge.node1.getLayout());
  48038. var p2 = clone$1(edge.node2.getLayout());
  48039. var points = [p1, p2];
  48040. if (+curveness) {
  48041. points.push([
  48042. (p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * curveness,
  48043. (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * curveness
  48044. ]);
  48045. }
  48046. edge.setLayout(points);
  48047. });
  48048. }
  48049. /*
  48050. * Licensed to the Apache Software Foundation (ASF) under one
  48051. * or more contributor license agreements. See the NOTICE file
  48052. * distributed with this work for additional information
  48053. * regarding copyright ownership. The ASF licenses this file
  48054. * to you under the Apache License, Version 2.0 (the
  48055. * "License"); you may not use this file except in compliance
  48056. * with the License. You may obtain a copy of the License at
  48057. *
  48058. * http://www.apache.org/licenses/LICENSE-2.0
  48059. *
  48060. * Unless required by applicable law or agreed to in writing,
  48061. * software distributed under the License is distributed on an
  48062. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48063. * KIND, either express or implied. See the License for the
  48064. * specific language governing permissions and limitations
  48065. * under the License.
  48066. */
  48067. var simpleLayout = function (ecModel, api) {
  48068. ecModel.eachSeriesByType('graph', function (seriesModel) {
  48069. var layout = seriesModel.get('layout');
  48070. var coordSys = seriesModel.coordinateSystem;
  48071. if (coordSys && coordSys.type !== 'view') {
  48072. var data = seriesModel.getData();
  48073. var dimensions = [];
  48074. each$1(coordSys.dimensions, function (coordDim) {
  48075. dimensions = dimensions.concat(data.mapDimension(coordDim, true));
  48076. });
  48077. for (var dataIndex = 0; dataIndex < data.count(); dataIndex++) {
  48078. var value = [];
  48079. var hasValue = false;
  48080. for (var i = 0; i < dimensions.length; i++) {
  48081. var val = data.get(dimensions[i], dataIndex);
  48082. if (!isNaN(val)) {
  48083. hasValue = true;
  48084. }
  48085. value.push(val);
  48086. }
  48087. if (hasValue) {
  48088. data.setItemLayout(dataIndex, coordSys.dataToPoint(value));
  48089. }
  48090. else {
  48091. // Also {Array.<number>}, not undefined to avoid if...else... statement
  48092. data.setItemLayout(dataIndex, [NaN, NaN]);
  48093. }
  48094. }
  48095. simpleLayoutEdge(data.graph);
  48096. }
  48097. else if (!layout || layout === 'none') {
  48098. simpleLayout$1(seriesModel);
  48099. }
  48100. });
  48101. };
  48102. /*
  48103. * Licensed to the Apache Software Foundation (ASF) under one
  48104. * or more contributor license agreements. See the NOTICE file
  48105. * distributed with this work for additional information
  48106. * regarding copyright ownership. The ASF licenses this file
  48107. * to you under the Apache License, Version 2.0 (the
  48108. * "License"); you may not use this file except in compliance
  48109. * with the License. You may obtain a copy of the License at
  48110. *
  48111. * http://www.apache.org/licenses/LICENSE-2.0
  48112. *
  48113. * Unless required by applicable law or agreed to in writing,
  48114. * software distributed under the License is distributed on an
  48115. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48116. * KIND, either express or implied. See the License for the
  48117. * specific language governing permissions and limitations
  48118. * under the License.
  48119. */
  48120. function circularLayout$1(seriesModel) {
  48121. var coordSys = seriesModel.coordinateSystem;
  48122. if (coordSys && coordSys.type !== 'view') {
  48123. return;
  48124. }
  48125. var rect = coordSys.getBoundingRect();
  48126. var nodeData = seriesModel.getData();
  48127. var graph = nodeData.graph;
  48128. var angle = 0;
  48129. var sum = nodeData.getSum('value');
  48130. var unitAngle = Math.PI * 2 / (sum || nodeData.count());
  48131. var cx = rect.width / 2 + rect.x;
  48132. var cy = rect.height / 2 + rect.y;
  48133. var r = Math.min(rect.width, rect.height) / 2;
  48134. graph.eachNode(function (node) {
  48135. var value = node.getValue('value');
  48136. angle += unitAngle * (sum ? value : 1) / 2;
  48137. node.setLayout([
  48138. r * Math.cos(angle) + cx,
  48139. r * Math.sin(angle) + cy
  48140. ]);
  48141. angle += unitAngle * (sum ? value : 1) / 2;
  48142. });
  48143. nodeData.setLayout({
  48144. cx: cx,
  48145. cy: cy
  48146. });
  48147. graph.eachEdge(function (edge) {
  48148. var curveness = edge.getModel().get('lineStyle.curveness') || 0;
  48149. var p1 = clone$1(edge.node1.getLayout());
  48150. var p2 = clone$1(edge.node2.getLayout());
  48151. var cp1;
  48152. var x12 = (p1[0] + p2[0]) / 2;
  48153. var y12 = (p1[1] + p2[1]) / 2;
  48154. if (+curveness) {
  48155. curveness *= 3;
  48156. cp1 = [
  48157. cx * curveness + x12 * (1 - curveness),
  48158. cy * curveness + y12 * (1 - curveness)
  48159. ];
  48160. }
  48161. edge.setLayout([p1, p2, cp1]);
  48162. });
  48163. }
  48164. /*
  48165. * Licensed to the Apache Software Foundation (ASF) under one
  48166. * or more contributor license agreements. See the NOTICE file
  48167. * distributed with this work for additional information
  48168. * regarding copyright ownership. The ASF licenses this file
  48169. * to you under the Apache License, Version 2.0 (the
  48170. * "License"); you may not use this file except in compliance
  48171. * with the License. You may obtain a copy of the License at
  48172. *
  48173. * http://www.apache.org/licenses/LICENSE-2.0
  48174. *
  48175. * Unless required by applicable law or agreed to in writing,
  48176. * software distributed under the License is distributed on an
  48177. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48178. * KIND, either express or implied. See the License for the
  48179. * specific language governing permissions and limitations
  48180. * under the License.
  48181. */
  48182. var circularLayout = function (ecModel) {
  48183. ecModel.eachSeriesByType('graph', function (seriesModel) {
  48184. if (seriesModel.get('layout') === 'circular') {
  48185. circularLayout$1(seriesModel);
  48186. }
  48187. });
  48188. };
  48189. /*
  48190. * Licensed to the Apache Software Foundation (ASF) under one
  48191. * or more contributor license agreements. See the NOTICE file
  48192. * distributed with this work for additional information
  48193. * regarding copyright ownership. The ASF licenses this file
  48194. * to you under the Apache License, Version 2.0 (the
  48195. * "License"); you may not use this file except in compliance
  48196. * with the License. You may obtain a copy of the License at
  48197. *
  48198. * http://www.apache.org/licenses/LICENSE-2.0
  48199. *
  48200. * Unless required by applicable law or agreed to in writing,
  48201. * software distributed under the License is distributed on an
  48202. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48203. * KIND, either express or implied. See the License for the
  48204. * specific language governing permissions and limitations
  48205. * under the License.
  48206. */
  48207. /*
  48208. * A third-party license is embeded for some of the code in this file:
  48209. * Some formulas were originally copied from "d3.js" with some
  48210. * modifications made for this project.
  48211. * (See more details in the comment of the method "step" below.)
  48212. * The use of the source code of this file is also subject to the terms
  48213. * and consitions of the license of "d3.js" (BSD-3Clause, see
  48214. * </licenses/LICENSE-d3>).
  48215. */
  48216. var scaleAndAdd$2 = scaleAndAdd;
  48217. // function adjacentNode(n, e) {
  48218. // return e.n1 === n ? e.n2 : e.n1;
  48219. // }
  48220. function forceLayout$1(nodes, edges, opts) {
  48221. var rect = opts.rect;
  48222. var width = rect.width;
  48223. var height = rect.height;
  48224. var center = [rect.x + width / 2, rect.y + height / 2];
  48225. // var scale = opts.scale || 1;
  48226. var gravity = opts.gravity == null ? 0.1 : opts.gravity;
  48227. // for (var i = 0; i < edges.length; i++) {
  48228. // var e = edges[i];
  48229. // var n1 = e.n1;
  48230. // var n2 = e.n2;
  48231. // n1.edges = n1.edges || [];
  48232. // n2.edges = n2.edges || [];
  48233. // n1.edges.push(e);
  48234. // n2.edges.push(e);
  48235. // }
  48236. // Init position
  48237. for (var i = 0; i < nodes.length; i++) {
  48238. var n = nodes[i];
  48239. if (!n.p) {
  48240. n.p = create(
  48241. width * (Math.random() - 0.5) + center[0],
  48242. height * (Math.random() - 0.5) + center[1]
  48243. );
  48244. }
  48245. n.pp = clone$1(n.p);
  48246. n.edges = null;
  48247. }
  48248. // Formula in 'Graph Drawing by Force-directed Placement'
  48249. // var k = scale * Math.sqrt(width * height / nodes.length);
  48250. // var k2 = k * k;
  48251. var friction = 0.6;
  48252. return {
  48253. warmUp: function () {
  48254. friction = 0.5;
  48255. },
  48256. setFixed: function (idx) {
  48257. nodes[idx].fixed = true;
  48258. },
  48259. setUnfixed: function (idx) {
  48260. nodes[idx].fixed = false;
  48261. },
  48262. /**
  48263. * Some formulas were originally copied from "d3.js"
  48264. * https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/layout/force.js
  48265. * with some modifications made for this project.
  48266. * See the license statement at the head of this file.
  48267. */
  48268. step: function (cb) {
  48269. var v12 = [];
  48270. var nLen = nodes.length;
  48271. for (var i = 0; i < edges.length; i++) {
  48272. var e = edges[i];
  48273. var n1 = e.n1;
  48274. var n2 = e.n2;
  48275. sub(v12, n2.p, n1.p);
  48276. var d = len(v12) - e.d;
  48277. var w = n2.w / (n1.w + n2.w);
  48278. if (isNaN(w)) {
  48279. w = 0;
  48280. }
  48281. normalize(v12, v12);
  48282. !n1.fixed && scaleAndAdd$2(n1.p, n1.p, v12, w * d * friction);
  48283. !n2.fixed && scaleAndAdd$2(n2.p, n2.p, v12, -(1 - w) * d * friction);
  48284. }
  48285. // Gravity
  48286. for (var i = 0; i < nLen; i++) {
  48287. var n = nodes[i];
  48288. if (!n.fixed) {
  48289. sub(v12, center, n.p);
  48290. // var d = vec2.len(v12);
  48291. // vec2.scale(v12, v12, 1 / d);
  48292. // var gravityFactor = gravity;
  48293. scaleAndAdd$2(n.p, n.p, v12, gravity * friction);
  48294. }
  48295. }
  48296. // Repulsive
  48297. // PENDING
  48298. for (var i = 0; i < nLen; i++) {
  48299. var n1 = nodes[i];
  48300. for (var j = i + 1; j < nLen; j++) {
  48301. var n2 = nodes[j];
  48302. sub(v12, n2.p, n1.p);
  48303. var d = len(v12);
  48304. if (d === 0) {
  48305. // Random repulse
  48306. set(v12, Math.random() - 0.5, Math.random() - 0.5);
  48307. d = 1;
  48308. }
  48309. var repFact = (n1.rep + n2.rep) / d / d;
  48310. !n1.fixed && scaleAndAdd$2(n1.pp, n1.pp, v12, repFact);
  48311. !n2.fixed && scaleAndAdd$2(n2.pp, n2.pp, v12, -repFact);
  48312. }
  48313. }
  48314. var v = [];
  48315. for (var i = 0; i < nLen; i++) {
  48316. var n = nodes[i];
  48317. if (!n.fixed) {
  48318. sub(v, n.p, n.pp);
  48319. scaleAndAdd$2(n.p, n.p, v, friction);
  48320. copy(n.pp, n.p);
  48321. }
  48322. }
  48323. friction = friction * 0.992;
  48324. cb && cb(nodes, edges, friction < 0.01);
  48325. }
  48326. };
  48327. }
  48328. /*
  48329. * Licensed to the Apache Software Foundation (ASF) under one
  48330. * or more contributor license agreements. See the NOTICE file
  48331. * distributed with this work for additional information
  48332. * regarding copyright ownership. The ASF licenses this file
  48333. * to you under the Apache License, Version 2.0 (the
  48334. * "License"); you may not use this file except in compliance
  48335. * with the License. You may obtain a copy of the License at
  48336. *
  48337. * http://www.apache.org/licenses/LICENSE-2.0
  48338. *
  48339. * Unless required by applicable law or agreed to in writing,
  48340. * software distributed under the License is distributed on an
  48341. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48342. * KIND, either express or implied. See the License for the
  48343. * specific language governing permissions and limitations
  48344. * under the License.
  48345. */
  48346. var forceLayout = function (ecModel) {
  48347. ecModel.eachSeriesByType('graph', function (graphSeries) {
  48348. var coordSys = graphSeries.coordinateSystem;
  48349. if (coordSys && coordSys.type !== 'view') {
  48350. return;
  48351. }
  48352. if (graphSeries.get('layout') === 'force') {
  48353. var preservedPoints = graphSeries.preservedPoints || {};
  48354. var graph = graphSeries.getGraph();
  48355. var nodeData = graph.data;
  48356. var edgeData = graph.edgeData;
  48357. var forceModel = graphSeries.getModel('force');
  48358. var initLayout = forceModel.get('initLayout');
  48359. if (graphSeries.preservedPoints) {
  48360. nodeData.each(function (idx) {
  48361. var id = nodeData.getId(idx);
  48362. nodeData.setItemLayout(idx, preservedPoints[id] || [NaN, NaN]);
  48363. });
  48364. }
  48365. else if (!initLayout || initLayout === 'none') {
  48366. simpleLayout$1(graphSeries);
  48367. }
  48368. else if (initLayout === 'circular') {
  48369. circularLayout$1(graphSeries);
  48370. }
  48371. var nodeDataExtent = nodeData.getDataExtent('value');
  48372. var edgeDataExtent = edgeData.getDataExtent('value');
  48373. // var edgeDataExtent = edgeData.getDataExtent('value');
  48374. var repulsion = forceModel.get('repulsion');
  48375. var edgeLength = forceModel.get('edgeLength');
  48376. if (!isArray(repulsion)) {
  48377. repulsion = [repulsion, repulsion];
  48378. }
  48379. if (!isArray(edgeLength)) {
  48380. edgeLength = [edgeLength, edgeLength];
  48381. }
  48382. // Larger value has smaller length
  48383. edgeLength = [edgeLength[1], edgeLength[0]];
  48384. var nodes = nodeData.mapArray('value', function (value, idx) {
  48385. var point = nodeData.getItemLayout(idx);
  48386. var rep = linearMap(value, nodeDataExtent, repulsion);
  48387. if (isNaN(rep)) {
  48388. rep = (repulsion[0] + repulsion[1]) / 2;
  48389. }
  48390. return {
  48391. w: rep,
  48392. rep: rep,
  48393. fixed: nodeData.getItemModel(idx).get('fixed'),
  48394. p: (!point || isNaN(point[0]) || isNaN(point[1])) ? null : point
  48395. };
  48396. });
  48397. var edges = edgeData.mapArray('value', function (value, idx) {
  48398. var edge = graph.getEdgeByIndex(idx);
  48399. var d = linearMap(value, edgeDataExtent, edgeLength);
  48400. if (isNaN(d)) {
  48401. d = (edgeLength[0] + edgeLength[1]) / 2;
  48402. }
  48403. return {
  48404. n1: nodes[edge.node1.dataIndex],
  48405. n2: nodes[edge.node2.dataIndex],
  48406. d: d,
  48407. curveness: edge.getModel().get('lineStyle.curveness') || 0
  48408. };
  48409. });
  48410. var coordSys = graphSeries.coordinateSystem;
  48411. var rect = coordSys.getBoundingRect();
  48412. var forceInstance = forceLayout$1(nodes, edges, {
  48413. rect: rect,
  48414. gravity: forceModel.get('gravity')
  48415. });
  48416. var oldStep = forceInstance.step;
  48417. forceInstance.step = function (cb) {
  48418. for (var i = 0, l = nodes.length; i < l; i++) {
  48419. if (nodes[i].fixed) {
  48420. // Write back to layout instance
  48421. copy(nodes[i].p, graph.getNodeByIndex(i).getLayout());
  48422. }
  48423. }
  48424. oldStep(function (nodes, edges, stopped) {
  48425. for (var i = 0, l = nodes.length; i < l; i++) {
  48426. if (!nodes[i].fixed) {
  48427. graph.getNodeByIndex(i).setLayout(nodes[i].p);
  48428. }
  48429. preservedPoints[nodeData.getId(i)] = nodes[i].p;
  48430. }
  48431. for (var i = 0, l = edges.length; i < l; i++) {
  48432. var e = edges[i];
  48433. var edge = graph.getEdgeByIndex(i);
  48434. var p1 = e.n1.p;
  48435. var p2 = e.n2.p;
  48436. var points = edge.getLayout();
  48437. points = points ? points.slice() : [];
  48438. points[0] = points[0] || [];
  48439. points[1] = points[1] || [];
  48440. copy(points[0], p1);
  48441. copy(points[1], p2);
  48442. if (+e.curveness) {
  48443. points[2] = [
  48444. (p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * e.curveness,
  48445. (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * e.curveness
  48446. ];
  48447. }
  48448. edge.setLayout(points);
  48449. }
  48450. // Update layout
  48451. cb && cb(stopped);
  48452. });
  48453. };
  48454. graphSeries.forceLayout = forceInstance;
  48455. graphSeries.preservedPoints = preservedPoints;
  48456. // Step to get the layout
  48457. forceInstance.step();
  48458. }
  48459. else {
  48460. // Remove prev injected forceLayout instance
  48461. graphSeries.forceLayout = null;
  48462. }
  48463. });
  48464. };
  48465. /*
  48466. * Licensed to the Apache Software Foundation (ASF) under one
  48467. * or more contributor license agreements. See the NOTICE file
  48468. * distributed with this work for additional information
  48469. * regarding copyright ownership. The ASF licenses this file
  48470. * to you under the Apache License, Version 2.0 (the
  48471. * "License"); you may not use this file except in compliance
  48472. * with the License. You may obtain a copy of the License at
  48473. *
  48474. * http://www.apache.org/licenses/LICENSE-2.0
  48475. *
  48476. * Unless required by applicable law or agreed to in writing,
  48477. * software distributed under the License is distributed on an
  48478. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48479. * KIND, either express or implied. See the License for the
  48480. * specific language governing permissions and limitations
  48481. * under the License.
  48482. */
  48483. // FIXME Where to create the simple view coordinate system
  48484. function getViewRect$1(seriesModel, api, aspect) {
  48485. var option = seriesModel.getBoxLayoutParams();
  48486. option.aspect = aspect;
  48487. return getLayoutRect(option, {
  48488. width: api.getWidth(),
  48489. height: api.getHeight()
  48490. });
  48491. }
  48492. var createView = function (ecModel, api) {
  48493. var viewList = [];
  48494. ecModel.eachSeriesByType('graph', function (seriesModel) {
  48495. var coordSysType = seriesModel.get('coordinateSystem');
  48496. if (!coordSysType || coordSysType === 'view') {
  48497. var data = seriesModel.getData();
  48498. var positions = data.mapArray(function (idx) {
  48499. var itemModel = data.getItemModel(idx);
  48500. return [+itemModel.get('x'), +itemModel.get('y')];
  48501. });
  48502. var min = [];
  48503. var max = [];
  48504. fromPoints(positions, min, max);
  48505. // If width or height is 0
  48506. if (max[0] - min[0] === 0) {
  48507. max[0] += 1;
  48508. min[0] -= 1;
  48509. }
  48510. if (max[1] - min[1] === 0) {
  48511. max[1] += 1;
  48512. min[1] -= 1;
  48513. }
  48514. var aspect = (max[0] - min[0]) / (max[1] - min[1]);
  48515. // FIXME If get view rect after data processed?
  48516. var viewRect = getViewRect$1(seriesModel, api, aspect);
  48517. // Position may be NaN, use view rect instead
  48518. if (isNaN(aspect)) {
  48519. min = [viewRect.x, viewRect.y];
  48520. max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
  48521. }
  48522. var bbWidth = max[0] - min[0];
  48523. var bbHeight = max[1] - min[1];
  48524. var viewWidth = viewRect.width;
  48525. var viewHeight = viewRect.height;
  48526. var viewCoordSys = seriesModel.coordinateSystem = new View();
  48527. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  48528. viewCoordSys.setBoundingRect(
  48529. min[0], min[1], bbWidth, bbHeight
  48530. );
  48531. viewCoordSys.setViewRect(
  48532. viewRect.x, viewRect.y, viewWidth, viewHeight
  48533. );
  48534. // Update roam info
  48535. viewCoordSys.setCenter(seriesModel.get('center'));
  48536. viewCoordSys.setZoom(seriesModel.get('zoom'));
  48537. viewList.push(viewCoordSys);
  48538. }
  48539. });
  48540. return viewList;
  48541. };
  48542. /*
  48543. * Licensed to the Apache Software Foundation (ASF) under one
  48544. * or more contributor license agreements. See the NOTICE file
  48545. * distributed with this work for additional information
  48546. * regarding copyright ownership. The ASF licenses this file
  48547. * to you under the Apache License, Version 2.0 (the
  48548. * "License"); you may not use this file except in compliance
  48549. * with the License. You may obtain a copy of the License at
  48550. *
  48551. * http://www.apache.org/licenses/LICENSE-2.0
  48552. *
  48553. * Unless required by applicable law or agreed to in writing,
  48554. * software distributed under the License is distributed on an
  48555. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48556. * KIND, either express or implied. See the License for the
  48557. * specific language governing permissions and limitations
  48558. * under the License.
  48559. */
  48560. registerProcessor(categoryFilter);
  48561. registerVisual(visualSymbol('graph', 'circle', null));
  48562. registerVisual(categoryVisual);
  48563. registerVisual(edgeVisual);
  48564. registerLayout(simpleLayout);
  48565. registerLayout(circularLayout);
  48566. registerLayout(forceLayout);
  48567. // Graph view coordinate system
  48568. registerCoordinateSystem('graphView', {
  48569. create: createView
  48570. });
  48571. /*
  48572. * Licensed to the Apache Software Foundation (ASF) under one
  48573. * or more contributor license agreements. See the NOTICE file
  48574. * distributed with this work for additional information
  48575. * regarding copyright ownership. The ASF licenses this file
  48576. * to you under the Apache License, Version 2.0 (the
  48577. * "License"); you may not use this file except in compliance
  48578. * with the License. You may obtain a copy of the License at
  48579. *
  48580. * http://www.apache.org/licenses/LICENSE-2.0
  48581. *
  48582. * Unless required by applicable law or agreed to in writing,
  48583. * software distributed under the License is distributed on an
  48584. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48585. * KIND, either express or implied. See the License for the
  48586. * specific language governing permissions and limitations
  48587. * under the License.
  48588. */
  48589. var GaugeSeries = SeriesModel.extend({
  48590. type: 'series.gauge',
  48591. getInitialData: function (option, ecModel) {
  48592. var dataOpt = option.data || [];
  48593. if (!isArray(dataOpt)) {
  48594. dataOpt = [dataOpt];
  48595. }
  48596. option.data = dataOpt;
  48597. return createListSimply(this, ['value']);
  48598. },
  48599. defaultOption: {
  48600. zlevel: 0,
  48601. z: 2,
  48602. // 默认全局居中
  48603. center: ['50%', '50%'],
  48604. legendHoverLink: true,
  48605. radius: '75%',
  48606. startAngle: 225,
  48607. endAngle: -45,
  48608. clockwise: true,
  48609. // 最小值
  48610. min: 0,
  48611. // 最大值
  48612. max: 100,
  48613. // 分割段数,默认为10
  48614. splitNumber: 10,
  48615. // 坐标轴线
  48616. axisLine: {
  48617. // 默认显示,属性show控制显示与否
  48618. show: true,
  48619. lineStyle: { // 属性lineStyle控制线条样式
  48620. color: [[0.2, '#91c7ae'], [0.8, '#63869e'], [1, '#c23531']],
  48621. width: 30
  48622. }
  48623. },
  48624. // 分隔线
  48625. splitLine: {
  48626. // 默认显示,属性show控制显示与否
  48627. show: true,
  48628. // 属性length控制线长
  48629. length: 30,
  48630. // 属性lineStyle(详见lineStyle)控制线条样式
  48631. lineStyle: {
  48632. color: '#eee',
  48633. width: 2,
  48634. type: 'solid'
  48635. }
  48636. },
  48637. // 坐标轴小标记
  48638. axisTick: {
  48639. // 属性show控制显示与否,默认不显示
  48640. show: true,
  48641. // 每份split细分多少段
  48642. splitNumber: 5,
  48643. // 属性length控制线长
  48644. length: 8,
  48645. // 属性lineStyle控制线条样式
  48646. lineStyle: {
  48647. color: '#eee',
  48648. width: 1,
  48649. type: 'solid'
  48650. }
  48651. },
  48652. axisLabel: {
  48653. show: true,
  48654. distance: 5,
  48655. // formatter: null,
  48656. color: 'auto'
  48657. },
  48658. pointer: {
  48659. show: true,
  48660. length: '80%',
  48661. width: 8
  48662. },
  48663. itemStyle: {
  48664. color: 'auto'
  48665. },
  48666. title: {
  48667. show: true,
  48668. // x, y,单位px
  48669. offsetCenter: [0, '-40%'],
  48670. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  48671. color: '#333',
  48672. fontSize: 15
  48673. },
  48674. detail: {
  48675. show: true,
  48676. backgroundColor: 'rgba(0,0,0,0)',
  48677. borderWidth: 0,
  48678. borderColor: '#ccc',
  48679. width: 100,
  48680. height: null, // self-adaption
  48681. padding: [5, 10],
  48682. // x, y,单位px
  48683. offsetCenter: [0, '40%'],
  48684. // formatter: null,
  48685. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  48686. color: 'auto',
  48687. fontSize: 30
  48688. }
  48689. }
  48690. });
  48691. /*
  48692. * Licensed to the Apache Software Foundation (ASF) under one
  48693. * or more contributor license agreements. See the NOTICE file
  48694. * distributed with this work for additional information
  48695. * regarding copyright ownership. The ASF licenses this file
  48696. * to you under the Apache License, Version 2.0 (the
  48697. * "License"); you may not use this file except in compliance
  48698. * with the License. You may obtain a copy of the License at
  48699. *
  48700. * http://www.apache.org/licenses/LICENSE-2.0
  48701. *
  48702. * Unless required by applicable law or agreed to in writing,
  48703. * software distributed under the License is distributed on an
  48704. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48705. * KIND, either express or implied. See the License for the
  48706. * specific language governing permissions and limitations
  48707. * under the License.
  48708. */
  48709. var PointerPath = Path.extend({
  48710. type: 'echartsGaugePointer',
  48711. shape: {
  48712. angle: 0,
  48713. width: 10,
  48714. r: 10,
  48715. x: 0,
  48716. y: 0
  48717. },
  48718. buildPath: function (ctx, shape) {
  48719. var mathCos = Math.cos;
  48720. var mathSin = Math.sin;
  48721. var r = shape.r;
  48722. var width = shape.width;
  48723. var angle = shape.angle;
  48724. var x = shape.x - mathCos(angle) * width * (width >= r / 3 ? 1 : 2);
  48725. var y = shape.y - mathSin(angle) * width * (width >= r / 3 ? 1 : 2);
  48726. angle = shape.angle - Math.PI / 2;
  48727. ctx.moveTo(x, y);
  48728. ctx.lineTo(
  48729. shape.x + mathCos(angle) * width,
  48730. shape.y + mathSin(angle) * width
  48731. );
  48732. ctx.lineTo(
  48733. shape.x + mathCos(shape.angle) * r,
  48734. shape.y + mathSin(shape.angle) * r
  48735. );
  48736. ctx.lineTo(
  48737. shape.x - mathCos(angle) * width,
  48738. shape.y - mathSin(angle) * width
  48739. );
  48740. ctx.lineTo(x, y);
  48741. return;
  48742. }
  48743. });
  48744. /*
  48745. * Licensed to the Apache Software Foundation (ASF) under one
  48746. * or more contributor license agreements. See the NOTICE file
  48747. * distributed with this work for additional information
  48748. * regarding copyright ownership. The ASF licenses this file
  48749. * to you under the Apache License, Version 2.0 (the
  48750. * "License"); you may not use this file except in compliance
  48751. * with the License. You may obtain a copy of the License at
  48752. *
  48753. * http://www.apache.org/licenses/LICENSE-2.0
  48754. *
  48755. * Unless required by applicable law or agreed to in writing,
  48756. * software distributed under the License is distributed on an
  48757. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48758. * KIND, either express or implied. See the License for the
  48759. * specific language governing permissions and limitations
  48760. * under the License.
  48761. */
  48762. function parsePosition(seriesModel, api) {
  48763. var center = seriesModel.get('center');
  48764. var width = api.getWidth();
  48765. var height = api.getHeight();
  48766. var size = Math.min(width, height);
  48767. var cx = parsePercent$1(center[0], api.getWidth());
  48768. var cy = parsePercent$1(center[1], api.getHeight());
  48769. var r = parsePercent$1(seriesModel.get('radius'), size / 2);
  48770. return {
  48771. cx: cx,
  48772. cy: cy,
  48773. r: r
  48774. };
  48775. }
  48776. function formatLabel(label, labelFormatter) {
  48777. if (labelFormatter) {
  48778. if (typeof labelFormatter === 'string') {
  48779. label = labelFormatter.replace('{value}', label != null ? label : '');
  48780. }
  48781. else if (typeof labelFormatter === 'function') {
  48782. label = labelFormatter(label);
  48783. }
  48784. }
  48785. return label;
  48786. }
  48787. var PI2$5 = Math.PI * 2;
  48788. var GaugeView = Chart.extend({
  48789. type: 'gauge',
  48790. render: function (seriesModel, ecModel, api) {
  48791. this.group.removeAll();
  48792. var colorList = seriesModel.get('axisLine.lineStyle.color');
  48793. var posInfo = parsePosition(seriesModel, api);
  48794. this._renderMain(
  48795. seriesModel, ecModel, api, colorList, posInfo
  48796. );
  48797. },
  48798. dispose: function () {},
  48799. _renderMain: function (seriesModel, ecModel, api, colorList, posInfo) {
  48800. var group = this.group;
  48801. var axisLineModel = seriesModel.getModel('axisLine');
  48802. var lineStyleModel = axisLineModel.getModel('lineStyle');
  48803. var clockwise = seriesModel.get('clockwise');
  48804. var startAngle = -seriesModel.get('startAngle') / 180 * Math.PI;
  48805. var endAngle = -seriesModel.get('endAngle') / 180 * Math.PI;
  48806. var angleRangeSpan = (endAngle - startAngle) % PI2$5;
  48807. var prevEndAngle = startAngle;
  48808. var axisLineWidth = lineStyleModel.get('width');
  48809. for (var i = 0; i < colorList.length; i++) {
  48810. // Clamp
  48811. var percent = Math.min(Math.max(colorList[i][0], 0), 1);
  48812. var endAngle = startAngle + angleRangeSpan * percent;
  48813. var sector = new Sector({
  48814. shape: {
  48815. startAngle: prevEndAngle,
  48816. endAngle: endAngle,
  48817. cx: posInfo.cx,
  48818. cy: posInfo.cy,
  48819. clockwise: clockwise,
  48820. r0: posInfo.r - axisLineWidth,
  48821. r: posInfo.r
  48822. },
  48823. silent: true
  48824. });
  48825. sector.setStyle({
  48826. fill: colorList[i][1]
  48827. });
  48828. sector.setStyle(lineStyleModel.getLineStyle(
  48829. // Because we use sector to simulate arc
  48830. // so the properties for stroking are useless
  48831. ['color', 'borderWidth', 'borderColor']
  48832. ));
  48833. group.add(sector);
  48834. prevEndAngle = endAngle;
  48835. }
  48836. var getColor = function (percent) {
  48837. // Less than 0
  48838. if (percent <= 0) {
  48839. return colorList[0][1];
  48840. }
  48841. for (var i = 0; i < colorList.length; i++) {
  48842. if (colorList[i][0] >= percent
  48843. && (i === 0 ? 0 : colorList[i - 1][0]) < percent
  48844. ) {
  48845. return colorList[i][1];
  48846. }
  48847. }
  48848. // More than 1
  48849. return colorList[i - 1][1];
  48850. };
  48851. if (!clockwise) {
  48852. var tmp = startAngle;
  48853. startAngle = endAngle;
  48854. endAngle = tmp;
  48855. }
  48856. this._renderTicks(
  48857. seriesModel, ecModel, api, getColor, posInfo,
  48858. startAngle, endAngle, clockwise
  48859. );
  48860. this._renderPointer(
  48861. seriesModel, ecModel, api, getColor, posInfo,
  48862. startAngle, endAngle, clockwise
  48863. );
  48864. this._renderTitle(
  48865. seriesModel, ecModel, api, getColor, posInfo
  48866. );
  48867. this._renderDetail(
  48868. seriesModel, ecModel, api, getColor, posInfo
  48869. );
  48870. },
  48871. _renderTicks: function (
  48872. seriesModel, ecModel, api, getColor, posInfo,
  48873. startAngle, endAngle, clockwise
  48874. ) {
  48875. var group = this.group;
  48876. var cx = posInfo.cx;
  48877. var cy = posInfo.cy;
  48878. var r = posInfo.r;
  48879. var minVal = +seriesModel.get('min');
  48880. var maxVal = +seriesModel.get('max');
  48881. var splitLineModel = seriesModel.getModel('splitLine');
  48882. var tickModel = seriesModel.getModel('axisTick');
  48883. var labelModel = seriesModel.getModel('axisLabel');
  48884. var splitNumber = seriesModel.get('splitNumber');
  48885. var subSplitNumber = tickModel.get('splitNumber');
  48886. var splitLineLen = parsePercent$1(
  48887. splitLineModel.get('length'), r
  48888. );
  48889. var tickLen = parsePercent$1(
  48890. tickModel.get('length'), r
  48891. );
  48892. var angle = startAngle;
  48893. var step = (endAngle - startAngle) / splitNumber;
  48894. var subStep = step / subSplitNumber;
  48895. var splitLineStyle = splitLineModel.getModel('lineStyle').getLineStyle();
  48896. var tickLineStyle = tickModel.getModel('lineStyle').getLineStyle();
  48897. for (var i = 0; i <= splitNumber; i++) {
  48898. var unitX = Math.cos(angle);
  48899. var unitY = Math.sin(angle);
  48900. // Split line
  48901. if (splitLineModel.get('show')) {
  48902. var splitLine = new Line({
  48903. shape: {
  48904. x1: unitX * r + cx,
  48905. y1: unitY * r + cy,
  48906. x2: unitX * (r - splitLineLen) + cx,
  48907. y2: unitY * (r - splitLineLen) + cy
  48908. },
  48909. style: splitLineStyle,
  48910. silent: true
  48911. });
  48912. if (splitLineStyle.stroke === 'auto') {
  48913. splitLine.setStyle({
  48914. stroke: getColor(i / splitNumber)
  48915. });
  48916. }
  48917. group.add(splitLine);
  48918. }
  48919. // Label
  48920. if (labelModel.get('show')) {
  48921. var label = formatLabel(
  48922. round$2(i / splitNumber * (maxVal - minVal) + minVal),
  48923. labelModel.get('formatter')
  48924. );
  48925. var distance = labelModel.get('distance');
  48926. var autoColor = getColor(i / splitNumber);
  48927. group.add(new Text({
  48928. style: setTextStyle({}, labelModel, {
  48929. text: label,
  48930. x: unitX * (r - splitLineLen - distance) + cx,
  48931. y: unitY * (r - splitLineLen - distance) + cy,
  48932. textVerticalAlign: unitY < -0.4 ? 'top' : (unitY > 0.4 ? 'bottom' : 'middle'),
  48933. textAlign: unitX < -0.4 ? 'left' : (unitX > 0.4 ? 'right' : 'center')
  48934. }, {autoColor: autoColor}),
  48935. silent: true
  48936. }));
  48937. }
  48938. // Axis tick
  48939. if (tickModel.get('show') && i !== splitNumber) {
  48940. for (var j = 0; j <= subSplitNumber; j++) {
  48941. var unitX = Math.cos(angle);
  48942. var unitY = Math.sin(angle);
  48943. var tickLine = new Line({
  48944. shape: {
  48945. x1: unitX * r + cx,
  48946. y1: unitY * r + cy,
  48947. x2: unitX * (r - tickLen) + cx,
  48948. y2: unitY * (r - tickLen) + cy
  48949. },
  48950. silent: true,
  48951. style: tickLineStyle
  48952. });
  48953. if (tickLineStyle.stroke === 'auto') {
  48954. tickLine.setStyle({
  48955. stroke: getColor((i + j / subSplitNumber) / splitNumber)
  48956. });
  48957. }
  48958. group.add(tickLine);
  48959. angle += subStep;
  48960. }
  48961. angle -= subStep;
  48962. }
  48963. else {
  48964. angle += step;
  48965. }
  48966. }
  48967. },
  48968. _renderPointer: function (
  48969. seriesModel, ecModel, api, getColor, posInfo,
  48970. startAngle, endAngle, clockwise
  48971. ) {
  48972. var group = this.group;
  48973. var oldData = this._data;
  48974. if (!seriesModel.get('pointer.show')) {
  48975. // Remove old element
  48976. oldData && oldData.eachItemGraphicEl(function (el) {
  48977. group.remove(el);
  48978. });
  48979. return;
  48980. }
  48981. var valueExtent = [+seriesModel.get('min'), +seriesModel.get('max')];
  48982. var angleExtent = [startAngle, endAngle];
  48983. var data = seriesModel.getData();
  48984. var valueDim = data.mapDimension('value');
  48985. data.diff(oldData)
  48986. .add(function (idx) {
  48987. var pointer = new PointerPath({
  48988. shape: {
  48989. angle: startAngle
  48990. }
  48991. });
  48992. initProps(pointer, {
  48993. shape: {
  48994. angle: linearMap(data.get(valueDim, idx), valueExtent, angleExtent, true)
  48995. }
  48996. }, seriesModel);
  48997. group.add(pointer);
  48998. data.setItemGraphicEl(idx, pointer);
  48999. })
  49000. .update(function (newIdx, oldIdx) {
  49001. var pointer = oldData.getItemGraphicEl(oldIdx);
  49002. updateProps(pointer, {
  49003. shape: {
  49004. angle: linearMap(data.get(valueDim, newIdx), valueExtent, angleExtent, true)
  49005. }
  49006. }, seriesModel);
  49007. group.add(pointer);
  49008. data.setItemGraphicEl(newIdx, pointer);
  49009. })
  49010. .remove(function (idx) {
  49011. var pointer = oldData.getItemGraphicEl(idx);
  49012. group.remove(pointer);
  49013. })
  49014. .execute();
  49015. data.eachItemGraphicEl(function (pointer, idx) {
  49016. var itemModel = data.getItemModel(idx);
  49017. var pointerModel = itemModel.getModel('pointer');
  49018. pointer.setShape({
  49019. x: posInfo.cx,
  49020. y: posInfo.cy,
  49021. width: parsePercent$1(
  49022. pointerModel.get('width'), posInfo.r
  49023. ),
  49024. r: parsePercent$1(pointerModel.get('length'), posInfo.r)
  49025. });
  49026. pointer.useStyle(itemModel.getModel('itemStyle').getItemStyle());
  49027. if (pointer.style.fill === 'auto') {
  49028. pointer.setStyle('fill', getColor(
  49029. linearMap(data.get(valueDim, idx), valueExtent, [0, 1], true)
  49030. ));
  49031. }
  49032. setHoverStyle(
  49033. pointer, itemModel.getModel('emphasis.itemStyle').getItemStyle()
  49034. );
  49035. });
  49036. this._data = data;
  49037. },
  49038. _renderTitle: function (
  49039. seriesModel, ecModel, api, getColor, posInfo
  49040. ) {
  49041. var data = seriesModel.getData();
  49042. var valueDim = data.mapDimension('value');
  49043. var titleModel = seriesModel.getModel('title');
  49044. if (titleModel.get('show')) {
  49045. var offsetCenter = titleModel.get('offsetCenter');
  49046. var x = posInfo.cx + parsePercent$1(offsetCenter[0], posInfo.r);
  49047. var y = posInfo.cy + parsePercent$1(offsetCenter[1], posInfo.r);
  49048. var minVal = +seriesModel.get('min');
  49049. var maxVal = +seriesModel.get('max');
  49050. var value = seriesModel.getData().get(valueDim, 0);
  49051. var autoColor = getColor(
  49052. linearMap(value, [minVal, maxVal], [0, 1], true)
  49053. );
  49054. this.group.add(new Text({
  49055. silent: true,
  49056. style: setTextStyle({}, titleModel, {
  49057. x: x,
  49058. y: y,
  49059. // FIXME First data name ?
  49060. text: data.getName(0),
  49061. textAlign: 'center',
  49062. textVerticalAlign: 'middle'
  49063. }, {autoColor: autoColor, forceRich: true})
  49064. }));
  49065. }
  49066. },
  49067. _renderDetail: function (
  49068. seriesModel, ecModel, api, getColor, posInfo
  49069. ) {
  49070. var detailModel = seriesModel.getModel('detail');
  49071. var minVal = +seriesModel.get('min');
  49072. var maxVal = +seriesModel.get('max');
  49073. if (detailModel.get('show')) {
  49074. var offsetCenter = detailModel.get('offsetCenter');
  49075. var x = posInfo.cx + parsePercent$1(offsetCenter[0], posInfo.r);
  49076. var y = posInfo.cy + parsePercent$1(offsetCenter[1], posInfo.r);
  49077. var width = parsePercent$1(detailModel.get('width'), posInfo.r);
  49078. var height = parsePercent$1(detailModel.get('height'), posInfo.r);
  49079. var data = seriesModel.getData();
  49080. var value = data.get(data.mapDimension('value'), 0);
  49081. var autoColor = getColor(
  49082. linearMap(value, [minVal, maxVal], [0, 1], true)
  49083. );
  49084. this.group.add(new Text({
  49085. silent: true,
  49086. style: setTextStyle({}, detailModel, {
  49087. x: x,
  49088. y: y,
  49089. text: formatLabel(
  49090. // FIXME First data name ?
  49091. value, detailModel.get('formatter')
  49092. ),
  49093. textWidth: isNaN(width) ? null : width,
  49094. textHeight: isNaN(height) ? null : height,
  49095. textAlign: 'center',
  49096. textVerticalAlign: 'middle'
  49097. }, {autoColor: autoColor, forceRich: true})
  49098. }));
  49099. }
  49100. }
  49101. });
  49102. /*
  49103. * Licensed to the Apache Software Foundation (ASF) under one
  49104. * or more contributor license agreements. See the NOTICE file
  49105. * distributed with this work for additional information
  49106. * regarding copyright ownership. The ASF licenses this file
  49107. * to you under the Apache License, Version 2.0 (the
  49108. * "License"); you may not use this file except in compliance
  49109. * with the License. You may obtain a copy of the License at
  49110. *
  49111. * http://www.apache.org/licenses/LICENSE-2.0
  49112. *
  49113. * Unless required by applicable law or agreed to in writing,
  49114. * software distributed under the License is distributed on an
  49115. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49116. * KIND, either express or implied. See the License for the
  49117. * specific language governing permissions and limitations
  49118. * under the License.
  49119. */
  49120. /*
  49121. * Licensed to the Apache Software Foundation (ASF) under one
  49122. * or more contributor license agreements. See the NOTICE file
  49123. * distributed with this work for additional information
  49124. * regarding copyright ownership. The ASF licenses this file
  49125. * to you under the Apache License, Version 2.0 (the
  49126. * "License"); you may not use this file except in compliance
  49127. * with the License. You may obtain a copy of the License at
  49128. *
  49129. * http://www.apache.org/licenses/LICENSE-2.0
  49130. *
  49131. * Unless required by applicable law or agreed to in writing,
  49132. * software distributed under the License is distributed on an
  49133. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49134. * KIND, either express or implied. See the License for the
  49135. * specific language governing permissions and limitations
  49136. * under the License.
  49137. */
  49138. var FunnelSeries = extendSeriesModel({
  49139. type: 'series.funnel',
  49140. init: function (option) {
  49141. FunnelSeries.superApply(this, 'init', arguments);
  49142. // Enable legend selection for each data item
  49143. // Use a function instead of direct access because data reference may changed
  49144. this.legendDataProvider = function () {
  49145. return this.getRawData();
  49146. };
  49147. // Extend labelLine emphasis
  49148. this._defaultLabelLine(option);
  49149. },
  49150. getInitialData: function (option, ecModel) {
  49151. return createListSimply(this, ['value']);
  49152. },
  49153. _defaultLabelLine: function (option) {
  49154. // Extend labelLine emphasis
  49155. defaultEmphasis(option, 'labelLine', ['show']);
  49156. var labelLineNormalOpt = option.labelLine;
  49157. var labelLineEmphasisOpt = option.emphasis.labelLine;
  49158. // Not show label line if `label.normal.show = false`
  49159. labelLineNormalOpt.show = labelLineNormalOpt.show
  49160. && option.label.show;
  49161. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  49162. && option.emphasis.label.show;
  49163. },
  49164. // Overwrite
  49165. getDataParams: function (dataIndex) {
  49166. var data = this.getData();
  49167. var params = FunnelSeries.superCall(this, 'getDataParams', dataIndex);
  49168. var valueDim = data.mapDimension('value');
  49169. var sum = data.getSum(valueDim);
  49170. // Percent is 0 if sum is 0
  49171. params.percent = !sum ? 0 : +(data.get(valueDim, dataIndex) / sum * 100).toFixed(2);
  49172. params.$vars.push('percent');
  49173. return params;
  49174. },
  49175. defaultOption: {
  49176. zlevel: 0, // 一级层叠
  49177. z: 2, // 二级层叠
  49178. legendHoverLink: true,
  49179. left: 80,
  49180. top: 60,
  49181. right: 80,
  49182. bottom: 60,
  49183. // width: {totalWidth} - left - right,
  49184. // height: {totalHeight} - top - bottom,
  49185. // 默认取数据最小最大值
  49186. // min: 0,
  49187. // max: 100,
  49188. minSize: '0%',
  49189. maxSize: '100%',
  49190. sort: 'descending', // 'ascending', 'descending'
  49191. gap: 0,
  49192. funnelAlign: 'center',
  49193. label: {
  49194. show: true,
  49195. position: 'outer'
  49196. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  49197. },
  49198. labelLine: {
  49199. show: true,
  49200. length: 20,
  49201. lineStyle: {
  49202. // color: 各异,
  49203. width: 1,
  49204. type: 'solid'
  49205. }
  49206. },
  49207. itemStyle: {
  49208. // color: 各异,
  49209. borderColor: '#fff',
  49210. borderWidth: 1
  49211. },
  49212. emphasis: {
  49213. label: {
  49214. show: true
  49215. }
  49216. }
  49217. }
  49218. });
  49219. /*
  49220. * Licensed to the Apache Software Foundation (ASF) under one
  49221. * or more contributor license agreements. See the NOTICE file
  49222. * distributed with this work for additional information
  49223. * regarding copyright ownership. The ASF licenses this file
  49224. * to you under the Apache License, Version 2.0 (the
  49225. * "License"); you may not use this file except in compliance
  49226. * with the License. You may obtain a copy of the License at
  49227. *
  49228. * http://www.apache.org/licenses/LICENSE-2.0
  49229. *
  49230. * Unless required by applicable law or agreed to in writing,
  49231. * software distributed under the License is distributed on an
  49232. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49233. * KIND, either express or implied. See the License for the
  49234. * specific language governing permissions and limitations
  49235. * under the License.
  49236. */
  49237. /**
  49238. * Piece of pie including Sector, Label, LabelLine
  49239. * @constructor
  49240. * @extends {module:zrender/graphic/Group}
  49241. */
  49242. function FunnelPiece(data, idx) {
  49243. Group.call(this);
  49244. var polygon = new Polygon();
  49245. var labelLine = new Polyline();
  49246. var text = new Text();
  49247. this.add(polygon);
  49248. this.add(labelLine);
  49249. this.add(text);
  49250. this.updateData(data, idx, true);
  49251. // Hover to change label and labelLine
  49252. function onEmphasis() {
  49253. labelLine.ignore = labelLine.hoverIgnore;
  49254. text.ignore = text.hoverIgnore;
  49255. }
  49256. function onNormal() {
  49257. labelLine.ignore = labelLine.normalIgnore;
  49258. text.ignore = text.normalIgnore;
  49259. }
  49260. this.on('emphasis', onEmphasis)
  49261. .on('normal', onNormal)
  49262. .on('mouseover', onEmphasis)
  49263. .on('mouseout', onNormal);
  49264. }
  49265. var funnelPieceProto = FunnelPiece.prototype;
  49266. var opacityAccessPath = ['itemStyle', 'opacity'];
  49267. funnelPieceProto.updateData = function (data, idx, firstCreate) {
  49268. var polygon = this.childAt(0);
  49269. var seriesModel = data.hostModel;
  49270. var itemModel = data.getItemModel(idx);
  49271. var layout = data.getItemLayout(idx);
  49272. var opacity = data.getItemModel(idx).get(opacityAccessPath);
  49273. opacity = opacity == null ? 1 : opacity;
  49274. // Reset style
  49275. polygon.useStyle({});
  49276. if (firstCreate) {
  49277. polygon.setShape({
  49278. points: layout.points
  49279. });
  49280. polygon.setStyle({opacity: 0});
  49281. initProps(polygon, {
  49282. style: {
  49283. opacity: opacity
  49284. }
  49285. }, seriesModel, idx);
  49286. }
  49287. else {
  49288. updateProps(polygon, {
  49289. style: {
  49290. opacity: opacity
  49291. },
  49292. shape: {
  49293. points: layout.points
  49294. }
  49295. }, seriesModel, idx);
  49296. }
  49297. // Update common style
  49298. var itemStyleModel = itemModel.getModel('itemStyle');
  49299. var visualColor = data.getItemVisual(idx, 'color');
  49300. polygon.setStyle(
  49301. defaults(
  49302. {
  49303. lineJoin: 'round',
  49304. fill: visualColor
  49305. },
  49306. itemStyleModel.getItemStyle(['opacity'])
  49307. )
  49308. );
  49309. polygon.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle();
  49310. this._updateLabel(data, idx);
  49311. setHoverStyle(this);
  49312. };
  49313. funnelPieceProto._updateLabel = function (data, idx) {
  49314. var labelLine = this.childAt(1);
  49315. var labelText = this.childAt(2);
  49316. var seriesModel = data.hostModel;
  49317. var itemModel = data.getItemModel(idx);
  49318. var layout = data.getItemLayout(idx);
  49319. var labelLayout = layout.label;
  49320. var visualColor = data.getItemVisual(idx, 'color');
  49321. updateProps(labelLine, {
  49322. shape: {
  49323. points: labelLayout.linePoints || labelLayout.linePoints
  49324. }
  49325. }, seriesModel, idx);
  49326. updateProps(labelText, {
  49327. style: {
  49328. x: labelLayout.x,
  49329. y: labelLayout.y
  49330. }
  49331. }, seriesModel, idx);
  49332. labelText.attr({
  49333. rotation: labelLayout.rotation,
  49334. origin: [labelLayout.x, labelLayout.y],
  49335. z2: 10
  49336. });
  49337. var labelModel = itemModel.getModel('label');
  49338. var labelHoverModel = itemModel.getModel('emphasis.label');
  49339. var labelLineModel = itemModel.getModel('labelLine');
  49340. var labelLineHoverModel = itemModel.getModel('emphasis.labelLine');
  49341. var visualColor = data.getItemVisual(idx, 'color');
  49342. setLabelStyle(
  49343. labelText.style, labelText.hoverStyle = {}, labelModel, labelHoverModel,
  49344. {
  49345. labelFetcher: data.hostModel,
  49346. labelDataIndex: idx,
  49347. defaultText: data.getName(idx),
  49348. autoColor: visualColor,
  49349. useInsideStyle: !!labelLayout.inside
  49350. },
  49351. {
  49352. textAlign: labelLayout.textAlign,
  49353. textVerticalAlign: labelLayout.verticalAlign
  49354. }
  49355. );
  49356. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  49357. labelText.hoverIgnore = !labelHoverModel.get('show');
  49358. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  49359. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  49360. // Default use item visual color
  49361. labelLine.setStyle({
  49362. stroke: visualColor
  49363. });
  49364. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  49365. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  49366. };
  49367. inherits(FunnelPiece, Group);
  49368. var FunnelView = Chart.extend({
  49369. type: 'funnel',
  49370. render: function (seriesModel, ecModel, api) {
  49371. var data = seriesModel.getData();
  49372. var oldData = this._data;
  49373. var group = this.group;
  49374. data.diff(oldData)
  49375. .add(function (idx) {
  49376. var funnelPiece = new FunnelPiece(data, idx);
  49377. data.setItemGraphicEl(idx, funnelPiece);
  49378. group.add(funnelPiece);
  49379. })
  49380. .update(function (newIdx, oldIdx) {
  49381. var piePiece = oldData.getItemGraphicEl(oldIdx);
  49382. piePiece.updateData(data, newIdx);
  49383. group.add(piePiece);
  49384. data.setItemGraphicEl(newIdx, piePiece);
  49385. })
  49386. .remove(function (idx) {
  49387. var piePiece = oldData.getItemGraphicEl(idx);
  49388. group.remove(piePiece);
  49389. })
  49390. .execute();
  49391. this._data = data;
  49392. },
  49393. remove: function () {
  49394. this.group.removeAll();
  49395. this._data = null;
  49396. },
  49397. dispose: function () {}
  49398. });
  49399. /*
  49400. * Licensed to the Apache Software Foundation (ASF) under one
  49401. * or more contributor license agreements. See the NOTICE file
  49402. * distributed with this work for additional information
  49403. * regarding copyright ownership. The ASF licenses this file
  49404. * to you under the Apache License, Version 2.0 (the
  49405. * "License"); you may not use this file except in compliance
  49406. * with the License. You may obtain a copy of the License at
  49407. *
  49408. * http://www.apache.org/licenses/LICENSE-2.0
  49409. *
  49410. * Unless required by applicable law or agreed to in writing,
  49411. * software distributed under the License is distributed on an
  49412. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49413. * KIND, either express or implied. See the License for the
  49414. * specific language governing permissions and limitations
  49415. * under the License.
  49416. */
  49417. function getViewRect$2(seriesModel, api) {
  49418. return getLayoutRect(
  49419. seriesModel.getBoxLayoutParams(), {
  49420. width: api.getWidth(),
  49421. height: api.getHeight()
  49422. }
  49423. );
  49424. }
  49425. function getSortedIndices(data, sort) {
  49426. var valueDim = data.mapDimension('value');
  49427. var valueArr = data.mapArray(valueDim, function (val) {
  49428. return val;
  49429. });
  49430. var indices = [];
  49431. var isAscending = sort === 'ascending';
  49432. for (var i = 0, len = data.count(); i < len; i++) {
  49433. indices[i] = i;
  49434. }
  49435. // Add custom sortable function & none sortable opetion by "options.sort"
  49436. if (typeof sort === 'function') {
  49437. indices.sort(sort);
  49438. }
  49439. else if (sort !== 'none') {
  49440. indices.sort(function (a, b) {
  49441. return isAscending ? valueArr[a] - valueArr[b] : valueArr[b] - valueArr[a];
  49442. });
  49443. }
  49444. return indices;
  49445. }
  49446. function labelLayout$1(data) {
  49447. data.each(function (idx) {
  49448. var itemModel = data.getItemModel(idx);
  49449. var labelModel = itemModel.getModel('label');
  49450. var labelPosition = labelModel.get('position');
  49451. var labelLineModel = itemModel.getModel('labelLine');
  49452. var layout = data.getItemLayout(idx);
  49453. var points = layout.points;
  49454. var isLabelInside = labelPosition === 'inner'
  49455. || labelPosition === 'inside' || labelPosition === 'center';
  49456. var textAlign;
  49457. var textX;
  49458. var textY;
  49459. var linePoints;
  49460. if (isLabelInside) {
  49461. textX = (points[0][0] + points[1][0] + points[2][0] + points[3][0]) / 4;
  49462. textY = (points[0][1] + points[1][1] + points[2][1] + points[3][1]) / 4;
  49463. textAlign = 'center';
  49464. linePoints = [
  49465. [textX, textY], [textX, textY]
  49466. ];
  49467. }
  49468. else {
  49469. var x1;
  49470. var y1;
  49471. var x2;
  49472. var labelLineLen = labelLineModel.get('length');
  49473. if (labelPosition === 'left') {
  49474. // Left side
  49475. x1 = (points[3][0] + points[0][0]) / 2;
  49476. y1 = (points[3][1] + points[0][1]) / 2;
  49477. x2 = x1 - labelLineLen;
  49478. textX = x2 - 5;
  49479. textAlign = 'right';
  49480. }
  49481. else {
  49482. // Right side
  49483. x1 = (points[1][0] + points[2][0]) / 2;
  49484. y1 = (points[1][1] + points[2][1]) / 2;
  49485. x2 = x1 + labelLineLen;
  49486. textX = x2 + 5;
  49487. textAlign = 'left';
  49488. }
  49489. var y2 = y1;
  49490. linePoints = [[x1, y1], [x2, y2]];
  49491. textY = y2;
  49492. }
  49493. layout.label = {
  49494. linePoints: linePoints,
  49495. x: textX,
  49496. y: textY,
  49497. verticalAlign: 'middle',
  49498. textAlign: textAlign,
  49499. inside: isLabelInside
  49500. };
  49501. });
  49502. }
  49503. var funnelLayout = function (ecModel, api, payload) {
  49504. ecModel.eachSeriesByType('funnel', function (seriesModel) {
  49505. var data = seriesModel.getData();
  49506. var valueDim = data.mapDimension('value');
  49507. var sort = seriesModel.get('sort');
  49508. var viewRect = getViewRect$2(seriesModel, api);
  49509. var indices = getSortedIndices(data, sort);
  49510. var sizeExtent = [
  49511. parsePercent$1(seriesModel.get('minSize'), viewRect.width),
  49512. parsePercent$1(seriesModel.get('maxSize'), viewRect.width)
  49513. ];
  49514. var dataExtent = data.getDataExtent(valueDim);
  49515. var min = seriesModel.get('min');
  49516. var max = seriesModel.get('max');
  49517. if (min == null) {
  49518. min = Math.min(dataExtent[0], 0);
  49519. }
  49520. if (max == null) {
  49521. max = dataExtent[1];
  49522. }
  49523. var funnelAlign = seriesModel.get('funnelAlign');
  49524. var gap = seriesModel.get('gap');
  49525. var itemHeight = (viewRect.height - gap * (data.count() - 1)) / data.count();
  49526. var y = viewRect.y;
  49527. var getLinePoints = function (idx, offY) {
  49528. // End point index is data.count() and we assign it 0
  49529. var val = data.get(valueDim, idx) || 0;
  49530. var itemWidth = linearMap(val, [min, max], sizeExtent, true);
  49531. var x0;
  49532. switch (funnelAlign) {
  49533. case 'left':
  49534. x0 = viewRect.x;
  49535. break;
  49536. case 'center':
  49537. x0 = viewRect.x + (viewRect.width - itemWidth) / 2;
  49538. break;
  49539. case 'right':
  49540. x0 = viewRect.x + viewRect.width - itemWidth;
  49541. break;
  49542. }
  49543. return [
  49544. [x0, offY],
  49545. [x0 + itemWidth, offY]
  49546. ];
  49547. };
  49548. if (sort === 'ascending') {
  49549. // From bottom to top
  49550. itemHeight = -itemHeight;
  49551. gap = -gap;
  49552. y += viewRect.height;
  49553. indices = indices.reverse();
  49554. }
  49555. for (var i = 0; i < indices.length; i++) {
  49556. var idx = indices[i];
  49557. var nextIdx = indices[i + 1];
  49558. var itemModel = data.getItemModel(idx);
  49559. var height = itemModel.get('itemStyle.height');
  49560. if (height == null) {
  49561. height = itemHeight;
  49562. }
  49563. else {
  49564. height = parsePercent$1(height, viewRect.height);
  49565. if (sort === 'ascending') {
  49566. height = -height;
  49567. }
  49568. }
  49569. var start = getLinePoints(idx, y);
  49570. var end = getLinePoints(nextIdx, y + height);
  49571. y += height + gap;
  49572. data.setItemLayout(idx, {
  49573. points: start.concat(end.slice().reverse())
  49574. });
  49575. }
  49576. labelLayout$1(data);
  49577. });
  49578. };
  49579. /*
  49580. * Licensed to the Apache Software Foundation (ASF) under one
  49581. * or more contributor license agreements. See the NOTICE file
  49582. * distributed with this work for additional information
  49583. * regarding copyright ownership. The ASF licenses this file
  49584. * to you under the Apache License, Version 2.0 (the
  49585. * "License"); you may not use this file except in compliance
  49586. * with the License. You may obtain a copy of the License at
  49587. *
  49588. * http://www.apache.org/licenses/LICENSE-2.0
  49589. *
  49590. * Unless required by applicable law or agreed to in writing,
  49591. * software distributed under the License is distributed on an
  49592. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49593. * KIND, either express or implied. See the License for the
  49594. * specific language governing permissions and limitations
  49595. * under the License.
  49596. */
  49597. registerVisual(dataColor('funnel'));
  49598. registerLayout(funnelLayout);
  49599. registerProcessor(dataFilter('funnel'));
  49600. /*
  49601. * Licensed to the Apache Software Foundation (ASF) under one
  49602. * or more contributor license agreements. See the NOTICE file
  49603. * distributed with this work for additional information
  49604. * regarding copyright ownership. The ASF licenses this file
  49605. * to you under the Apache License, Version 2.0 (the
  49606. * "License"); you may not use this file except in compliance
  49607. * with the License. You may obtain a copy of the License at
  49608. *
  49609. * http://www.apache.org/licenses/LICENSE-2.0
  49610. *
  49611. * Unless required by applicable law or agreed to in writing,
  49612. * software distributed under the License is distributed on an
  49613. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49614. * KIND, either express or implied. See the License for the
  49615. * specific language governing permissions and limitations
  49616. * under the License.
  49617. */
  49618. var parallelPreprocessor = function (option) {
  49619. createParallelIfNeeded(option);
  49620. mergeAxisOptionFromParallel(option);
  49621. };
  49622. /**
  49623. * Create a parallel coordinate if not exists.
  49624. * @inner
  49625. */
  49626. function createParallelIfNeeded(option) {
  49627. if (option.parallel) {
  49628. return;
  49629. }
  49630. var hasParallelSeries = false;
  49631. each$1(option.series, function (seriesOpt) {
  49632. if (seriesOpt && seriesOpt.type === 'parallel') {
  49633. hasParallelSeries = true;
  49634. }
  49635. });
  49636. if (hasParallelSeries) {
  49637. option.parallel = [{}];
  49638. }
  49639. }
  49640. /**
  49641. * Merge aixs definition from parallel option (if exists) to axis option.
  49642. * @inner
  49643. */
  49644. function mergeAxisOptionFromParallel(option) {
  49645. var axes = normalizeToArray(option.parallelAxis);
  49646. each$1(axes, function (axisOption) {
  49647. if (!isObject$1(axisOption)) {
  49648. return;
  49649. }
  49650. var parallelIndex = axisOption.parallelIndex || 0;
  49651. var parallelOption = normalizeToArray(option.parallel)[parallelIndex];
  49652. if (parallelOption && parallelOption.parallelAxisDefault) {
  49653. merge(axisOption, parallelOption.parallelAxisDefault, false);
  49654. }
  49655. });
  49656. }
  49657. /*
  49658. * Licensed to the Apache Software Foundation (ASF) under one
  49659. * or more contributor license agreements. See the NOTICE file
  49660. * distributed with this work for additional information
  49661. * regarding copyright ownership. The ASF licenses this file
  49662. * to you under the Apache License, Version 2.0 (the
  49663. * "License"); you may not use this file except in compliance
  49664. * with the License. You may obtain a copy of the License at
  49665. *
  49666. * http://www.apache.org/licenses/LICENSE-2.0
  49667. *
  49668. * Unless required by applicable law or agreed to in writing,
  49669. * software distributed under the License is distributed on an
  49670. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49671. * KIND, either express or implied. See the License for the
  49672. * specific language governing permissions and limitations
  49673. * under the License.
  49674. */
  49675. /**
  49676. * @constructor module:echarts/coord/parallel/ParallelAxis
  49677. * @extends {module:echarts/coord/Axis}
  49678. * @param {string} dim
  49679. * @param {*} scale
  49680. * @param {Array.<number>} coordExtent
  49681. * @param {string} axisType
  49682. */
  49683. var ParallelAxis = function (dim, scale, coordExtent, axisType, axisIndex) {
  49684. Axis.call(this, dim, scale, coordExtent);
  49685. /**
  49686. * Axis type
  49687. * - 'category'
  49688. * - 'value'
  49689. * - 'time'
  49690. * - 'log'
  49691. * @type {string}
  49692. */
  49693. this.type = axisType || 'value';
  49694. /**
  49695. * @type {number}
  49696. * @readOnly
  49697. */
  49698. this.axisIndex = axisIndex;
  49699. };
  49700. ParallelAxis.prototype = {
  49701. constructor: ParallelAxis,
  49702. /**
  49703. * Axis model
  49704. * @param {module:echarts/coord/parallel/AxisModel}
  49705. */
  49706. model: null,
  49707. /**
  49708. * @override
  49709. */
  49710. isHorizontal: function () {
  49711. return this.coordinateSystem.getModel().get('layout') !== 'horizontal';
  49712. }
  49713. };
  49714. inherits(ParallelAxis, Axis);
  49715. /*
  49716. * Licensed to the Apache Software Foundation (ASF) under one
  49717. * or more contributor license agreements. See the NOTICE file
  49718. * distributed with this work for additional information
  49719. * regarding copyright ownership. The ASF licenses this file
  49720. * to you under the Apache License, Version 2.0 (the
  49721. * "License"); you may not use this file except in compliance
  49722. * with the License. You may obtain a copy of the License at
  49723. *
  49724. * http://www.apache.org/licenses/LICENSE-2.0
  49725. *
  49726. * Unless required by applicable law or agreed to in writing,
  49727. * software distributed under the License is distributed on an
  49728. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49729. * KIND, either express or implied. See the License for the
  49730. * specific language governing permissions and limitations
  49731. * under the License.
  49732. */
  49733. /**
  49734. * Calculate slider move result.
  49735. * Usage:
  49736. * (1) If both handle0 and handle1 are needed to be moved, set minSpan the same as
  49737. * maxSpan and the same as `Math.abs(handleEnd[1] - handleEnds[0])`.
  49738. * (2) If handle0 is forbidden to cross handle1, set minSpan as `0`.
  49739. *
  49740. * @param {number} delta Move length.
  49741. * @param {Array.<number>} handleEnds handleEnds[0] can be bigger then handleEnds[1].
  49742. * handleEnds will be modified in this method.
  49743. * @param {Array.<number>} extent handleEnds is restricted by extent.
  49744. * extent[0] should less or equals than extent[1].
  49745. * @param {number|string} handleIndex Can be 'all', means that both move the two handleEnds,
  49746. * where the input minSpan and maxSpan will not work.
  49747. * @param {number} [minSpan] The range of dataZoom can not be smaller than that.
  49748. * If not set, handle0 and cross handle1. If set as a non-negative
  49749. * number (including `0`), handles will push each other when reaching
  49750. * the minSpan.
  49751. * @param {number} [maxSpan] The range of dataZoom can not be larger than that.
  49752. * @return {Array.<number>} The input handleEnds.
  49753. */
  49754. var sliderMove = function (delta, handleEnds, extent, handleIndex, minSpan, maxSpan) {
  49755. // Normalize firstly.
  49756. handleEnds[0] = restrict$1(handleEnds[0], extent);
  49757. handleEnds[1] = restrict$1(handleEnds[1], extent);
  49758. delta = delta || 0;
  49759. var extentSpan = extent[1] - extent[0];
  49760. // Notice maxSpan and minSpan can be null/undefined.
  49761. if (minSpan != null) {
  49762. minSpan = restrict$1(minSpan, [0, extentSpan]);
  49763. }
  49764. if (maxSpan != null) {
  49765. maxSpan = Math.max(maxSpan, minSpan != null ? minSpan : 0);
  49766. }
  49767. if (handleIndex === 'all') {
  49768. minSpan = maxSpan = Math.abs(handleEnds[1] - handleEnds[0]);
  49769. handleIndex = 0;
  49770. }
  49771. var originalDistSign = getSpanSign(handleEnds, handleIndex);
  49772. handleEnds[handleIndex] += delta;
  49773. // Restrict in extent.
  49774. var extentMinSpan = minSpan || 0;
  49775. var realExtent = extent.slice();
  49776. originalDistSign.sign < 0 ? (realExtent[0] += extentMinSpan) : (realExtent[1] -= extentMinSpan);
  49777. handleEnds[handleIndex] = restrict$1(handleEnds[handleIndex], realExtent);
  49778. // Expand span.
  49779. var currDistSign = getSpanSign(handleEnds, handleIndex);
  49780. if (minSpan != null && (
  49781. currDistSign.sign !== originalDistSign.sign || currDistSign.span < minSpan
  49782. )) {
  49783. // If minSpan exists, 'cross' is forbinden.
  49784. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + originalDistSign.sign * minSpan;
  49785. }
  49786. // Shrink span.
  49787. var currDistSign = getSpanSign(handleEnds, handleIndex);
  49788. if (maxSpan != null && currDistSign.span > maxSpan) {
  49789. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + currDistSign.sign * maxSpan;
  49790. }
  49791. return handleEnds;
  49792. };
  49793. function getSpanSign(handleEnds, handleIndex) {
  49794. var dist = handleEnds[handleIndex] - handleEnds[1 - handleIndex];
  49795. // If `handleEnds[0] === handleEnds[1]`, always believe that handleEnd[0]
  49796. // is at left of handleEnds[1] for non-cross case.
  49797. return {span: Math.abs(dist), sign: dist > 0 ? -1 : dist < 0 ? 1 : handleIndex ? -1 : 1};
  49798. }
  49799. function restrict$1(value, extend) {
  49800. return Math.min(extend[1], Math.max(extend[0], value));
  49801. }
  49802. /*
  49803. * Licensed to the Apache Software Foundation (ASF) under one
  49804. * or more contributor license agreements. See the NOTICE file
  49805. * distributed with this work for additional information
  49806. * regarding copyright ownership. The ASF licenses this file
  49807. * to you under the Apache License, Version 2.0 (the
  49808. * "License"); you may not use this file except in compliance
  49809. * with the License. You may obtain a copy of the License at
  49810. *
  49811. * http://www.apache.org/licenses/LICENSE-2.0
  49812. *
  49813. * Unless required by applicable law or agreed to in writing,
  49814. * software distributed under the License is distributed on an
  49815. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49816. * KIND, either express or implied. See the License for the
  49817. * specific language governing permissions and limitations
  49818. * under the License.
  49819. */
  49820. /**
  49821. * Parallel Coordinates
  49822. * <https://en.wikipedia.org/wiki/Parallel_coordinates>
  49823. */
  49824. var each$11 = each$1;
  49825. var mathMin$5 = Math.min;
  49826. var mathMax$5 = Math.max;
  49827. var mathFloor$2 = Math.floor;
  49828. var mathCeil$2 = Math.ceil;
  49829. var round$3 = round$2;
  49830. var PI$3 = Math.PI;
  49831. function Parallel(parallelModel, ecModel, api) {
  49832. /**
  49833. * key: dimension
  49834. * @type {Object.<string, module:echarts/coord/parallel/Axis>}
  49835. * @private
  49836. */
  49837. this._axesMap = createHashMap();
  49838. /**
  49839. * key: dimension
  49840. * value: {position: [], rotation, }
  49841. * @type {Object.<string, Object>}
  49842. * @private
  49843. */
  49844. this._axesLayout = {};
  49845. /**
  49846. * Always follow axis order.
  49847. * @type {Array.<string>}
  49848. * @readOnly
  49849. */
  49850. this.dimensions = parallelModel.dimensions;
  49851. /**
  49852. * @type {module:zrender/core/BoundingRect}
  49853. */
  49854. this._rect;
  49855. /**
  49856. * @type {module:echarts/coord/parallel/ParallelModel}
  49857. */
  49858. this._model = parallelModel;
  49859. this._init(parallelModel, ecModel, api);
  49860. }
  49861. Parallel.prototype = {
  49862. type: 'parallel',
  49863. constructor: Parallel,
  49864. /**
  49865. * Initialize cartesian coordinate systems
  49866. * @private
  49867. */
  49868. _init: function (parallelModel, ecModel, api) {
  49869. var dimensions = parallelModel.dimensions;
  49870. var parallelAxisIndex = parallelModel.parallelAxisIndex;
  49871. each$11(dimensions, function (dim, idx) {
  49872. var axisIndex = parallelAxisIndex[idx];
  49873. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  49874. var axis = this._axesMap.set(dim, new ParallelAxis(
  49875. dim,
  49876. createScaleByModel(axisModel),
  49877. [0, 0],
  49878. axisModel.get('type'),
  49879. axisIndex
  49880. ));
  49881. var isCategory = axis.type === 'category';
  49882. axis.onBand = isCategory && axisModel.get('boundaryGap');
  49883. axis.inverse = axisModel.get('inverse');
  49884. // Injection
  49885. axisModel.axis = axis;
  49886. axis.model = axisModel;
  49887. axis.coordinateSystem = axisModel.coordinateSystem = this;
  49888. }, this);
  49889. },
  49890. /**
  49891. * Update axis scale after data processed
  49892. * @param {module:echarts/model/Global} ecModel
  49893. * @param {module:echarts/ExtensionAPI} api
  49894. */
  49895. update: function (ecModel, api) {
  49896. this._updateAxesFromSeries(this._model, ecModel);
  49897. },
  49898. /**
  49899. * @override
  49900. */
  49901. containPoint: function (point) {
  49902. var layoutInfo = this._makeLayoutInfo();
  49903. var axisBase = layoutInfo.axisBase;
  49904. var layoutBase = layoutInfo.layoutBase;
  49905. var pixelDimIndex = layoutInfo.pixelDimIndex;
  49906. var pAxis = point[1 - pixelDimIndex];
  49907. var pLayout = point[pixelDimIndex];
  49908. return pAxis >= axisBase
  49909. && pAxis <= axisBase + layoutInfo.axisLength
  49910. && pLayout >= layoutBase
  49911. && pLayout <= layoutBase + layoutInfo.layoutLength;
  49912. },
  49913. getModel: function () {
  49914. return this._model;
  49915. },
  49916. /**
  49917. * Update properties from series
  49918. * @private
  49919. */
  49920. _updateAxesFromSeries: function (parallelModel, ecModel) {
  49921. ecModel.eachSeries(function (seriesModel) {
  49922. if (!parallelModel.contains(seriesModel, ecModel)) {
  49923. return;
  49924. }
  49925. var data = seriesModel.getData();
  49926. each$11(this.dimensions, function (dim) {
  49927. var axis = this._axesMap.get(dim);
  49928. axis.scale.unionExtentFromData(data, data.mapDimension(dim));
  49929. niceScaleExtent(axis.scale, axis.model);
  49930. }, this);
  49931. }, this);
  49932. },
  49933. /**
  49934. * Resize the parallel coordinate system.
  49935. * @param {module:echarts/coord/parallel/ParallelModel} parallelModel
  49936. * @param {module:echarts/ExtensionAPI} api
  49937. */
  49938. resize: function (parallelModel, api) {
  49939. this._rect = getLayoutRect(
  49940. parallelModel.getBoxLayoutParams(),
  49941. {
  49942. width: api.getWidth(),
  49943. height: api.getHeight()
  49944. }
  49945. );
  49946. this._layoutAxes();
  49947. },
  49948. /**
  49949. * @return {module:zrender/core/BoundingRect}
  49950. */
  49951. getRect: function () {
  49952. return this._rect;
  49953. },
  49954. /**
  49955. * @private
  49956. */
  49957. _makeLayoutInfo: function () {
  49958. var parallelModel = this._model;
  49959. var rect = this._rect;
  49960. var xy = ['x', 'y'];
  49961. var wh = ['width', 'height'];
  49962. var layout = parallelModel.get('layout');
  49963. var pixelDimIndex = layout === 'horizontal' ? 0 : 1;
  49964. var layoutLength = rect[wh[pixelDimIndex]];
  49965. var layoutExtent = [0, layoutLength];
  49966. var axisCount = this.dimensions.length;
  49967. var axisExpandWidth = restrict(parallelModel.get('axisExpandWidth'), layoutExtent);
  49968. var axisExpandCount = restrict(parallelModel.get('axisExpandCount') || 0, [0, axisCount]);
  49969. var axisExpandable = parallelModel.get('axisExpandable')
  49970. && axisCount > 3
  49971. && axisCount > axisExpandCount
  49972. && axisExpandCount > 1
  49973. && axisExpandWidth > 0
  49974. && layoutLength > 0;
  49975. // `axisExpandWindow` is According to the coordinates of [0, axisExpandLength],
  49976. // for sake of consider the case that axisCollapseWidth is 0 (when screen is narrow),
  49977. // where collapsed axes should be overlapped.
  49978. var axisExpandWindow = parallelModel.get('axisExpandWindow');
  49979. var winSize;
  49980. if (!axisExpandWindow) {
  49981. winSize = restrict(axisExpandWidth * (axisExpandCount - 1), layoutExtent);
  49982. var axisExpandCenter = parallelModel.get('axisExpandCenter') || mathFloor$2(axisCount / 2);
  49983. axisExpandWindow = [axisExpandWidth * axisExpandCenter - winSize / 2];
  49984. axisExpandWindow[1] = axisExpandWindow[0] + winSize;
  49985. }
  49986. else {
  49987. winSize = restrict(axisExpandWindow[1] - axisExpandWindow[0], layoutExtent);
  49988. axisExpandWindow[1] = axisExpandWindow[0] + winSize;
  49989. }
  49990. var axisCollapseWidth = (layoutLength - winSize) / (axisCount - axisExpandCount);
  49991. // Avoid axisCollapseWidth is too small.
  49992. axisCollapseWidth < 3 && (axisCollapseWidth = 0);
  49993. // Find the first and last indices > ewin[0] and < ewin[1].
  49994. var winInnerIndices = [
  49995. mathFloor$2(round$3(axisExpandWindow[0] / axisExpandWidth, 1)) + 1,
  49996. mathCeil$2(round$3(axisExpandWindow[1] / axisExpandWidth, 1)) - 1
  49997. ];
  49998. // Pos in ec coordinates.
  49999. var axisExpandWindow0Pos = axisCollapseWidth / axisExpandWidth * axisExpandWindow[0];
  50000. return {
  50001. layout: layout,
  50002. pixelDimIndex: pixelDimIndex,
  50003. layoutBase: rect[xy[pixelDimIndex]],
  50004. layoutLength: layoutLength,
  50005. axisBase: rect[xy[1 - pixelDimIndex]],
  50006. axisLength: rect[wh[1 - pixelDimIndex]],
  50007. axisExpandable: axisExpandable,
  50008. axisExpandWidth: axisExpandWidth,
  50009. axisCollapseWidth: axisCollapseWidth,
  50010. axisExpandWindow: axisExpandWindow,
  50011. axisCount: axisCount,
  50012. winInnerIndices: winInnerIndices,
  50013. axisExpandWindow0Pos: axisExpandWindow0Pos
  50014. };
  50015. },
  50016. /**
  50017. * @private
  50018. */
  50019. _layoutAxes: function () {
  50020. var rect = this._rect;
  50021. var axes = this._axesMap;
  50022. var dimensions = this.dimensions;
  50023. var layoutInfo = this._makeLayoutInfo();
  50024. var layout = layoutInfo.layout;
  50025. axes.each(function (axis) {
  50026. var axisExtent = [0, layoutInfo.axisLength];
  50027. var idx = axis.inverse ? 1 : 0;
  50028. axis.setExtent(axisExtent[idx], axisExtent[1 - idx]);
  50029. });
  50030. each$11(dimensions, function (dim, idx) {
  50031. var posInfo = (layoutInfo.axisExpandable
  50032. ? layoutAxisWithExpand : layoutAxisWithoutExpand
  50033. )(idx, layoutInfo);
  50034. var positionTable = {
  50035. horizontal: {
  50036. x: posInfo.position,
  50037. y: layoutInfo.axisLength
  50038. },
  50039. vertical: {
  50040. x: 0,
  50041. y: posInfo.position
  50042. }
  50043. };
  50044. var rotationTable = {
  50045. horizontal: PI$3 / 2,
  50046. vertical: 0
  50047. };
  50048. var position = [
  50049. positionTable[layout].x + rect.x,
  50050. positionTable[layout].y + rect.y
  50051. ];
  50052. var rotation = rotationTable[layout];
  50053. var transform = create$1();
  50054. rotate(transform, transform, rotation);
  50055. translate(transform, transform, position);
  50056. // TODO
  50057. // tick等排布信息。
  50058. // TODO
  50059. // 根据axis order 更新 dimensions顺序。
  50060. this._axesLayout[dim] = {
  50061. position: position,
  50062. rotation: rotation,
  50063. transform: transform,
  50064. axisNameAvailableWidth: posInfo.axisNameAvailableWidth,
  50065. axisLabelShow: posInfo.axisLabelShow,
  50066. nameTruncateMaxWidth: posInfo.nameTruncateMaxWidth,
  50067. tickDirection: 1,
  50068. labelDirection: 1
  50069. };
  50070. }, this);
  50071. },
  50072. /**
  50073. * Get axis by dim.
  50074. * @param {string} dim
  50075. * @return {module:echarts/coord/parallel/ParallelAxis} [description]
  50076. */
  50077. getAxis: function (dim) {
  50078. return this._axesMap.get(dim);
  50079. },
  50080. /**
  50081. * Convert a dim value of a single item of series data to Point.
  50082. * @param {*} value
  50083. * @param {string} dim
  50084. * @return {Array}
  50085. */
  50086. dataToPoint: function (value, dim) {
  50087. return this.axisCoordToPoint(
  50088. this._axesMap.get(dim).dataToCoord(value),
  50089. dim
  50090. );
  50091. },
  50092. /**
  50093. * Travel data for one time, get activeState of each data item.
  50094. * @param {module:echarts/data/List} data
  50095. * @param {Functio} cb param: {string} activeState 'active' or 'inactive' or 'normal'
  50096. * {number} dataIndex
  50097. * @param {number} [start=0] the start dataIndex that travel from.
  50098. * @param {number} [end=data.count()] the next dataIndex of the last dataIndex will be travel.
  50099. */
  50100. eachActiveState: function (data, callback, start, end) {
  50101. start == null && (start = 0);
  50102. end == null && (end = data.count());
  50103. var axesMap = this._axesMap;
  50104. var dimensions = this.dimensions;
  50105. var dataDimensions = [];
  50106. var axisModels = [];
  50107. each$1(dimensions, function (axisDim) {
  50108. dataDimensions.push(data.mapDimension(axisDim));
  50109. axisModels.push(axesMap.get(axisDim).model);
  50110. });
  50111. var hasActiveSet = this.hasAxisBrushed();
  50112. for (var dataIndex = start; dataIndex < end; dataIndex++) {
  50113. var activeState;
  50114. if (!hasActiveSet) {
  50115. activeState = 'normal';
  50116. }
  50117. else {
  50118. activeState = 'active';
  50119. var values = data.getValues(dataDimensions, dataIndex);
  50120. for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
  50121. var state = axisModels[j].getActiveState(values[j]);
  50122. if (state === 'inactive') {
  50123. activeState = 'inactive';
  50124. break;
  50125. }
  50126. }
  50127. }
  50128. callback(activeState, dataIndex);
  50129. }
  50130. },
  50131. /**
  50132. * Whether has any activeSet.
  50133. * @return {boolean}
  50134. */
  50135. hasAxisBrushed: function () {
  50136. var dimensions = this.dimensions;
  50137. var axesMap = this._axesMap;
  50138. var hasActiveSet = false;
  50139. for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
  50140. if (axesMap.get(dimensions[j]).model.getActiveState() !== 'normal') {
  50141. hasActiveSet = true;
  50142. }
  50143. }
  50144. return hasActiveSet;
  50145. },
  50146. /**
  50147. * Convert coords of each axis to Point.
  50148. * Return point. For example: [10, 20]
  50149. * @param {Array.<number>} coords
  50150. * @param {string} dim
  50151. * @return {Array.<number>}
  50152. */
  50153. axisCoordToPoint: function (coord, dim) {
  50154. var axisLayout = this._axesLayout[dim];
  50155. return applyTransform$1([coord, 0], axisLayout.transform);
  50156. },
  50157. /**
  50158. * Get axis layout.
  50159. */
  50160. getAxisLayout: function (dim) {
  50161. return clone(this._axesLayout[dim]);
  50162. },
  50163. /**
  50164. * @param {Array.<number>} point
  50165. * @return {Object} {axisExpandWindow, delta, behavior: 'jump' | 'slide' | 'none'}.
  50166. */
  50167. getSlidedAxisExpandWindow: function (point) {
  50168. var layoutInfo = this._makeLayoutInfo();
  50169. var pixelDimIndex = layoutInfo.pixelDimIndex;
  50170. var axisExpandWindow = layoutInfo.axisExpandWindow.slice();
  50171. var winSize = axisExpandWindow[1] - axisExpandWindow[0];
  50172. var extent = [0, layoutInfo.axisExpandWidth * (layoutInfo.axisCount - 1)];
  50173. // Out of the area of coordinate system.
  50174. if (!this.containPoint(point)) {
  50175. return {behavior: 'none', axisExpandWindow: axisExpandWindow};
  50176. }
  50177. // Conver the point from global to expand coordinates.
  50178. var pointCoord = point[pixelDimIndex] - layoutInfo.layoutBase - layoutInfo.axisExpandWindow0Pos;
  50179. // For dragging operation convenience, the window should not be
  50180. // slided when mouse is the center area of the window.
  50181. var delta;
  50182. var behavior = 'slide';
  50183. var axisCollapseWidth = layoutInfo.axisCollapseWidth;
  50184. var triggerArea = this._model.get('axisExpandSlideTriggerArea');
  50185. // But consider touch device, jump is necessary.
  50186. var useJump = triggerArea[0] != null;
  50187. if (axisCollapseWidth) {
  50188. if (useJump && axisCollapseWidth && pointCoord < winSize * triggerArea[0]) {
  50189. behavior = 'jump';
  50190. delta = pointCoord - winSize * triggerArea[2];
  50191. }
  50192. else if (useJump && axisCollapseWidth && pointCoord > winSize * (1 - triggerArea[0])) {
  50193. behavior = 'jump';
  50194. delta = pointCoord - winSize * (1 - triggerArea[2]);
  50195. }
  50196. else {
  50197. (delta = pointCoord - winSize * triggerArea[1]) >= 0
  50198. && (delta = pointCoord - winSize * (1 - triggerArea[1])) <= 0
  50199. && (delta = 0);
  50200. }
  50201. delta *= layoutInfo.axisExpandWidth / axisCollapseWidth;
  50202. delta
  50203. ? sliderMove(delta, axisExpandWindow, extent, 'all')
  50204. // Avoid nonsense triger on mousemove.
  50205. : (behavior = 'none');
  50206. }
  50207. // When screen is too narrow, make it visible and slidable, although it is hard to interact.
  50208. else {
  50209. var winSize = axisExpandWindow[1] - axisExpandWindow[0];
  50210. var pos = extent[1] * pointCoord / winSize;
  50211. axisExpandWindow = [mathMax$5(0, pos - winSize / 2)];
  50212. axisExpandWindow[1] = mathMin$5(extent[1], axisExpandWindow[0] + winSize);
  50213. axisExpandWindow[0] = axisExpandWindow[1] - winSize;
  50214. }
  50215. return {
  50216. axisExpandWindow: axisExpandWindow,
  50217. behavior: behavior
  50218. };
  50219. }
  50220. };
  50221. function restrict(len, extent) {
  50222. return mathMin$5(mathMax$5(len, extent[0]), extent[1]);
  50223. }
  50224. function layoutAxisWithoutExpand(axisIndex, layoutInfo) {
  50225. var step = layoutInfo.layoutLength / (layoutInfo.axisCount - 1);
  50226. return {
  50227. position: step * axisIndex,
  50228. axisNameAvailableWidth: step,
  50229. axisLabelShow: true
  50230. };
  50231. }
  50232. function layoutAxisWithExpand(axisIndex, layoutInfo) {
  50233. var layoutLength = layoutInfo.layoutLength;
  50234. var axisExpandWidth = layoutInfo.axisExpandWidth;
  50235. var axisCount = layoutInfo.axisCount;
  50236. var axisCollapseWidth = layoutInfo.axisCollapseWidth;
  50237. var winInnerIndices = layoutInfo.winInnerIndices;
  50238. var position;
  50239. var axisNameAvailableWidth = axisCollapseWidth;
  50240. var axisLabelShow = false;
  50241. var nameTruncateMaxWidth;
  50242. if (axisIndex < winInnerIndices[0]) {
  50243. position = axisIndex * axisCollapseWidth;
  50244. nameTruncateMaxWidth = axisCollapseWidth;
  50245. }
  50246. else if (axisIndex <= winInnerIndices[1]) {
  50247. position = layoutInfo.axisExpandWindow0Pos
  50248. + axisIndex * axisExpandWidth - layoutInfo.axisExpandWindow[0];
  50249. axisNameAvailableWidth = axisExpandWidth;
  50250. axisLabelShow = true;
  50251. }
  50252. else {
  50253. position = layoutLength - (axisCount - 1 - axisIndex) * axisCollapseWidth;
  50254. nameTruncateMaxWidth = axisCollapseWidth;
  50255. }
  50256. return {
  50257. position: position,
  50258. axisNameAvailableWidth: axisNameAvailableWidth,
  50259. axisLabelShow: axisLabelShow,
  50260. nameTruncateMaxWidth: nameTruncateMaxWidth
  50261. };
  50262. }
  50263. /*
  50264. * Licensed to the Apache Software Foundation (ASF) under one
  50265. * or more contributor license agreements. See the NOTICE file
  50266. * distributed with this work for additional information
  50267. * regarding copyright ownership. The ASF licenses this file
  50268. * to you under the Apache License, Version 2.0 (the
  50269. * "License"); you may not use this file except in compliance
  50270. * with the License. You may obtain a copy of the License at
  50271. *
  50272. * http://www.apache.org/licenses/LICENSE-2.0
  50273. *
  50274. * Unless required by applicable law or agreed to in writing,
  50275. * software distributed under the License is distributed on an
  50276. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50277. * KIND, either express or implied. See the License for the
  50278. * specific language governing permissions and limitations
  50279. * under the License.
  50280. */
  50281. /**
  50282. * Parallel coordinate system creater.
  50283. */
  50284. function create$2(ecModel, api) {
  50285. var coordSysList = [];
  50286. ecModel.eachComponent('parallel', function (parallelModel, idx) {
  50287. var coordSys = new Parallel(parallelModel, ecModel, api);
  50288. coordSys.name = 'parallel_' + idx;
  50289. coordSys.resize(parallelModel, api);
  50290. parallelModel.coordinateSystem = coordSys;
  50291. coordSys.model = parallelModel;
  50292. coordSysList.push(coordSys);
  50293. });
  50294. // Inject the coordinateSystems into seriesModel
  50295. ecModel.eachSeries(function (seriesModel) {
  50296. if (seriesModel.get('coordinateSystem') === 'parallel') {
  50297. var parallelModel = ecModel.queryComponents({
  50298. mainType: 'parallel',
  50299. index: seriesModel.get('parallelIndex'),
  50300. id: seriesModel.get('parallelId')
  50301. })[0];
  50302. seriesModel.coordinateSystem = parallelModel.coordinateSystem;
  50303. }
  50304. });
  50305. return coordSysList;
  50306. }
  50307. CoordinateSystemManager.register('parallel', {create: create$2});
  50308. /*
  50309. * Licensed to the Apache Software Foundation (ASF) under one
  50310. * or more contributor license agreements. See the NOTICE file
  50311. * distributed with this work for additional information
  50312. * regarding copyright ownership. The ASF licenses this file
  50313. * to you under the Apache License, Version 2.0 (the
  50314. * "License"); you may not use this file except in compliance
  50315. * with the License. You may obtain a copy of the License at
  50316. *
  50317. * http://www.apache.org/licenses/LICENSE-2.0
  50318. *
  50319. * Unless required by applicable law or agreed to in writing,
  50320. * software distributed under the License is distributed on an
  50321. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50322. * KIND, either express or implied. See the License for the
  50323. * specific language governing permissions and limitations
  50324. * under the License.
  50325. */
  50326. var AxisModel$2 = ComponentModel.extend({
  50327. type: 'baseParallelAxis',
  50328. /**
  50329. * @type {module:echarts/coord/parallel/Axis}
  50330. */
  50331. axis: null,
  50332. /**
  50333. * @type {Array.<Array.<number>}
  50334. * @readOnly
  50335. */
  50336. activeIntervals: [],
  50337. /**
  50338. * @return {Object}
  50339. */
  50340. getAreaSelectStyle: function () {
  50341. return makeStyleMapper(
  50342. [
  50343. ['fill', 'color'],
  50344. ['lineWidth', 'borderWidth'],
  50345. ['stroke', 'borderColor'],
  50346. ['width', 'width'],
  50347. ['opacity', 'opacity']
  50348. ]
  50349. )(this.getModel('areaSelectStyle'));
  50350. },
  50351. /**
  50352. * The code of this feature is put on AxisModel but not ParallelAxis,
  50353. * because axisModel can be alive after echarts updating but instance of
  50354. * ParallelAxis having been disposed. this._activeInterval should be kept
  50355. * when action dispatched (i.e. legend click).
  50356. *
  50357. * @param {Array.<Array<number>>} intervals interval.length === 0
  50358. * means set all active.
  50359. * @public
  50360. */
  50361. setActiveIntervals: function (intervals) {
  50362. var activeIntervals = this.activeIntervals = clone(intervals);
  50363. // Normalize
  50364. if (activeIntervals) {
  50365. for (var i = activeIntervals.length - 1; i >= 0; i--) {
  50366. asc(activeIntervals[i]);
  50367. }
  50368. }
  50369. },
  50370. /**
  50371. * @param {number|string} [value] When attempting to detect 'no activeIntervals set',
  50372. * value can not be input.
  50373. * @return {string} 'normal': no activeIntervals set,
  50374. * 'active',
  50375. * 'inactive'.
  50376. * @public
  50377. */
  50378. getActiveState: function (value) {
  50379. var activeIntervals = this.activeIntervals;
  50380. if (!activeIntervals.length) {
  50381. return 'normal';
  50382. }
  50383. if (value == null || isNaN(value)) {
  50384. return 'inactive';
  50385. }
  50386. // Simple optimization
  50387. if (activeIntervals.length === 1) {
  50388. var interval = activeIntervals[0];
  50389. if (interval[0] <= value && value <= interval[1]) {
  50390. return 'active';
  50391. }
  50392. }
  50393. else {
  50394. for (var i = 0, len = activeIntervals.length; i < len; i++) {
  50395. if (activeIntervals[i][0] <= value && value <= activeIntervals[i][1]) {
  50396. return 'active';
  50397. }
  50398. }
  50399. }
  50400. return 'inactive';
  50401. }
  50402. });
  50403. var defaultOption$1 = {
  50404. type: 'value',
  50405. /**
  50406. * @type {Array.<number>}
  50407. */
  50408. dim: null, // 0, 1, 2, ...
  50409. // parallelIndex: null,
  50410. areaSelectStyle: {
  50411. width: 20,
  50412. borderWidth: 1,
  50413. borderColor: 'rgba(160,197,232)',
  50414. color: 'rgba(160,197,232)',
  50415. opacity: 0.3
  50416. },
  50417. realtime: true, // Whether realtime update view when select.
  50418. z: 10
  50419. };
  50420. merge(AxisModel$2.prototype, axisModelCommonMixin);
  50421. function getAxisType$1(axisName, option) {
  50422. return option.type || (option.data ? 'category' : 'value');
  50423. }
  50424. axisModelCreator('parallel', AxisModel$2, getAxisType$1, defaultOption$1);
  50425. /*
  50426. * Licensed to the Apache Software Foundation (ASF) under one
  50427. * or more contributor license agreements. See the NOTICE file
  50428. * distributed with this work for additional information
  50429. * regarding copyright ownership. The ASF licenses this file
  50430. * to you under the Apache License, Version 2.0 (the
  50431. * "License"); you may not use this file except in compliance
  50432. * with the License. You may obtain a copy of the License at
  50433. *
  50434. * http://www.apache.org/licenses/LICENSE-2.0
  50435. *
  50436. * Unless required by applicable law or agreed to in writing,
  50437. * software distributed under the License is distributed on an
  50438. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50439. * KIND, either express or implied. See the License for the
  50440. * specific language governing permissions and limitations
  50441. * under the License.
  50442. */
  50443. ComponentModel.extend({
  50444. type: 'parallel',
  50445. dependencies: ['parallelAxis'],
  50446. /**
  50447. * @type {module:echarts/coord/parallel/Parallel}
  50448. */
  50449. coordinateSystem: null,
  50450. /**
  50451. * Each item like: 'dim0', 'dim1', 'dim2', ...
  50452. * @type {Array.<string>}
  50453. * @readOnly
  50454. */
  50455. dimensions: null,
  50456. /**
  50457. * Coresponding to dimensions.
  50458. * @type {Array.<number>}
  50459. * @readOnly
  50460. */
  50461. parallelAxisIndex: null,
  50462. layoutMode: 'box',
  50463. defaultOption: {
  50464. zlevel: 0,
  50465. z: 0,
  50466. left: 80,
  50467. top: 60,
  50468. right: 80,
  50469. bottom: 60,
  50470. // width: {totalWidth} - left - right,
  50471. // height: {totalHeight} - top - bottom,
  50472. layout: 'horizontal', // 'horizontal' or 'vertical'
  50473. // FIXME
  50474. // naming?
  50475. axisExpandable: false,
  50476. axisExpandCenter: null,
  50477. axisExpandCount: 0,
  50478. axisExpandWidth: 50, // FIXME '10%' ?
  50479. axisExpandRate: 17,
  50480. axisExpandDebounce: 50,
  50481. // [out, in, jumpTarget]. In percentage. If use [null, 0.05], null means full.
  50482. // Do not doc to user until necessary.
  50483. axisExpandSlideTriggerArea: [-0.15, 0.05, 0.4],
  50484. axisExpandTriggerOn: 'click', // 'mousemove' or 'click'
  50485. parallelAxisDefault: null
  50486. },
  50487. /**
  50488. * @override
  50489. */
  50490. init: function () {
  50491. ComponentModel.prototype.init.apply(this, arguments);
  50492. this.mergeOption({});
  50493. },
  50494. /**
  50495. * @override
  50496. */
  50497. mergeOption: function (newOption) {
  50498. var thisOption = this.option;
  50499. newOption && merge(thisOption, newOption, true);
  50500. this._initDimensions();
  50501. },
  50502. /**
  50503. * Whether series or axis is in this coordinate system.
  50504. * @param {module:echarts/model/Series|module:echarts/coord/parallel/AxisModel} model
  50505. * @param {module:echarts/model/Global} ecModel
  50506. */
  50507. contains: function (model, ecModel) {
  50508. var parallelIndex = model.get('parallelIndex');
  50509. return parallelIndex != null
  50510. && ecModel.getComponent('parallel', parallelIndex) === this;
  50511. },
  50512. setAxisExpand: function (opt) {
  50513. each$1(
  50514. ['axisExpandable', 'axisExpandCenter', 'axisExpandCount', 'axisExpandWidth', 'axisExpandWindow'],
  50515. function (name) {
  50516. if (opt.hasOwnProperty(name)) {
  50517. this.option[name] = opt[name];
  50518. }
  50519. },
  50520. this
  50521. );
  50522. },
  50523. /**
  50524. * @private
  50525. */
  50526. _initDimensions: function () {
  50527. var dimensions = this.dimensions = [];
  50528. var parallelAxisIndex = this.parallelAxisIndex = [];
  50529. var axisModels = filter(this.dependentModels.parallelAxis, function (axisModel) {
  50530. // Can not use this.contains here, because
  50531. // initialization has not been completed yet.
  50532. return (axisModel.get('parallelIndex') || 0) === this.componentIndex;
  50533. }, this);
  50534. each$1(axisModels, function (axisModel) {
  50535. dimensions.push('dim' + axisModel.get('dim'));
  50536. parallelAxisIndex.push(axisModel.componentIndex);
  50537. });
  50538. }
  50539. });
  50540. /*
  50541. * Licensed to the Apache Software Foundation (ASF) under one
  50542. * or more contributor license agreements. See the NOTICE file
  50543. * distributed with this work for additional information
  50544. * regarding copyright ownership. The ASF licenses this file
  50545. * to you under the Apache License, Version 2.0 (the
  50546. * "License"); you may not use this file except in compliance
  50547. * with the License. You may obtain a copy of the License at
  50548. *
  50549. * http://www.apache.org/licenses/LICENSE-2.0
  50550. *
  50551. * Unless required by applicable law or agreed to in writing,
  50552. * software distributed under the License is distributed on an
  50553. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50554. * KIND, either express or implied. See the License for the
  50555. * specific language governing permissions and limitations
  50556. * under the License.
  50557. */
  50558. /**
  50559. * @payload
  50560. * @property {string} parallelAxisId
  50561. * @property {Array.<Array.<number>>} intervals
  50562. */
  50563. var actionInfo$1 = {
  50564. type: 'axisAreaSelect',
  50565. event: 'axisAreaSelected'
  50566. // update: 'updateVisual'
  50567. };
  50568. registerAction(actionInfo$1, function (payload, ecModel) {
  50569. ecModel.eachComponent(
  50570. {mainType: 'parallelAxis', query: payload},
  50571. function (parallelAxisModel) {
  50572. parallelAxisModel.axis.model.setActiveIntervals(payload.intervals);
  50573. }
  50574. );
  50575. });
  50576. /**
  50577. * @payload
  50578. */
  50579. registerAction('parallelAxisExpand', function (payload, ecModel) {
  50580. ecModel.eachComponent(
  50581. {mainType: 'parallel', query: payload},
  50582. function (parallelModel) {
  50583. parallelModel.setAxisExpand(payload);
  50584. }
  50585. );
  50586. });
  50587. /*
  50588. * Licensed to the Apache Software Foundation (ASF) under one
  50589. * or more contributor license agreements. See the NOTICE file
  50590. * distributed with this work for additional information
  50591. * regarding copyright ownership. The ASF licenses this file
  50592. * to you under the Apache License, Version 2.0 (the
  50593. * "License"); you may not use this file except in compliance
  50594. * with the License. You may obtain a copy of the License at
  50595. *
  50596. * http://www.apache.org/licenses/LICENSE-2.0
  50597. *
  50598. * Unless required by applicable law or agreed to in writing,
  50599. * software distributed under the License is distributed on an
  50600. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50601. * KIND, either express or implied. See the License for the
  50602. * specific language governing permissions and limitations
  50603. * under the License.
  50604. */
  50605. var curry$2 = curry;
  50606. var each$12 = each$1;
  50607. var map$2 = map;
  50608. var mathMin$6 = Math.min;
  50609. var mathMax$6 = Math.max;
  50610. var mathPow$2 = Math.pow;
  50611. var COVER_Z = 10000;
  50612. var UNSELECT_THRESHOLD = 6;
  50613. var MIN_RESIZE_LINE_WIDTH = 6;
  50614. var MUTEX_RESOURCE_KEY = 'globalPan';
  50615. var DIRECTION_MAP = {
  50616. w: [0, 0],
  50617. e: [0, 1],
  50618. n: [1, 0],
  50619. s: [1, 1]
  50620. };
  50621. var CURSOR_MAP = {
  50622. w: 'ew',
  50623. e: 'ew',
  50624. n: 'ns',
  50625. s: 'ns',
  50626. ne: 'nesw',
  50627. sw: 'nesw',
  50628. nw: 'nwse',
  50629. se: 'nwse'
  50630. };
  50631. var DEFAULT_BRUSH_OPT = {
  50632. brushStyle: {
  50633. lineWidth: 2,
  50634. stroke: 'rgba(0,0,0,0.3)',
  50635. fill: 'rgba(0,0,0,0.1)'
  50636. },
  50637. transformable: true,
  50638. brushMode: 'single',
  50639. removeOnClick: false
  50640. };
  50641. var baseUID = 0;
  50642. /**
  50643. * @alias module:echarts/component/helper/BrushController
  50644. * @constructor
  50645. * @mixin {module:zrender/mixin/Eventful}
  50646. * @event module:echarts/component/helper/BrushController#brush
  50647. * params:
  50648. * areas: Array.<Array>, coord relates to container group,
  50649. * If no container specified, to global.
  50650. * opt {
  50651. * isEnd: boolean,
  50652. * removeOnClick: boolean
  50653. * }
  50654. *
  50655. * @param {module:zrender/zrender~ZRender} zr
  50656. */
  50657. function BrushController(zr) {
  50658. if (__DEV__) {
  50659. assert$1(zr);
  50660. }
  50661. Eventful.call(this);
  50662. /**
  50663. * @type {module:zrender/zrender~ZRender}
  50664. * @private
  50665. */
  50666. this._zr = zr;
  50667. /**
  50668. * @type {module:zrender/container/Group}
  50669. * @readOnly
  50670. */
  50671. this.group = new Group();
  50672. /**
  50673. * Only for drawing (after enabledBrush).
  50674. * 'line', 'rect', 'polygon' or false
  50675. * If passing false/null/undefined, disable brush.
  50676. * If passing 'auto', determined by panel.defaultBrushType
  50677. * @private
  50678. * @type {string}
  50679. */
  50680. this._brushType;
  50681. /**
  50682. * Only for drawing (after enabledBrush).
  50683. *
  50684. * @private
  50685. * @type {Object}
  50686. */
  50687. this._brushOption;
  50688. /**
  50689. * @private
  50690. * @type {Object}
  50691. */
  50692. this._panels;
  50693. /**
  50694. * @private
  50695. * @type {Array.<nubmer>}
  50696. */
  50697. this._track = [];
  50698. /**
  50699. * @private
  50700. * @type {boolean}
  50701. */
  50702. this._dragging;
  50703. /**
  50704. * @private
  50705. * @type {Array}
  50706. */
  50707. this._covers = [];
  50708. /**
  50709. * @private
  50710. * @type {moudule:zrender/container/Group}
  50711. */
  50712. this._creatingCover;
  50713. /**
  50714. * `true` means global panel
  50715. * @private
  50716. * @type {module:zrender/container/Group|boolean}
  50717. */
  50718. this._creatingPanel;
  50719. /**
  50720. * @private
  50721. * @type {boolean}
  50722. */
  50723. this._enableGlobalPan;
  50724. /**
  50725. * @private
  50726. * @type {boolean}
  50727. */
  50728. if (__DEV__) {
  50729. this._mounted;
  50730. }
  50731. /**
  50732. * @private
  50733. * @type {string}
  50734. */
  50735. this._uid = 'brushController_' + baseUID++;
  50736. /**
  50737. * @private
  50738. * @type {Object}
  50739. */
  50740. this._handlers = {};
  50741. each$12(mouseHandlers, function (handler, eventName) {
  50742. this._handlers[eventName] = bind(handler, this);
  50743. }, this);
  50744. }
  50745. BrushController.prototype = {
  50746. constructor: BrushController,
  50747. /**
  50748. * If set to null/undefined/false, select disabled.
  50749. * @param {Object} brushOption
  50750. * @param {string|boolean} brushOption.brushType 'line', 'rect', 'polygon' or false
  50751. * If passing false/null/undefined, disable brush.
  50752. * If passing 'auto', determined by panel.defaultBrushType.
  50753. * ('auto' can not be used in global panel)
  50754. * @param {number} [brushOption.brushMode='single'] 'single' or 'multiple'
  50755. * @param {boolean} [brushOption.transformable=true]
  50756. * @param {boolean} [brushOption.removeOnClick=false]
  50757. * @param {Object} [brushOption.brushStyle]
  50758. * @param {number} [brushOption.brushStyle.width]
  50759. * @param {number} [brushOption.brushStyle.lineWidth]
  50760. * @param {string} [brushOption.brushStyle.stroke]
  50761. * @param {string} [brushOption.brushStyle.fill]
  50762. * @param {number} [brushOption.z]
  50763. */
  50764. enableBrush: function (brushOption) {
  50765. if (__DEV__) {
  50766. assert$1(this._mounted);
  50767. }
  50768. this._brushType && doDisableBrush(this);
  50769. brushOption.brushType && doEnableBrush(this, brushOption);
  50770. return this;
  50771. },
  50772. /**
  50773. * @param {Array.<Object>} panelOpts If not pass, it is global brush.
  50774. * Each items: {
  50775. * panelId, // mandatory.
  50776. * clipPath, // mandatory. function.
  50777. * isTargetByCursor, // mandatory. function.
  50778. * defaultBrushType, // optional, only used when brushType is 'auto'.
  50779. * getLinearBrushOtherExtent, // optional. function.
  50780. * }
  50781. */
  50782. setPanels: function (panelOpts) {
  50783. if (panelOpts && panelOpts.length) {
  50784. var panels = this._panels = {};
  50785. each$1(panelOpts, function (panelOpts) {
  50786. panels[panelOpts.panelId] = clone(panelOpts);
  50787. });
  50788. }
  50789. else {
  50790. this._panels = null;
  50791. }
  50792. return this;
  50793. },
  50794. /**
  50795. * @param {Object} [opt]
  50796. * @return {boolean} [opt.enableGlobalPan=false]
  50797. */
  50798. mount: function (opt) {
  50799. opt = opt || {};
  50800. if (__DEV__) {
  50801. this._mounted = true; // should be at first.
  50802. }
  50803. this._enableGlobalPan = opt.enableGlobalPan;
  50804. var thisGroup = this.group;
  50805. this._zr.add(thisGroup);
  50806. thisGroup.attr({
  50807. position: opt.position || [0, 0],
  50808. rotation: opt.rotation || 0,
  50809. scale: opt.scale || [1, 1]
  50810. });
  50811. this._transform = thisGroup.getLocalTransform();
  50812. return this;
  50813. },
  50814. eachCover: function (cb, context) {
  50815. each$12(this._covers, cb, context);
  50816. },
  50817. /**
  50818. * Update covers.
  50819. * @param {Array.<Object>} brushOptionList Like:
  50820. * [
  50821. * {id: 'xx', brushType: 'line', range: [23, 44], brushStyle, transformable},
  50822. * {id: 'yy', brushType: 'rect', range: [[23, 44], [23, 54]]},
  50823. * ...
  50824. * ]
  50825. * `brushType` is required in each cover info. (can not be 'auto')
  50826. * `id` is not mandatory.
  50827. * `brushStyle`, `transformable` is not mandatory, use DEFAULT_BRUSH_OPT by default.
  50828. * If brushOptionList is null/undefined, all covers removed.
  50829. */
  50830. updateCovers: function (brushOptionList) {
  50831. if (__DEV__) {
  50832. assert$1(this._mounted);
  50833. }
  50834. brushOptionList = map(brushOptionList, function (brushOption) {
  50835. return merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  50836. });
  50837. var tmpIdPrefix = '\0-brush-index-';
  50838. var oldCovers = this._covers;
  50839. var newCovers = this._covers = [];
  50840. var controller = this;
  50841. var creatingCover = this._creatingCover;
  50842. (new DataDiffer(oldCovers, brushOptionList, oldGetKey, getKey))
  50843. .add(addOrUpdate)
  50844. .update(addOrUpdate)
  50845. .remove(remove)
  50846. .execute();
  50847. return this;
  50848. function getKey(brushOption, index) {
  50849. return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index)
  50850. + '-' + brushOption.brushType;
  50851. }
  50852. function oldGetKey(cover, index) {
  50853. return getKey(cover.__brushOption, index);
  50854. }
  50855. function addOrUpdate(newIndex, oldIndex) {
  50856. var newBrushOption = brushOptionList[newIndex];
  50857. // Consider setOption in event listener of brushSelect,
  50858. // where updating cover when creating should be forbiden.
  50859. if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
  50860. newCovers[newIndex] = oldCovers[oldIndex];
  50861. }
  50862. else {
  50863. var cover = newCovers[newIndex] = oldIndex != null
  50864. ? (
  50865. oldCovers[oldIndex].__brushOption = newBrushOption,
  50866. oldCovers[oldIndex]
  50867. )
  50868. : endCreating(controller, createCover(controller, newBrushOption));
  50869. updateCoverAfterCreation(controller, cover);
  50870. }
  50871. }
  50872. function remove(oldIndex) {
  50873. if (oldCovers[oldIndex] !== creatingCover) {
  50874. controller.group.remove(oldCovers[oldIndex]);
  50875. }
  50876. }
  50877. },
  50878. unmount: function () {
  50879. if (__DEV__) {
  50880. if (!this._mounted) {
  50881. return;
  50882. }
  50883. }
  50884. this.enableBrush(false);
  50885. // container may 'removeAll' outside.
  50886. clearCovers(this);
  50887. this._zr.remove(this.group);
  50888. if (__DEV__) {
  50889. this._mounted = false; // should be at last.
  50890. }
  50891. return this;
  50892. },
  50893. dispose: function () {
  50894. this.unmount();
  50895. this.off();
  50896. }
  50897. };
  50898. mixin(BrushController, Eventful);
  50899. function doEnableBrush(controller, brushOption) {
  50900. var zr = controller._zr;
  50901. // Consider roam, which takes globalPan too.
  50902. if (!controller._enableGlobalPan) {
  50903. take(zr, MUTEX_RESOURCE_KEY, controller._uid);
  50904. }
  50905. each$12(controller._handlers, function (handler, eventName) {
  50906. zr.on(eventName, handler);
  50907. });
  50908. controller._brushType = brushOption.brushType;
  50909. controller._brushOption = merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  50910. }
  50911. function doDisableBrush(controller) {
  50912. var zr = controller._zr;
  50913. release(zr, MUTEX_RESOURCE_KEY, controller._uid);
  50914. each$12(controller._handlers, function (handler, eventName) {
  50915. zr.off(eventName, handler);
  50916. });
  50917. controller._brushType = controller._brushOption = null;
  50918. }
  50919. function createCover(controller, brushOption) {
  50920. var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
  50921. cover.__brushOption = brushOption;
  50922. updateZ$1(cover, brushOption);
  50923. controller.group.add(cover);
  50924. return cover;
  50925. }
  50926. function endCreating(controller, creatingCover) {
  50927. var coverRenderer = getCoverRenderer(creatingCover);
  50928. if (coverRenderer.endCreating) {
  50929. coverRenderer.endCreating(controller, creatingCover);
  50930. updateZ$1(creatingCover, creatingCover.__brushOption);
  50931. }
  50932. return creatingCover;
  50933. }
  50934. function updateCoverShape(controller, cover) {
  50935. var brushOption = cover.__brushOption;
  50936. getCoverRenderer(cover).updateCoverShape(
  50937. controller, cover, brushOption.range, brushOption
  50938. );
  50939. }
  50940. function updateZ$1(cover, brushOption) {
  50941. var z = brushOption.z;
  50942. z == null && (z = COVER_Z);
  50943. cover.traverse(function (el) {
  50944. el.z = z;
  50945. el.z2 = z; // Consider in given container.
  50946. });
  50947. }
  50948. function updateCoverAfterCreation(controller, cover) {
  50949. getCoverRenderer(cover).updateCommon(controller, cover);
  50950. updateCoverShape(controller, cover);
  50951. }
  50952. function getCoverRenderer(cover) {
  50953. return coverRenderers[cover.__brushOption.brushType];
  50954. }
  50955. // return target panel or `true` (means global panel)
  50956. function getPanelByPoint(controller, e, localCursorPoint) {
  50957. var panels = controller._panels;
  50958. if (!panels) {
  50959. return true; // Global panel
  50960. }
  50961. var panel;
  50962. var transform = controller._transform;
  50963. each$12(panels, function (pn) {
  50964. pn.isTargetByCursor(e, localCursorPoint, transform) && (panel = pn);
  50965. });
  50966. return panel;
  50967. }
  50968. // Return a panel or true
  50969. function getPanelByCover(controller, cover) {
  50970. var panels = controller._panels;
  50971. if (!panels) {
  50972. return true; // Global panel
  50973. }
  50974. var panelId = cover.__brushOption.panelId;
  50975. // User may give cover without coord sys info,
  50976. // which is then treated as global panel.
  50977. return panelId != null ? panels[panelId] : true;
  50978. }
  50979. function clearCovers(controller) {
  50980. var covers = controller._covers;
  50981. var originalLength = covers.length;
  50982. each$12(covers, function (cover) {
  50983. controller.group.remove(cover);
  50984. }, controller);
  50985. covers.length = 0;
  50986. return !!originalLength;
  50987. }
  50988. function trigger$1(controller, opt) {
  50989. var areas = map$2(controller._covers, function (cover) {
  50990. var brushOption = cover.__brushOption;
  50991. var range = clone(brushOption.range);
  50992. return {
  50993. brushType: brushOption.brushType,
  50994. panelId: brushOption.panelId,
  50995. range: range
  50996. };
  50997. });
  50998. controller.trigger('brush', areas, {
  50999. isEnd: !!opt.isEnd,
  51000. removeOnClick: !!opt.removeOnClick
  51001. });
  51002. }
  51003. function shouldShowCover(controller) {
  51004. var track = controller._track;
  51005. if (!track.length) {
  51006. return false;
  51007. }
  51008. var p2 = track[track.length - 1];
  51009. var p1 = track[0];
  51010. var dx = p2[0] - p1[0];
  51011. var dy = p2[1] - p1[1];
  51012. var dist = mathPow$2(dx * dx + dy * dy, 0.5);
  51013. return dist > UNSELECT_THRESHOLD;
  51014. }
  51015. function getTrackEnds(track) {
  51016. var tail = track.length - 1;
  51017. tail < 0 && (tail = 0);
  51018. return [track[0], track[tail]];
  51019. }
  51020. function createBaseRectCover(doDrift, controller, brushOption, edgeNames) {
  51021. var cover = new Group();
  51022. cover.add(new Rect({
  51023. name: 'main',
  51024. style: makeStyle(brushOption),
  51025. silent: true,
  51026. draggable: true,
  51027. cursor: 'move',
  51028. drift: curry$2(doDrift, controller, cover, 'nswe'),
  51029. ondragend: curry$2(trigger$1, controller, {isEnd: true})
  51030. }));
  51031. each$12(
  51032. edgeNames,
  51033. function (name) {
  51034. cover.add(new Rect({
  51035. name: name,
  51036. style: {opacity: 0},
  51037. draggable: true,
  51038. silent: true,
  51039. invisible: true,
  51040. drift: curry$2(doDrift, controller, cover, name),
  51041. ondragend: curry$2(trigger$1, controller, {isEnd: true})
  51042. }));
  51043. }
  51044. );
  51045. return cover;
  51046. }
  51047. function updateBaseRect(controller, cover, localRange, brushOption) {
  51048. var lineWidth = brushOption.brushStyle.lineWidth || 0;
  51049. var handleSize = mathMax$6(lineWidth, MIN_RESIZE_LINE_WIDTH);
  51050. var x = localRange[0][0];
  51051. var y = localRange[1][0];
  51052. var xa = x - lineWidth / 2;
  51053. var ya = y - lineWidth / 2;
  51054. var x2 = localRange[0][1];
  51055. var y2 = localRange[1][1];
  51056. var x2a = x2 - handleSize + lineWidth / 2;
  51057. var y2a = y2 - handleSize + lineWidth / 2;
  51058. var width = x2 - x;
  51059. var height = y2 - y;
  51060. var widtha = width + lineWidth;
  51061. var heighta = height + lineWidth;
  51062. updateRectShape(controller, cover, 'main', x, y, width, height);
  51063. if (brushOption.transformable) {
  51064. updateRectShape(controller, cover, 'w', xa, ya, handleSize, heighta);
  51065. updateRectShape(controller, cover, 'e', x2a, ya, handleSize, heighta);
  51066. updateRectShape(controller, cover, 'n', xa, ya, widtha, handleSize);
  51067. updateRectShape(controller, cover, 's', xa, y2a, widtha, handleSize);
  51068. updateRectShape(controller, cover, 'nw', xa, ya, handleSize, handleSize);
  51069. updateRectShape(controller, cover, 'ne', x2a, ya, handleSize, handleSize);
  51070. updateRectShape(controller, cover, 'sw', xa, y2a, handleSize, handleSize);
  51071. updateRectShape(controller, cover, 'se', x2a, y2a, handleSize, handleSize);
  51072. }
  51073. }
  51074. function updateCommon(controller, cover) {
  51075. var brushOption = cover.__brushOption;
  51076. var transformable = brushOption.transformable;
  51077. var mainEl = cover.childAt(0);
  51078. mainEl.useStyle(makeStyle(brushOption));
  51079. mainEl.attr({
  51080. silent: !transformable,
  51081. cursor: transformable ? 'move' : 'default'
  51082. });
  51083. each$12(
  51084. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw'],
  51085. function (name) {
  51086. var el = cover.childOfName(name);
  51087. var globalDir = getGlobalDirection(controller, name);
  51088. el && el.attr({
  51089. silent: !transformable,
  51090. invisible: !transformable,
  51091. cursor: transformable ? CURSOR_MAP[globalDir] + '-resize' : null
  51092. });
  51093. }
  51094. );
  51095. }
  51096. function updateRectShape(controller, cover, name, x, y, w, h) {
  51097. var el = cover.childOfName(name);
  51098. el && el.setShape(pointsToRect(
  51099. clipByPanel(controller, cover, [[x, y], [x + w, y + h]])
  51100. ));
  51101. }
  51102. function makeStyle(brushOption) {
  51103. return defaults({strokeNoScale: true}, brushOption.brushStyle);
  51104. }
  51105. function formatRectRange(x, y, x2, y2) {
  51106. var min = [mathMin$6(x, x2), mathMin$6(y, y2)];
  51107. var max = [mathMax$6(x, x2), mathMax$6(y, y2)];
  51108. return [
  51109. [min[0], max[0]], // x range
  51110. [min[1], max[1]] // y range
  51111. ];
  51112. }
  51113. function getTransform$1(controller) {
  51114. return getTransform(controller.group);
  51115. }
  51116. function getGlobalDirection(controller, localDirection) {
  51117. if (localDirection.length > 1) {
  51118. localDirection = localDirection.split('');
  51119. var globalDir = [
  51120. getGlobalDirection(controller, localDirection[0]),
  51121. getGlobalDirection(controller, localDirection[1])
  51122. ];
  51123. (globalDir[0] === 'e' || globalDir[0] === 'w') && globalDir.reverse();
  51124. return globalDir.join('');
  51125. }
  51126. else {
  51127. var map$$1 = {w: 'left', e: 'right', n: 'top', s: 'bottom'};
  51128. var inverseMap = {left: 'w', right: 'e', top: 'n', bottom: 's'};
  51129. var globalDir = transformDirection(
  51130. map$$1[localDirection], getTransform$1(controller)
  51131. );
  51132. return inverseMap[globalDir];
  51133. }
  51134. }
  51135. function driftRect(toRectRange, fromRectRange, controller, cover, name, dx, dy, e) {
  51136. var brushOption = cover.__brushOption;
  51137. var rectRange = toRectRange(brushOption.range);
  51138. var localDelta = toLocalDelta(controller, dx, dy);
  51139. each$12(name.split(''), function (namePart) {
  51140. var ind = DIRECTION_MAP[namePart];
  51141. rectRange[ind[0]][ind[1]] += localDelta[ind[0]];
  51142. });
  51143. brushOption.range = fromRectRange(formatRectRange(
  51144. rectRange[0][0], rectRange[1][0], rectRange[0][1], rectRange[1][1]
  51145. ));
  51146. updateCoverAfterCreation(controller, cover);
  51147. trigger$1(controller, {isEnd: false});
  51148. }
  51149. function driftPolygon(controller, cover, dx, dy, e) {
  51150. var range = cover.__brushOption.range;
  51151. var localDelta = toLocalDelta(controller, dx, dy);
  51152. each$12(range, function (point) {
  51153. point[0] += localDelta[0];
  51154. point[1] += localDelta[1];
  51155. });
  51156. updateCoverAfterCreation(controller, cover);
  51157. trigger$1(controller, {isEnd: false});
  51158. }
  51159. function toLocalDelta(controller, dx, dy) {
  51160. var thisGroup = controller.group;
  51161. var localD = thisGroup.transformCoordToLocal(dx, dy);
  51162. var localZero = thisGroup.transformCoordToLocal(0, 0);
  51163. return [localD[0] - localZero[0], localD[1] - localZero[1]];
  51164. }
  51165. function clipByPanel(controller, cover, data) {
  51166. var panel = getPanelByCover(controller, cover);
  51167. return (panel && panel !== true)
  51168. ? panel.clipPath(data, controller._transform)
  51169. : clone(data);
  51170. }
  51171. function pointsToRect(points) {
  51172. var xmin = mathMin$6(points[0][0], points[1][0]);
  51173. var ymin = mathMin$6(points[0][1], points[1][1]);
  51174. var xmax = mathMax$6(points[0][0], points[1][0]);
  51175. var ymax = mathMax$6(points[0][1], points[1][1]);
  51176. return {
  51177. x: xmin,
  51178. y: ymin,
  51179. width: xmax - xmin,
  51180. height: ymax - ymin
  51181. };
  51182. }
  51183. function resetCursor(controller, e, localCursorPoint) {
  51184. // Check active
  51185. if (!controller._brushType) {
  51186. return;
  51187. }
  51188. var zr = controller._zr;
  51189. var covers = controller._covers;
  51190. var currPanel = getPanelByPoint(controller, e, localCursorPoint);
  51191. // Check whether in covers.
  51192. if (!controller._dragging) {
  51193. for (var i = 0; i < covers.length; i++) {
  51194. var brushOption = covers[i].__brushOption;
  51195. if (currPanel
  51196. && (currPanel === true || brushOption.panelId === currPanel.panelId)
  51197. && coverRenderers[brushOption.brushType].contain(
  51198. covers[i], localCursorPoint[0], localCursorPoint[1]
  51199. )
  51200. ) {
  51201. // Use cursor style set on cover.
  51202. return;
  51203. }
  51204. }
  51205. }
  51206. currPanel && zr.setCursorStyle('crosshair');
  51207. }
  51208. function preventDefault(e) {
  51209. var rawE = e.event;
  51210. rawE.preventDefault && rawE.preventDefault();
  51211. }
  51212. function mainShapeContain(cover, x, y) {
  51213. return cover.childOfName('main').contain(x, y);
  51214. }
  51215. function updateCoverByMouse(controller, e, localCursorPoint, isEnd) {
  51216. var creatingCover = controller._creatingCover;
  51217. var panel = controller._creatingPanel;
  51218. var thisBrushOption = controller._brushOption;
  51219. var eventParams;
  51220. controller._track.push(localCursorPoint.slice());
  51221. if (shouldShowCover(controller) || creatingCover) {
  51222. if (panel && !creatingCover) {
  51223. thisBrushOption.brushMode === 'single' && clearCovers(controller);
  51224. var brushOption = clone(thisBrushOption);
  51225. brushOption.brushType = determineBrushType(brushOption.brushType, panel);
  51226. brushOption.panelId = panel === true ? null : panel.panelId;
  51227. creatingCover = controller._creatingCover = createCover(controller, brushOption);
  51228. controller._covers.push(creatingCover);
  51229. }
  51230. if (creatingCover) {
  51231. var coverRenderer = coverRenderers[determineBrushType(controller._brushType, panel)];
  51232. var coverBrushOption = creatingCover.__brushOption;
  51233. coverBrushOption.range = coverRenderer.getCreatingRange(
  51234. clipByPanel(controller, creatingCover, controller._track)
  51235. );
  51236. if (isEnd) {
  51237. endCreating(controller, creatingCover);
  51238. coverRenderer.updateCommon(controller, creatingCover);
  51239. }
  51240. updateCoverShape(controller, creatingCover);
  51241. eventParams = {isEnd: isEnd};
  51242. }
  51243. }
  51244. else if (
  51245. isEnd
  51246. && thisBrushOption.brushMode === 'single'
  51247. && thisBrushOption.removeOnClick
  51248. ) {
  51249. // Help user to remove covers easily, only by a tiny drag, in 'single' mode.
  51250. // But a single click do not clear covers, because user may have casual
  51251. // clicks (for example, click on other component and do not expect covers
  51252. // disappear).
  51253. // Only some cover removed, trigger action, but not every click trigger action.
  51254. if (getPanelByPoint(controller, e, localCursorPoint) && clearCovers(controller)) {
  51255. eventParams = {isEnd: isEnd, removeOnClick: true};
  51256. }
  51257. }
  51258. return eventParams;
  51259. }
  51260. function determineBrushType(brushType, panel) {
  51261. if (brushType === 'auto') {
  51262. if (__DEV__) {
  51263. assert$1(
  51264. panel && panel.defaultBrushType,
  51265. 'MUST have defaultBrushType when brushType is "atuo"'
  51266. );
  51267. }
  51268. return panel.defaultBrushType;
  51269. }
  51270. return brushType;
  51271. }
  51272. var mouseHandlers = {
  51273. mousedown: function (e) {
  51274. if (this._dragging) {
  51275. // In case some browser do not support globalOut,
  51276. // and release mose out side the browser.
  51277. handleDragEnd.call(this, e);
  51278. }
  51279. else if (!e.target || !e.target.draggable) {
  51280. preventDefault(e);
  51281. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  51282. this._creatingCover = null;
  51283. var panel = this._creatingPanel = getPanelByPoint(this, e, localCursorPoint);
  51284. if (panel) {
  51285. this._dragging = true;
  51286. this._track = [localCursorPoint.slice()];
  51287. }
  51288. }
  51289. },
  51290. mousemove: function (e) {
  51291. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  51292. resetCursor(this, e, localCursorPoint);
  51293. if (this._dragging) {
  51294. preventDefault(e);
  51295. var eventParams = updateCoverByMouse(this, e, localCursorPoint, false);
  51296. eventParams && trigger$1(this, eventParams);
  51297. }
  51298. },
  51299. mouseup: handleDragEnd //,
  51300. // FIXME
  51301. // in tooltip, globalout should not be triggered.
  51302. // globalout: handleDragEnd
  51303. };
  51304. function handleDragEnd(e) {
  51305. if (this._dragging) {
  51306. preventDefault(e);
  51307. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  51308. var eventParams = updateCoverByMouse(this, e, localCursorPoint, true);
  51309. this._dragging = false;
  51310. this._track = [];
  51311. this._creatingCover = null;
  51312. // trigger event shoule be at final, after procedure will be nested.
  51313. eventParams && trigger$1(this, eventParams);
  51314. }
  51315. }
  51316. /**
  51317. * key: brushType
  51318. * @type {Object}
  51319. */
  51320. var coverRenderers = {
  51321. lineX: getLineRenderer(0),
  51322. lineY: getLineRenderer(1),
  51323. rect: {
  51324. createCover: function (controller, brushOption) {
  51325. return createBaseRectCover(
  51326. curry$2(
  51327. driftRect,
  51328. function (range) {
  51329. return range;
  51330. },
  51331. function (range) {
  51332. return range;
  51333. }
  51334. ),
  51335. controller,
  51336. brushOption,
  51337. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw']
  51338. );
  51339. },
  51340. getCreatingRange: function (localTrack) {
  51341. var ends = getTrackEnds(localTrack);
  51342. return formatRectRange(ends[1][0], ends[1][1], ends[0][0], ends[0][1]);
  51343. },
  51344. updateCoverShape: function (controller, cover, localRange, brushOption) {
  51345. updateBaseRect(controller, cover, localRange, brushOption);
  51346. },
  51347. updateCommon: updateCommon,
  51348. contain: mainShapeContain
  51349. },
  51350. polygon: {
  51351. createCover: function (controller, brushOption) {
  51352. var cover = new Group();
  51353. // Do not use graphic.Polygon because graphic.Polyline do not close the
  51354. // border of the shape when drawing, which is a better experience for user.
  51355. cover.add(new Polyline({
  51356. name: 'main',
  51357. style: makeStyle(brushOption),
  51358. silent: true
  51359. }));
  51360. return cover;
  51361. },
  51362. getCreatingRange: function (localTrack) {
  51363. return localTrack;
  51364. },
  51365. endCreating: function (controller, cover) {
  51366. cover.remove(cover.childAt(0));
  51367. // Use graphic.Polygon close the shape.
  51368. cover.add(new Polygon({
  51369. name: 'main',
  51370. draggable: true,
  51371. drift: curry$2(driftPolygon, controller, cover),
  51372. ondragend: curry$2(trigger$1, controller, {isEnd: true})
  51373. }));
  51374. },
  51375. updateCoverShape: function (controller, cover, localRange, brushOption) {
  51376. cover.childAt(0).setShape({
  51377. points: clipByPanel(controller, cover, localRange)
  51378. });
  51379. },
  51380. updateCommon: updateCommon,
  51381. contain: mainShapeContain
  51382. }
  51383. };
  51384. function getLineRenderer(xyIndex) {
  51385. return {
  51386. createCover: function (controller, brushOption) {
  51387. return createBaseRectCover(
  51388. curry$2(
  51389. driftRect,
  51390. function (range) {
  51391. var rectRange = [range, [0, 100]];
  51392. xyIndex && rectRange.reverse();
  51393. return rectRange;
  51394. },
  51395. function (rectRange) {
  51396. return rectRange[xyIndex];
  51397. }
  51398. ),
  51399. controller,
  51400. brushOption,
  51401. [['w', 'e'], ['n', 's']][xyIndex]
  51402. );
  51403. },
  51404. getCreatingRange: function (localTrack) {
  51405. var ends = getTrackEnds(localTrack);
  51406. var min = mathMin$6(ends[0][xyIndex], ends[1][xyIndex]);
  51407. var max = mathMax$6(ends[0][xyIndex], ends[1][xyIndex]);
  51408. return [min, max];
  51409. },
  51410. updateCoverShape: function (controller, cover, localRange, brushOption) {
  51411. var otherExtent;
  51412. // If brushWidth not specified, fit the panel.
  51413. var panel = getPanelByCover(controller, cover);
  51414. if (panel !== true && panel.getLinearBrushOtherExtent) {
  51415. otherExtent = panel.getLinearBrushOtherExtent(
  51416. xyIndex, controller._transform
  51417. );
  51418. }
  51419. else {
  51420. var zr = controller._zr;
  51421. otherExtent = [0, [zr.getWidth(), zr.getHeight()][1 - xyIndex]];
  51422. }
  51423. var rectRange = [localRange, otherExtent];
  51424. xyIndex && rectRange.reverse();
  51425. updateBaseRect(controller, cover, rectRange, brushOption);
  51426. },
  51427. updateCommon: updateCommon,
  51428. contain: mainShapeContain
  51429. };
  51430. }
  51431. /*
  51432. * Licensed to the Apache Software Foundation (ASF) under one
  51433. * or more contributor license agreements. See the NOTICE file
  51434. * distributed with this work for additional information
  51435. * regarding copyright ownership. The ASF licenses this file
  51436. * to you under the Apache License, Version 2.0 (the
  51437. * "License"); you may not use this file except in compliance
  51438. * with the License. You may obtain a copy of the License at
  51439. *
  51440. * http://www.apache.org/licenses/LICENSE-2.0
  51441. *
  51442. * Unless required by applicable law or agreed to in writing,
  51443. * software distributed under the License is distributed on an
  51444. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51445. * KIND, either express or implied. See the License for the
  51446. * specific language governing permissions and limitations
  51447. * under the License.
  51448. */
  51449. function makeRectPanelClipPath(rect) {
  51450. rect = normalizeRect(rect);
  51451. return function (localPoints, transform) {
  51452. return clipPointsByRect(localPoints, rect);
  51453. };
  51454. }
  51455. function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  51456. rect = normalizeRect(rect);
  51457. return function (xyIndex) {
  51458. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  51459. var brushWidth = idx ? rect.width : rect.height;
  51460. var base = idx ? rect.x : rect.y;
  51461. return [base, base + (brushWidth || 0)];
  51462. };
  51463. }
  51464. function makeRectIsTargetByCursor(rect, api, targetModel) {
  51465. rect = normalizeRect(rect);
  51466. return function (e, localCursorPoint, transform) {
  51467. return rect.contain(localCursorPoint[0], localCursorPoint[1])
  51468. && !onIrrelevantElement(e, api, targetModel);
  51469. };
  51470. }
  51471. // Consider width/height is negative.
  51472. function normalizeRect(rect) {
  51473. return BoundingRect.create(rect);
  51474. }
  51475. /*
  51476. * Licensed to the Apache Software Foundation (ASF) under one
  51477. * or more contributor license agreements. See the NOTICE file
  51478. * distributed with this work for additional information
  51479. * regarding copyright ownership. The ASF licenses this file
  51480. * to you under the Apache License, Version 2.0 (the
  51481. * "License"); you may not use this file except in compliance
  51482. * with the License. You may obtain a copy of the License at
  51483. *
  51484. * http://www.apache.org/licenses/LICENSE-2.0
  51485. *
  51486. * Unless required by applicable law or agreed to in writing,
  51487. * software distributed under the License is distributed on an
  51488. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51489. * KIND, either express or implied. See the License for the
  51490. * specific language governing permissions and limitations
  51491. * under the License.
  51492. */
  51493. var elementList = ['axisLine', 'axisTickLabel', 'axisName'];
  51494. var AxisView$2 = extendComponentView({
  51495. type: 'parallelAxis',
  51496. /**
  51497. * @override
  51498. */
  51499. init: function (ecModel, api) {
  51500. AxisView$2.superApply(this, 'init', arguments);
  51501. /**
  51502. * @type {module:echarts/component/helper/BrushController}
  51503. */
  51504. (this._brushController = new BrushController(api.getZr()))
  51505. .on('brush', bind(this._onBrush, this));
  51506. },
  51507. /**
  51508. * @override
  51509. */
  51510. render: function (axisModel, ecModel, api, payload) {
  51511. if (fromAxisAreaSelect(axisModel, ecModel, payload)) {
  51512. return;
  51513. }
  51514. this.axisModel = axisModel;
  51515. this.api = api;
  51516. this.group.removeAll();
  51517. var oldAxisGroup = this._axisGroup;
  51518. this._axisGroup = new Group();
  51519. this.group.add(this._axisGroup);
  51520. if (!axisModel.get('show')) {
  51521. return;
  51522. }
  51523. var coordSysModel = getCoordSysModel(axisModel, ecModel);
  51524. var coordSys = coordSysModel.coordinateSystem;
  51525. var areaSelectStyle = axisModel.getAreaSelectStyle();
  51526. var areaWidth = areaSelectStyle.width;
  51527. var dim = axisModel.axis.dim;
  51528. var axisLayout = coordSys.getAxisLayout(dim);
  51529. var builderOpt = extend(
  51530. {strokeContainThreshold: areaWidth},
  51531. axisLayout
  51532. );
  51533. var axisBuilder = new AxisBuilder(axisModel, builderOpt);
  51534. each$1(elementList, axisBuilder.add, axisBuilder);
  51535. this._axisGroup.add(axisBuilder.getGroup());
  51536. this._refreshBrushController(
  51537. builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api
  51538. );
  51539. var animationModel = (payload && payload.animation === false) ? null : axisModel;
  51540. groupTransition(oldAxisGroup, this._axisGroup, animationModel);
  51541. },
  51542. // /**
  51543. // * @override
  51544. // */
  51545. // updateVisual: function (axisModel, ecModel, api, payload) {
  51546. // this._brushController && this._brushController
  51547. // .updateCovers(getCoverInfoList(axisModel));
  51548. // },
  51549. _refreshBrushController: function (
  51550. builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api
  51551. ) {
  51552. // After filtering, axis may change, select area needs to be update.
  51553. var extent = axisModel.axis.getExtent();
  51554. var extentLen = extent[1] - extent[0];
  51555. var extra = Math.min(30, Math.abs(extentLen) * 0.1); // Arbitrary value.
  51556. // width/height might be negative, which will be
  51557. // normalized in BoundingRect.
  51558. var rect = BoundingRect.create({
  51559. x: extent[0],
  51560. y: -areaWidth / 2,
  51561. width: extentLen,
  51562. height: areaWidth
  51563. });
  51564. rect.x -= extra;
  51565. rect.width += 2 * extra;
  51566. this._brushController
  51567. .mount({
  51568. enableGlobalPan: true,
  51569. rotation: builderOpt.rotation,
  51570. position: builderOpt.position
  51571. })
  51572. .setPanels([{
  51573. panelId: 'pl',
  51574. clipPath: makeRectPanelClipPath(rect),
  51575. isTargetByCursor: makeRectIsTargetByCursor(rect, api, coordSysModel),
  51576. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect, 0)
  51577. }])
  51578. .enableBrush({
  51579. brushType: 'lineX',
  51580. brushStyle: areaSelectStyle,
  51581. removeOnClick: true
  51582. })
  51583. .updateCovers(getCoverInfoList(axisModel));
  51584. },
  51585. _onBrush: function (coverInfoList, opt) {
  51586. // Do not cache these object, because the mey be changed.
  51587. var axisModel = this.axisModel;
  51588. var axis = axisModel.axis;
  51589. var intervals = map(coverInfoList, function (coverInfo) {
  51590. return [
  51591. axis.coordToData(coverInfo.range[0], true),
  51592. axis.coordToData(coverInfo.range[1], true)
  51593. ];
  51594. });
  51595. // If realtime is true, action is not dispatched on drag end, because
  51596. // the drag end emits the same params with the last drag move event,
  51597. // and may have some delay when using touch pad.
  51598. if (!axisModel.option.realtime === opt.isEnd || opt.removeOnClick) { // jshint ignore:line
  51599. this.api.dispatchAction({
  51600. type: 'axisAreaSelect',
  51601. parallelAxisId: axisModel.id,
  51602. intervals: intervals
  51603. });
  51604. }
  51605. },
  51606. /**
  51607. * @override
  51608. */
  51609. dispose: function () {
  51610. this._brushController.dispose();
  51611. }
  51612. });
  51613. function fromAxisAreaSelect(axisModel, ecModel, payload) {
  51614. return payload
  51615. && payload.type === 'axisAreaSelect'
  51616. && ecModel.findComponents(
  51617. {mainType: 'parallelAxis', query: payload}
  51618. )[0] === axisModel;
  51619. }
  51620. function getCoverInfoList(axisModel) {
  51621. var axis = axisModel.axis;
  51622. return map(axisModel.activeIntervals, function (interval) {
  51623. return {
  51624. brushType: 'lineX',
  51625. panelId: 'pl',
  51626. range: [
  51627. axis.dataToCoord(interval[0], true),
  51628. axis.dataToCoord(interval[1], true)
  51629. ]
  51630. };
  51631. });
  51632. }
  51633. function getCoordSysModel(axisModel, ecModel) {
  51634. return ecModel.getComponent(
  51635. 'parallel', axisModel.get('parallelIndex')
  51636. );
  51637. }
  51638. /*
  51639. * Licensed to the Apache Software Foundation (ASF) under one
  51640. * or more contributor license agreements. See the NOTICE file
  51641. * distributed with this work for additional information
  51642. * regarding copyright ownership. The ASF licenses this file
  51643. * to you under the Apache License, Version 2.0 (the
  51644. * "License"); you may not use this file except in compliance
  51645. * with the License. You may obtain a copy of the License at
  51646. *
  51647. * http://www.apache.org/licenses/LICENSE-2.0
  51648. *
  51649. * Unless required by applicable law or agreed to in writing,
  51650. * software distributed under the License is distributed on an
  51651. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51652. * KIND, either express or implied. See the License for the
  51653. * specific language governing permissions and limitations
  51654. * under the License.
  51655. */
  51656. /*
  51657. * Licensed to the Apache Software Foundation (ASF) under one
  51658. * or more contributor license agreements. See the NOTICE file
  51659. * distributed with this work for additional information
  51660. * regarding copyright ownership. The ASF licenses this file
  51661. * to you under the Apache License, Version 2.0 (the
  51662. * "License"); you may not use this file except in compliance
  51663. * with the License. You may obtain a copy of the License at
  51664. *
  51665. * http://www.apache.org/licenses/LICENSE-2.0
  51666. *
  51667. * Unless required by applicable law or agreed to in writing,
  51668. * software distributed under the License is distributed on an
  51669. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51670. * KIND, either express or implied. See the License for the
  51671. * specific language governing permissions and limitations
  51672. * under the License.
  51673. */
  51674. var CLICK_THRESHOLD = 5; // > 4
  51675. // Parallel view
  51676. extendComponentView({
  51677. type: 'parallel',
  51678. render: function (parallelModel, ecModel, api) {
  51679. this._model = parallelModel;
  51680. this._api = api;
  51681. if (!this._handlers) {
  51682. this._handlers = {};
  51683. each$1(handlers, function (handler, eventName) {
  51684. api.getZr().on(eventName, this._handlers[eventName] = bind(handler, this));
  51685. }, this);
  51686. }
  51687. createOrUpdate(
  51688. this,
  51689. '_throttledDispatchExpand',
  51690. parallelModel.get('axisExpandRate'),
  51691. 'fixRate'
  51692. );
  51693. },
  51694. dispose: function (ecModel, api) {
  51695. each$1(this._handlers, function (handler, eventName) {
  51696. api.getZr().off(eventName, handler);
  51697. });
  51698. this._handlers = null;
  51699. },
  51700. /**
  51701. * @param {Object} [opt] If null, cancle the last action triggering for debounce.
  51702. */
  51703. _throttledDispatchExpand: function (opt) {
  51704. this._dispatchExpand(opt);
  51705. },
  51706. _dispatchExpand: function (opt) {
  51707. opt && this._api.dispatchAction(
  51708. extend({type: 'parallelAxisExpand'}, opt)
  51709. );
  51710. }
  51711. });
  51712. var handlers = {
  51713. mousedown: function (e) {
  51714. if (checkTrigger(this, 'click')) {
  51715. this._mouseDownPoint = [e.offsetX, e.offsetY];
  51716. }
  51717. },
  51718. mouseup: function (e) {
  51719. var mouseDownPoint = this._mouseDownPoint;
  51720. if (checkTrigger(this, 'click') && mouseDownPoint) {
  51721. var point = [e.offsetX, e.offsetY];
  51722. var dist = Math.pow(mouseDownPoint[0] - point[0], 2)
  51723. + Math.pow(mouseDownPoint[1] - point[1], 2);
  51724. if (dist > CLICK_THRESHOLD) {
  51725. return;
  51726. }
  51727. var result = this._model.coordinateSystem.getSlidedAxisExpandWindow(
  51728. [e.offsetX, e.offsetY]
  51729. );
  51730. result.behavior !== 'none' && this._dispatchExpand({
  51731. axisExpandWindow: result.axisExpandWindow
  51732. });
  51733. }
  51734. this._mouseDownPoint = null;
  51735. },
  51736. mousemove: function (e) {
  51737. // Should do nothing when brushing.
  51738. if (this._mouseDownPoint || !checkTrigger(this, 'mousemove')) {
  51739. return;
  51740. }
  51741. var model = this._model;
  51742. var result = model.coordinateSystem.getSlidedAxisExpandWindow(
  51743. [e.offsetX, e.offsetY]
  51744. );
  51745. var behavior = result.behavior;
  51746. behavior === 'jump' && this._throttledDispatchExpand.debounceNextCall(model.get('axisExpandDebounce'));
  51747. this._throttledDispatchExpand(
  51748. behavior === 'none'
  51749. ? null // Cancle the last trigger, in case that mouse slide out of the area quickly.
  51750. : {
  51751. axisExpandWindow: result.axisExpandWindow,
  51752. // Jumping uses animation, and sliding suppresses animation.
  51753. animation: behavior === 'jump' ? null : false
  51754. }
  51755. );
  51756. }
  51757. };
  51758. function checkTrigger(view, triggerOn) {
  51759. var model = view._model;
  51760. return model.get('axisExpandable') && model.get('axisExpandTriggerOn') === triggerOn;
  51761. }
  51762. registerPreprocessor(parallelPreprocessor);
  51763. /*
  51764. * Licensed to the Apache Software Foundation (ASF) under one
  51765. * or more contributor license agreements. See the NOTICE file
  51766. * distributed with this work for additional information
  51767. * regarding copyright ownership. The ASF licenses this file
  51768. * to you under the Apache License, Version 2.0 (the
  51769. * "License"); you may not use this file except in compliance
  51770. * with the License. You may obtain a copy of the License at
  51771. *
  51772. * http://www.apache.org/licenses/LICENSE-2.0
  51773. *
  51774. * Unless required by applicable law or agreed to in writing,
  51775. * software distributed under the License is distributed on an
  51776. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51777. * KIND, either express or implied. See the License for the
  51778. * specific language governing permissions and limitations
  51779. * under the License.
  51780. */
  51781. SeriesModel.extend({
  51782. type: 'series.parallel',
  51783. dependencies: ['parallel'],
  51784. visualColorAccessPath: 'lineStyle.color',
  51785. getInitialData: function (option, ecModel) {
  51786. var source = this.getSource();
  51787. setEncodeAndDimensions(source, this);
  51788. return createListFromArray(source, this);
  51789. },
  51790. /**
  51791. * User can get data raw indices on 'axisAreaSelected' event received.
  51792. *
  51793. * @public
  51794. * @param {string} activeState 'active' or 'inactive' or 'normal'
  51795. * @return {Array.<number>} Raw indices
  51796. */
  51797. getRawIndicesByActiveState: function (activeState) {
  51798. var coordSys = this.coordinateSystem;
  51799. var data = this.getData();
  51800. var indices = [];
  51801. coordSys.eachActiveState(data, function (theActiveState, dataIndex) {
  51802. if (activeState === theActiveState) {
  51803. indices.push(data.getRawIndex(dataIndex));
  51804. }
  51805. });
  51806. return indices;
  51807. },
  51808. defaultOption: {
  51809. zlevel: 0, // 一级层叠
  51810. z: 2, // 二级层叠
  51811. coordinateSystem: 'parallel',
  51812. parallelIndex: 0,
  51813. label: {
  51814. show: false
  51815. },
  51816. inactiveOpacity: 0.05,
  51817. activeOpacity: 1,
  51818. lineStyle: {
  51819. width: 1,
  51820. opacity: 0.45,
  51821. type: 'solid'
  51822. },
  51823. emphasis: {
  51824. label: {
  51825. show: false
  51826. }
  51827. },
  51828. progressive: 500,
  51829. smooth: false, // true | false | number
  51830. animationEasing: 'linear'
  51831. }
  51832. });
  51833. function setEncodeAndDimensions(source, seriesModel) {
  51834. // The mapping of parallelAxis dimension to data dimension can
  51835. // be specified in parallelAxis.option.dim. For example, if
  51836. // parallelAxis.option.dim is 'dim3', it mapping to the third
  51837. // dimension of data. But `data.encode` has higher priority.
  51838. // Moreover, parallelModel.dimension should not be regarded as data
  51839. // dimensions. Consider dimensions = ['dim4', 'dim2', 'dim6'];
  51840. if (source.encodeDefine) {
  51841. return;
  51842. }
  51843. var parallelModel = seriesModel.ecModel.getComponent(
  51844. 'parallel', seriesModel.get('parallelIndex')
  51845. );
  51846. if (!parallelModel) {
  51847. return;
  51848. }
  51849. var encodeDefine = source.encodeDefine = createHashMap();
  51850. each$1(parallelModel.dimensions, function (axisDim) {
  51851. var dataDimIndex = convertDimNameToNumber(axisDim);
  51852. encodeDefine.set(axisDim, dataDimIndex);
  51853. });
  51854. }
  51855. function convertDimNameToNumber(dimName) {
  51856. return +dimName.replace('dim', '');
  51857. }
  51858. /*
  51859. * Licensed to the Apache Software Foundation (ASF) under one
  51860. * or more contributor license agreements. See the NOTICE file
  51861. * distributed with this work for additional information
  51862. * regarding copyright ownership. The ASF licenses this file
  51863. * to you under the Apache License, Version 2.0 (the
  51864. * "License"); you may not use this file except in compliance
  51865. * with the License. You may obtain a copy of the License at
  51866. *
  51867. * http://www.apache.org/licenses/LICENSE-2.0
  51868. *
  51869. * Unless required by applicable law or agreed to in writing,
  51870. * software distributed under the License is distributed on an
  51871. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51872. * KIND, either express or implied. See the License for the
  51873. * specific language governing permissions and limitations
  51874. * under the License.
  51875. */
  51876. var DEFAULT_SMOOTH = 0.3;
  51877. var ParallelView = Chart.extend({
  51878. type: 'parallel',
  51879. init: function () {
  51880. /**
  51881. * @type {module:zrender/container/Group}
  51882. * @private
  51883. */
  51884. this._dataGroup = new Group();
  51885. this.group.add(this._dataGroup);
  51886. /**
  51887. * @type {module:echarts/data/List}
  51888. */
  51889. this._data;
  51890. /**
  51891. * @type {boolean}
  51892. */
  51893. this._initialized;
  51894. },
  51895. /**
  51896. * @override
  51897. */
  51898. render: function (seriesModel, ecModel, api, payload) {
  51899. var dataGroup = this._dataGroup;
  51900. var data = seriesModel.getData();
  51901. var oldData = this._data;
  51902. var coordSys = seriesModel.coordinateSystem;
  51903. var dimensions = coordSys.dimensions;
  51904. var seriesScope = makeSeriesScope$2(seriesModel);
  51905. data.diff(oldData)
  51906. .add(add)
  51907. .update(update)
  51908. .remove(remove)
  51909. .execute();
  51910. function add(newDataIndex) {
  51911. var line = addEl(data, dataGroup, newDataIndex, dimensions, coordSys);
  51912. updateElCommon(line, data, newDataIndex, seriesScope);
  51913. }
  51914. function update(newDataIndex, oldDataIndex) {
  51915. var line = oldData.getItemGraphicEl(oldDataIndex);
  51916. var points = createLinePoints(data, newDataIndex, dimensions, coordSys);
  51917. data.setItemGraphicEl(newDataIndex, line);
  51918. var animationModel = (payload && payload.animation === false) ? null : seriesModel;
  51919. updateProps(line, {shape: {points: points}}, animationModel, newDataIndex);
  51920. updateElCommon(line, data, newDataIndex, seriesScope);
  51921. }
  51922. function remove(oldDataIndex) {
  51923. var line = oldData.getItemGraphicEl(oldDataIndex);
  51924. dataGroup.remove(line);
  51925. }
  51926. // First create
  51927. if (!this._initialized) {
  51928. this._initialized = true;
  51929. var clipPath = createGridClipShape$1(
  51930. coordSys, seriesModel, function () {
  51931. // Callback will be invoked immediately if there is no animation
  51932. setTimeout(function () {
  51933. dataGroup.removeClipPath();
  51934. });
  51935. }
  51936. );
  51937. dataGroup.setClipPath(clipPath);
  51938. }
  51939. this._data = data;
  51940. },
  51941. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  51942. this._initialized = true;
  51943. this._data = null;
  51944. this._dataGroup.removeAll();
  51945. },
  51946. incrementalRender: function (taskParams, seriesModel, ecModel) {
  51947. var data = seriesModel.getData();
  51948. var coordSys = seriesModel.coordinateSystem;
  51949. var dimensions = coordSys.dimensions;
  51950. var seriesScope = makeSeriesScope$2(seriesModel);
  51951. for (var dataIndex = taskParams.start; dataIndex < taskParams.end; dataIndex++) {
  51952. var line = addEl(data, this._dataGroup, dataIndex, dimensions, coordSys);
  51953. line.incremental = true;
  51954. updateElCommon(line, data, dataIndex, seriesScope);
  51955. }
  51956. },
  51957. dispose: function () {},
  51958. // _renderForProgressive: function (seriesModel) {
  51959. // var dataGroup = this._dataGroup;
  51960. // var data = seriesModel.getData();
  51961. // var oldData = this._data;
  51962. // var coordSys = seriesModel.coordinateSystem;
  51963. // var dimensions = coordSys.dimensions;
  51964. // var option = seriesModel.option;
  51965. // var progressive = option.progressive;
  51966. // var smooth = option.smooth ? SMOOTH : null;
  51967. // // In progressive animation is disabled, so use simple data diff,
  51968. // // which effects performance less.
  51969. // // (Typically performance for data with length 7000+ like:
  51970. // // simpleDiff: 60ms, addEl: 184ms,
  51971. // // in RMBP 2.4GHz intel i7, OSX 10.9 chrome 50.0.2661.102 (64-bit))
  51972. // if (simpleDiff(oldData, data, dimensions)) {
  51973. // dataGroup.removeAll();
  51974. // data.each(function (dataIndex) {
  51975. // addEl(data, dataGroup, dataIndex, dimensions, coordSys);
  51976. // });
  51977. // }
  51978. // updateElCommon(data, progressive, smooth);
  51979. // // Consider switch between progressive and not.
  51980. // data.__plProgressive = true;
  51981. // this._data = data;
  51982. // },
  51983. /**
  51984. * @override
  51985. */
  51986. remove: function () {
  51987. this._dataGroup && this._dataGroup.removeAll();
  51988. this._data = null;
  51989. }
  51990. });
  51991. function createGridClipShape$1(coordSys, seriesModel, cb) {
  51992. var parallelModel = coordSys.model;
  51993. var rect = coordSys.getRect();
  51994. var rectEl = new Rect({
  51995. shape: {
  51996. x: rect.x,
  51997. y: rect.y,
  51998. width: rect.width,
  51999. height: rect.height
  52000. }
  52001. });
  52002. var dim = parallelModel.get('layout') === 'horizontal' ? 'width' : 'height';
  52003. rectEl.setShape(dim, 0);
  52004. initProps(rectEl, {
  52005. shape: {
  52006. width: rect.width,
  52007. height: rect.height
  52008. }
  52009. }, seriesModel, cb);
  52010. return rectEl;
  52011. }
  52012. function createLinePoints(data, dataIndex, dimensions, coordSys) {
  52013. var points = [];
  52014. for (var i = 0; i < dimensions.length; i++) {
  52015. var dimName = dimensions[i];
  52016. var value = data.get(data.mapDimension(dimName), dataIndex);
  52017. if (!isEmptyValue(value, coordSys.getAxis(dimName).type)) {
  52018. points.push(coordSys.dataToPoint(value, dimName));
  52019. }
  52020. }
  52021. return points;
  52022. }
  52023. function addEl(data, dataGroup, dataIndex, dimensions, coordSys) {
  52024. var points = createLinePoints(data, dataIndex, dimensions, coordSys);
  52025. var line = new Polyline({
  52026. shape: {points: points},
  52027. silent: true,
  52028. z2: 10
  52029. });
  52030. dataGroup.add(line);
  52031. data.setItemGraphicEl(dataIndex, line);
  52032. return line;
  52033. }
  52034. function makeSeriesScope$2(seriesModel) {
  52035. var smooth = seriesModel.get('smooth', true);
  52036. smooth === true && (smooth = DEFAULT_SMOOTH);
  52037. return {
  52038. lineStyle: seriesModel.getModel('lineStyle').getLineStyle(),
  52039. smooth: smooth != null ? smooth : DEFAULT_SMOOTH
  52040. };
  52041. }
  52042. function updateElCommon(el, data, dataIndex, seriesScope) {
  52043. var lineStyle = seriesScope.lineStyle;
  52044. if (data.hasItemOption) {
  52045. var lineStyleModel = data.getItemModel(dataIndex).getModel('lineStyle');
  52046. lineStyle = lineStyleModel.getLineStyle();
  52047. }
  52048. el.useStyle(lineStyle);
  52049. var elStyle = el.style;
  52050. elStyle.fill = null;
  52051. // lineStyle.color have been set to itemVisual in module:echarts/visual/seriesColor.
  52052. elStyle.stroke = data.getItemVisual(dataIndex, 'color');
  52053. // lineStyle.opacity have been set to itemVisual in parallelVisual.
  52054. elStyle.opacity = data.getItemVisual(dataIndex, 'opacity');
  52055. seriesScope.smooth && (el.shape.smooth = seriesScope.smooth);
  52056. }
  52057. // function simpleDiff(oldData, newData, dimensions) {
  52058. // var oldLen;
  52059. // if (!oldData
  52060. // || !oldData.__plProgressive
  52061. // || (oldLen = oldData.count()) !== newData.count()
  52062. // ) {
  52063. // return true;
  52064. // }
  52065. // var dimLen = dimensions.length;
  52066. // for (var i = 0; i < oldLen; i++) {
  52067. // for (var j = 0; j < dimLen; j++) {
  52068. // if (oldData.get(dimensions[j], i) !== newData.get(dimensions[j], i)) {
  52069. // return true;
  52070. // }
  52071. // }
  52072. // }
  52073. // return false;
  52074. // }
  52075. // FIXME
  52076. // 公用方法?
  52077. function isEmptyValue(val, axisType) {
  52078. return axisType === 'category'
  52079. ? val == null
  52080. : (val == null || isNaN(val)); // axisType === 'value'
  52081. }
  52082. /*
  52083. * Licensed to the Apache Software Foundation (ASF) under one
  52084. * or more contributor license agreements. See the NOTICE file
  52085. * distributed with this work for additional information
  52086. * regarding copyright ownership. The ASF licenses this file
  52087. * to you under the Apache License, Version 2.0 (the
  52088. * "License"); you may not use this file except in compliance
  52089. * with the License. You may obtain a copy of the License at
  52090. *
  52091. * http://www.apache.org/licenses/LICENSE-2.0
  52092. *
  52093. * Unless required by applicable law or agreed to in writing,
  52094. * software distributed under the License is distributed on an
  52095. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52096. * KIND, either express or implied. See the License for the
  52097. * specific language governing permissions and limitations
  52098. * under the License.
  52099. */
  52100. var opacityAccessPath$1 = ['lineStyle', 'normal', 'opacity'];
  52101. var parallelVisual = {
  52102. seriesType: 'parallel',
  52103. reset: function (seriesModel, ecModel, api) {
  52104. var itemStyleModel = seriesModel.getModel('itemStyle');
  52105. var lineStyleModel = seriesModel.getModel('lineStyle');
  52106. var globalColors = ecModel.get('color');
  52107. var color = lineStyleModel.get('color')
  52108. || itemStyleModel.get('color')
  52109. || globalColors[seriesModel.seriesIndex % globalColors.length];
  52110. var inactiveOpacity = seriesModel.get('inactiveOpacity');
  52111. var activeOpacity = seriesModel.get('activeOpacity');
  52112. var lineStyle = seriesModel.getModel('lineStyle').getLineStyle();
  52113. var coordSys = seriesModel.coordinateSystem;
  52114. var data = seriesModel.getData();
  52115. var opacityMap = {
  52116. normal: lineStyle.opacity,
  52117. active: activeOpacity,
  52118. inactive: inactiveOpacity
  52119. };
  52120. data.setVisual('color', color);
  52121. function progress(params, data) {
  52122. coordSys.eachActiveState(data, function (activeState, dataIndex) {
  52123. var opacity = opacityMap[activeState];
  52124. if (activeState === 'normal' && data.hasItemOption) {
  52125. var itemOpacity = data.getItemModel(dataIndex).get(opacityAccessPath$1, true);
  52126. itemOpacity != null && (opacity = itemOpacity);
  52127. }
  52128. data.setItemVisual(dataIndex, 'opacity', opacity);
  52129. }, params.start, params.end);
  52130. }
  52131. return {progress: progress};
  52132. }
  52133. };
  52134. /*
  52135. * Licensed to the Apache Software Foundation (ASF) under one
  52136. * or more contributor license agreements. See the NOTICE file
  52137. * distributed with this work for additional information
  52138. * regarding copyright ownership. The ASF licenses this file
  52139. * to you under the Apache License, Version 2.0 (the
  52140. * "License"); you may not use this file except in compliance
  52141. * with the License. You may obtain a copy of the License at
  52142. *
  52143. * http://www.apache.org/licenses/LICENSE-2.0
  52144. *
  52145. * Unless required by applicable law or agreed to in writing,
  52146. * software distributed under the License is distributed on an
  52147. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52148. * KIND, either express or implied. See the License for the
  52149. * specific language governing permissions and limitations
  52150. * under the License.
  52151. */
  52152. registerVisual(parallelVisual);
  52153. /*
  52154. * Licensed to the Apache Software Foundation (ASF) under one
  52155. * or more contributor license agreements. See the NOTICE file
  52156. * distributed with this work for additional information
  52157. * regarding copyright ownership. The ASF licenses this file
  52158. * to you under the Apache License, Version 2.0 (the
  52159. * "License"); you may not use this file except in compliance
  52160. * with the License. You may obtain a copy of the License at
  52161. *
  52162. * http://www.apache.org/licenses/LICENSE-2.0
  52163. *
  52164. * Unless required by applicable law or agreed to in writing,
  52165. * software distributed under the License is distributed on an
  52166. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52167. * KIND, either express or implied. See the License for the
  52168. * specific language governing permissions and limitations
  52169. * under the License.
  52170. */
  52171. /**
  52172. * @file Get initial data and define sankey view's series model
  52173. * @author Deqing Li(annong035@gmail.com)
  52174. */
  52175. var SankeySeries = SeriesModel.extend({
  52176. type: 'series.sankey',
  52177. layoutInfo: null,
  52178. /**
  52179. * Init a graph data structure from data in option series
  52180. *
  52181. * @param {Object} option the object used to config echarts view
  52182. * @return {module:echarts/data/List} storage initial data
  52183. */
  52184. getInitialData: function (option) {
  52185. var links = option.edges || option.links;
  52186. var nodes = option.data || option.nodes;
  52187. if (nodes && links) {
  52188. var graph = createGraphFromNodeEdge(nodes, links, this, true);
  52189. return graph.data;
  52190. }
  52191. },
  52192. setNodePosition: function (dataIndex, localPosition) {
  52193. var dataItem = this.option.data[dataIndex];
  52194. dataItem.localX = localPosition[0];
  52195. dataItem.localY = localPosition[1];
  52196. },
  52197. /**
  52198. * Return the graphic data structure
  52199. *
  52200. * @return {module:echarts/data/Graph} graphic data structure
  52201. */
  52202. getGraph: function () {
  52203. return this.getData().graph;
  52204. },
  52205. /**
  52206. * Get edge data of graphic data structure
  52207. *
  52208. * @return {module:echarts/data/List} data structure of list
  52209. */
  52210. getEdgeData: function () {
  52211. return this.getGraph().edgeData;
  52212. },
  52213. /**
  52214. * @override
  52215. */
  52216. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  52217. // dataType === 'node' or empty do not show tooltip by default
  52218. if (dataType === 'edge') {
  52219. var params = this.getDataParams(dataIndex, dataType);
  52220. var rawDataOpt = params.data;
  52221. var html = rawDataOpt.source + ' -- ' + rawDataOpt.target;
  52222. if (params.value) {
  52223. html += ' : ' + params.value;
  52224. }
  52225. return encodeHTML(html);
  52226. }
  52227. return SankeySeries.superCall(this, 'formatTooltip', dataIndex, multipleSeries);
  52228. },
  52229. optionUpdated: function () {
  52230. var option = this.option;
  52231. if (option.focusNodeAdjacency === true) {
  52232. option.focusNodeAdjacency = 'allEdges';
  52233. }
  52234. },
  52235. defaultOption: {
  52236. zlevel: 0,
  52237. z: 2,
  52238. coordinateSystem: 'view',
  52239. layout: null,
  52240. // The position of the whole view
  52241. left: '5%',
  52242. top: '5%',
  52243. right: '20%',
  52244. bottom: '5%',
  52245. // Value can be 'vertical'
  52246. orient: 'horizontal',
  52247. // The dx of the node
  52248. nodeWidth: 20,
  52249. // The vertical distance between two nodes
  52250. nodeGap: 8,
  52251. // Control if the node can move or not
  52252. draggable: true,
  52253. // Value can be 'inEdges', 'outEdges', 'allEdges', true (the same as 'allEdges').
  52254. focusNodeAdjacency: false,
  52255. // The number of iterations to change the position of the node
  52256. layoutIterations: 32,
  52257. label: {
  52258. show: true,
  52259. position: 'right',
  52260. color: '#000',
  52261. fontSize: 12
  52262. },
  52263. itemStyle: {
  52264. borderWidth: 1,
  52265. borderColor: '#333'
  52266. },
  52267. lineStyle: {
  52268. color: '#314656',
  52269. opacity: 0.2,
  52270. curveness: 0.5
  52271. },
  52272. emphasis: {
  52273. label: {
  52274. show: true
  52275. },
  52276. lineStyle: {
  52277. opacity: 0.6
  52278. }
  52279. },
  52280. animationEasing: 'linear',
  52281. animationDuration: 1000
  52282. }
  52283. });
  52284. /*
  52285. * Licensed to the Apache Software Foundation (ASF) under one
  52286. * or more contributor license agreements. See the NOTICE file
  52287. * distributed with this work for additional information
  52288. * regarding copyright ownership. The ASF licenses this file
  52289. * to you under the Apache License, Version 2.0 (the
  52290. * "License"); you may not use this file except in compliance
  52291. * with the License. You may obtain a copy of the License at
  52292. *
  52293. * http://www.apache.org/licenses/LICENSE-2.0
  52294. *
  52295. * Unless required by applicable law or agreed to in writing,
  52296. * software distributed under the License is distributed on an
  52297. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52298. * KIND, either express or implied. See the License for the
  52299. * specific language governing permissions and limitations
  52300. * under the License.
  52301. */
  52302. /**
  52303. * @file The file used to draw sankey view
  52304. * @author Deqing Li(annong035@gmail.com)
  52305. */
  52306. var nodeOpacityPath$1 = ['itemStyle', 'opacity'];
  52307. var lineOpacityPath$1 = ['lineStyle', 'opacity'];
  52308. function getItemOpacity$1(item, opacityPath) {
  52309. return item.getVisual('opacity') || item.getModel().get(opacityPath);
  52310. }
  52311. function fadeOutItem$1(item, opacityPath, opacityRatio) {
  52312. var el = item.getGraphicEl();
  52313. var opacity = getItemOpacity$1(item, opacityPath);
  52314. if (opacityRatio != null) {
  52315. opacity == null && (opacity = 1);
  52316. opacity *= opacityRatio;
  52317. }
  52318. el.downplay && el.downplay();
  52319. el.traverse(function (child) {
  52320. if (child.type !== 'group') {
  52321. child.setStyle('opacity', opacity);
  52322. }
  52323. });
  52324. }
  52325. function fadeInItem$1(item, opacityPath) {
  52326. var opacity = getItemOpacity$1(item, opacityPath);
  52327. var el = item.getGraphicEl();
  52328. el.highlight && el.highlight();
  52329. el.traverse(function (child) {
  52330. if (child.type !== 'group') {
  52331. child.setStyle('opacity', opacity);
  52332. }
  52333. });
  52334. }
  52335. var SankeyShape = extendShape({
  52336. shape: {
  52337. x1: 0, y1: 0,
  52338. x2: 0, y2: 0,
  52339. cpx1: 0, cpy1: 0,
  52340. cpx2: 0, cpy2: 0,
  52341. extent: 0,
  52342. orient: ''
  52343. },
  52344. buildPath: function (ctx, shape) {
  52345. var extent = shape.extent;
  52346. var orient = shape.orient;
  52347. if (orient === 'vertical') {
  52348. ctx.moveTo(shape.x1, shape.y1);
  52349. ctx.bezierCurveTo(
  52350. shape.cpx1, shape.cpy1,
  52351. shape.cpx2, shape.cpy2,
  52352. shape.x2, shape.y2
  52353. );
  52354. ctx.lineTo(shape.x2 + extent, shape.y2);
  52355. ctx.bezierCurveTo(
  52356. shape.cpx2 + extent, shape.cpy2,
  52357. shape.cpx1 + extent, shape.cpy1,
  52358. shape.x1 + extent, shape.y1
  52359. );
  52360. }
  52361. else {
  52362. ctx.moveTo(shape.x1, shape.y1);
  52363. ctx.bezierCurveTo(
  52364. shape.cpx1, shape.cpy1,
  52365. shape.cpx2, shape.cpy2,
  52366. shape.x2, shape.y2
  52367. );
  52368. ctx.lineTo(shape.x2, shape.y2 + extent);
  52369. ctx.bezierCurveTo(
  52370. shape.cpx2, shape.cpy2 + extent,
  52371. shape.cpx1, shape.cpy1 + extent,
  52372. shape.x1, shape.y1 + extent
  52373. );
  52374. }
  52375. ctx.closePath();
  52376. }
  52377. });
  52378. extendChartView({
  52379. type: 'sankey',
  52380. /**
  52381. * @private
  52382. * @type {module:echarts/chart/sankey/SankeySeries}
  52383. */
  52384. _model: null,
  52385. /**
  52386. * @private
  52387. * @type {boolean}
  52388. */
  52389. _focusAdjacencyDisabled: false,
  52390. render: function (seriesModel, ecModel, api) {
  52391. var sankeyView = this;
  52392. var graph = seriesModel.getGraph();
  52393. var group = this.group;
  52394. var layoutInfo = seriesModel.layoutInfo;
  52395. // view width
  52396. var width = layoutInfo.width;
  52397. // view height
  52398. var height = layoutInfo.height;
  52399. var nodeData = seriesModel.getData();
  52400. var edgeData = seriesModel.getData('edge');
  52401. var orient = seriesModel.get('orient');
  52402. this._model = seriesModel;
  52403. group.removeAll();
  52404. group.attr('position', [layoutInfo.x, layoutInfo.y]);
  52405. // generate a bezire Curve for each edge
  52406. graph.eachEdge(function (edge) {
  52407. var curve = new SankeyShape();
  52408. curve.dataIndex = edge.dataIndex;
  52409. curve.seriesIndex = seriesModel.seriesIndex;
  52410. curve.dataType = 'edge';
  52411. var lineStyleModel = edge.getModel('lineStyle');
  52412. var curvature = lineStyleModel.get('curveness');
  52413. var n1Layout = edge.node1.getLayout();
  52414. var node1Model = edge.node1.getModel();
  52415. var dragX1 = node1Model.get('localX');
  52416. var dragY1 = node1Model.get('localY');
  52417. var n2Layout = edge.node2.getLayout();
  52418. var node2Model = edge.node2.getModel();
  52419. var dragX2 = node2Model.get('localX');
  52420. var dragY2 = node2Model.get('localY');
  52421. var edgeLayout = edge.getLayout();
  52422. var x1;
  52423. var y1;
  52424. var x2;
  52425. var y2;
  52426. var cpx1;
  52427. var cpy1;
  52428. var cpx2;
  52429. var cpy2;
  52430. curve.shape.extent = Math.max(1, edgeLayout.dy);
  52431. curve.shape.orient = orient;
  52432. if (orient === 'vertical') {
  52433. x1 = (dragX1 != null ? dragX1 * width : n1Layout.x) + edgeLayout.sy;
  52434. y1 = (dragY1 != null ? dragY1 * height : n1Layout.y) + n1Layout.dy;
  52435. x2 = (dragX2 != null ? dragX2 * width : n2Layout.x) + edgeLayout.ty;
  52436. y2 = dragY2 != null ? dragY2 * height : n2Layout.y;
  52437. cpx1 = x1;
  52438. cpy1 = y1 * (1 - curvature) + y2 * curvature;
  52439. cpx2 = x2;
  52440. cpy2 = y1 * curvature + y2 * (1 - curvature);
  52441. }
  52442. else {
  52443. x1 = (dragX1 != null ? dragX1 * width : n1Layout.x) + n1Layout.dx;
  52444. y1 = (dragY1 != null ? dragY1 * height : n1Layout.y) + edgeLayout.sy;
  52445. x2 = dragX2 != null ? dragX2 * width : n2Layout.x;
  52446. y2 = (dragY2 != null ? dragY2 * height : n2Layout.y) + edgeLayout.ty;
  52447. cpx1 = x1 * (1 - curvature) + x2 * curvature;
  52448. cpy1 = y1;
  52449. cpx2 = x1 * curvature + x2 * (1 - curvature);
  52450. cpy2 = y2;
  52451. }
  52452. curve.setShape({
  52453. x1: x1,
  52454. y1: y1,
  52455. x2: x2,
  52456. y2: y2,
  52457. cpx1: cpx1,
  52458. cpy1: cpy1,
  52459. cpx2: cpx2,
  52460. cpy2: cpy2
  52461. });
  52462. curve.setStyle(lineStyleModel.getItemStyle());
  52463. // Special color, use source node color or target node color
  52464. switch (curve.style.fill) {
  52465. case 'source':
  52466. curve.style.fill = edge.node1.getVisual('color');
  52467. break;
  52468. case 'target':
  52469. curve.style.fill = edge.node2.getVisual('color');
  52470. break;
  52471. }
  52472. setHoverStyle(curve, edge.getModel('emphasis.lineStyle').getItemStyle());
  52473. group.add(curve);
  52474. edgeData.setItemGraphicEl(edge.dataIndex, curve);
  52475. });
  52476. // Generate a rect for each node
  52477. graph.eachNode(function (node) {
  52478. var layout = node.getLayout();
  52479. var itemModel = node.getModel();
  52480. var dragX = itemModel.get('localX');
  52481. var dragY = itemModel.get('localY');
  52482. var labelModel = itemModel.getModel('label');
  52483. var labelHoverModel = itemModel.getModel('emphasis.label');
  52484. var rect = new Rect({
  52485. shape: {
  52486. x: dragX != null ? dragX * width : layout.x,
  52487. y: dragY != null ? dragY * height : layout.y,
  52488. width: layout.dx,
  52489. height: layout.dy
  52490. },
  52491. style: itemModel.getModel('itemStyle').getItemStyle()
  52492. });
  52493. var hoverStyle = node.getModel('emphasis.itemStyle').getItemStyle();
  52494. setLabelStyle(
  52495. rect.style, hoverStyle, labelModel, labelHoverModel,
  52496. {
  52497. labelFetcher: seriesModel,
  52498. labelDataIndex: node.dataIndex,
  52499. defaultText: node.id,
  52500. isRectText: true
  52501. }
  52502. );
  52503. rect.setStyle('fill', node.getVisual('color'));
  52504. setHoverStyle(rect, hoverStyle);
  52505. group.add(rect);
  52506. nodeData.setItemGraphicEl(node.dataIndex, rect);
  52507. rect.dataType = 'node';
  52508. });
  52509. nodeData.eachItemGraphicEl(function (el, dataIndex) {
  52510. var itemModel = nodeData.getItemModel(dataIndex);
  52511. if (itemModel.get('draggable')) {
  52512. el.drift = function (dx, dy) {
  52513. sankeyView._focusAdjacencyDisabled = true;
  52514. this.shape.x += dx;
  52515. this.shape.y += dy;
  52516. this.dirty();
  52517. api.dispatchAction({
  52518. type: 'dragNode',
  52519. seriesId: seriesModel.id,
  52520. dataIndex: nodeData.getRawIndex(dataIndex),
  52521. localX: this.shape.x / width,
  52522. localY: this.shape.y / height
  52523. });
  52524. };
  52525. el.ondragend = function () {
  52526. sankeyView._focusAdjacencyDisabled = false;
  52527. };
  52528. el.draggable = true;
  52529. el.cursor = 'move';
  52530. }
  52531. if (itemModel.get('focusNodeAdjacency')) {
  52532. el.off('mouseover').on('mouseover', function () {
  52533. if (!sankeyView._focusAdjacencyDisabled) {
  52534. api.dispatchAction({
  52535. type: 'focusNodeAdjacency',
  52536. seriesId: seriesModel.id,
  52537. dataIndex: el.dataIndex
  52538. });
  52539. }
  52540. });
  52541. el.off('mouseout').on('mouseout', function () {
  52542. if (!sankeyView._focusAdjacencyDisabled) {
  52543. api.dispatchAction({
  52544. type: 'unfocusNodeAdjacency',
  52545. seriesId: seriesModel.id
  52546. });
  52547. }
  52548. });
  52549. }
  52550. });
  52551. edgeData.eachItemGraphicEl(function (el, dataIndex) {
  52552. var edgeModel = edgeData.getItemModel(dataIndex);
  52553. if (edgeModel.get('focusNodeAdjacency')) {
  52554. el.off('mouseover').on('mouseover', function () {
  52555. if (!sankeyView._focusAdjacencyDisabled) {
  52556. api.dispatchAction({
  52557. type: 'focusNodeAdjacency',
  52558. seriesId: seriesModel.id,
  52559. edgeDataIndex: el.dataIndex
  52560. });
  52561. }
  52562. });
  52563. el.off('mouseout').on('mouseout', function () {
  52564. if (!sankeyView._focusAdjacencyDisabled) {
  52565. api.dispatchAction({
  52566. type: 'unfocusNodeAdjacency',
  52567. seriesId: seriesModel.id
  52568. });
  52569. }
  52570. });
  52571. }
  52572. });
  52573. if (!this._data && seriesModel.get('animation')) {
  52574. group.setClipPath(createGridClipShape$2(group.getBoundingRect(), seriesModel, function () {
  52575. group.removeClipPath();
  52576. }));
  52577. }
  52578. this._data = seriesModel.getData();
  52579. },
  52580. dispose: function () {},
  52581. focusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  52582. var data = this._model.getData();
  52583. var graph = data.graph;
  52584. var dataIndex = payload.dataIndex;
  52585. var itemModel = data.getItemModel(dataIndex);
  52586. var edgeDataIndex = payload.edgeDataIndex;
  52587. if (dataIndex == null && edgeDataIndex == null) {
  52588. return;
  52589. }
  52590. var node = graph.getNodeByIndex(dataIndex);
  52591. var edge = graph.getEdgeByIndex(edgeDataIndex);
  52592. graph.eachNode(function (node) {
  52593. fadeOutItem$1(node, nodeOpacityPath$1, 0.1);
  52594. });
  52595. graph.eachEdge(function (edge) {
  52596. fadeOutItem$1(edge, lineOpacityPath$1, 0.1);
  52597. });
  52598. if (node) {
  52599. fadeInItem$1(node, nodeOpacityPath$1);
  52600. var focusNodeAdj = itemModel.get('focusNodeAdjacency');
  52601. if (focusNodeAdj === 'outEdges') {
  52602. each$1(node.outEdges, function (edge) {
  52603. if (edge.dataIndex < 0) {
  52604. return;
  52605. }
  52606. fadeInItem$1(edge, lineOpacityPath$1);
  52607. fadeInItem$1(edge.node2, nodeOpacityPath$1);
  52608. });
  52609. }
  52610. else if (focusNodeAdj === 'inEdges') {
  52611. each$1(node.inEdges, function (edge) {
  52612. if (edge.dataIndex < 0) {
  52613. return;
  52614. }
  52615. fadeInItem$1(edge, lineOpacityPath$1);
  52616. fadeInItem$1(edge.node1, nodeOpacityPath$1);
  52617. });
  52618. }
  52619. else if (focusNodeAdj === 'allEdges') {
  52620. each$1(node.edges, function (edge) {
  52621. if (edge.dataIndex < 0) {
  52622. return;
  52623. }
  52624. fadeInItem$1(edge, lineOpacityPath$1);
  52625. fadeInItem$1(edge.node1, nodeOpacityPath$1);
  52626. fadeInItem$1(edge.node2, nodeOpacityPath$1);
  52627. });
  52628. }
  52629. }
  52630. if (edge) {
  52631. fadeInItem$1(edge, lineOpacityPath$1);
  52632. fadeInItem$1(edge.node1, nodeOpacityPath$1);
  52633. fadeInItem$1(edge.node2, nodeOpacityPath$1);
  52634. }
  52635. },
  52636. unfocusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  52637. var graph = this._model.getGraph();
  52638. graph.eachNode(function (node) {
  52639. fadeOutItem$1(node, nodeOpacityPath$1);
  52640. });
  52641. graph.eachEdge(function (edge) {
  52642. fadeOutItem$1(edge, lineOpacityPath$1);
  52643. });
  52644. }
  52645. });
  52646. // Add animation to the view
  52647. function createGridClipShape$2(rect, seriesModel, cb) {
  52648. var rectEl = new Rect({
  52649. shape: {
  52650. x: rect.x - 10,
  52651. y: rect.y - 10,
  52652. width: 0,
  52653. height: rect.height + 20
  52654. }
  52655. });
  52656. initProps(rectEl, {
  52657. shape: {
  52658. width: rect.width + 20,
  52659. height: rect.height + 20
  52660. }
  52661. }, seriesModel, cb);
  52662. return rectEl;
  52663. }
  52664. /*
  52665. * Licensed to the Apache Software Foundation (ASF) under one
  52666. * or more contributor license agreements. See the NOTICE file
  52667. * distributed with this work for additional information
  52668. * regarding copyright ownership. The ASF licenses this file
  52669. * to you under the Apache License, Version 2.0 (the
  52670. * "License"); you may not use this file except in compliance
  52671. * with the License. You may obtain a copy of the License at
  52672. *
  52673. * http://www.apache.org/licenses/LICENSE-2.0
  52674. *
  52675. * Unless required by applicable law or agreed to in writing,
  52676. * software distributed under the License is distributed on an
  52677. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52678. * KIND, either express or implied. See the License for the
  52679. * specific language governing permissions and limitations
  52680. * under the License.
  52681. */
  52682. /**
  52683. * @file The interactive action of sankey view
  52684. * @author Deqing Li(annong035@gmail.com)
  52685. */
  52686. registerAction({
  52687. type: 'dragNode',
  52688. event: 'dragNode',
  52689. // here can only use 'update' now, other value is not support in echarts.
  52690. update: 'update'
  52691. }, function (payload, ecModel) {
  52692. ecModel.eachComponent({mainType: 'series', subType: 'sankey', query: payload}, function (seriesModel) {
  52693. seriesModel.setNodePosition(payload.dataIndex, [payload.localX, payload.localY]);
  52694. });
  52695. });
  52696. /*
  52697. * Licensed to the Apache Software Foundation (ASF) under one
  52698. * or more contributor license agreements. See the NOTICE file
  52699. * distributed with this work for additional information
  52700. * regarding copyright ownership. The ASF licenses this file
  52701. * to you under the Apache License, Version 2.0 (the
  52702. * "License"); you may not use this file except in compliance
  52703. * with the License. You may obtain a copy of the License at
  52704. *
  52705. * http://www.apache.org/licenses/LICENSE-2.0
  52706. *
  52707. * Unless required by applicable law or agreed to in writing,
  52708. * software distributed under the License is distributed on an
  52709. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52710. * KIND, either express or implied. See the License for the
  52711. * specific language governing permissions and limitations
  52712. * under the License.
  52713. */
  52714. /**
  52715. * @file The layout algorithm of sankey view
  52716. * @author Deqing Li(annong035@gmail.com)
  52717. */
  52718. var sankeyLayout = function (ecModel, api, payload) {
  52719. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  52720. var nodeWidth = seriesModel.get('nodeWidth');
  52721. var nodeGap = seriesModel.get('nodeGap');
  52722. var layoutInfo = getViewRect$3(seriesModel, api);
  52723. seriesModel.layoutInfo = layoutInfo;
  52724. var width = layoutInfo.width;
  52725. var height = layoutInfo.height;
  52726. var graph = seriesModel.getGraph();
  52727. var nodes = graph.nodes;
  52728. var edges = graph.edges;
  52729. computeNodeValues(nodes);
  52730. var filteredNodes = filter(nodes, function (node) {
  52731. return node.getLayout().value === 0;
  52732. });
  52733. var iterations = filteredNodes.length !== 0
  52734. ? 0 : seriesModel.get('layoutIterations');
  52735. var orient = seriesModel.get('orient');
  52736. layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient);
  52737. });
  52738. };
  52739. /**
  52740. * Get the layout position of the whole view
  52741. *
  52742. * @param {module:echarts/model/Series} seriesModel the model object of sankey series
  52743. * @param {module:echarts/ExtensionAPI} api provide the API list that the developer can call
  52744. * @return {module:zrender/core/BoundingRect} size of rect to draw the sankey view
  52745. */
  52746. function getViewRect$3(seriesModel, api) {
  52747. return getLayoutRect(
  52748. seriesModel.getBoxLayoutParams(), {
  52749. width: api.getWidth(),
  52750. height: api.getHeight()
  52751. }
  52752. );
  52753. }
  52754. function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient) {
  52755. computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient);
  52756. computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient);
  52757. computeEdgeDepths(nodes, orient);
  52758. }
  52759. /**
  52760. * Compute the value of each node by summing the associated edge's value
  52761. *
  52762. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  52763. */
  52764. function computeNodeValues(nodes) {
  52765. each$1(nodes, function (node) {
  52766. var value1 = sum(node.outEdges, getEdgeValue);
  52767. var value2 = sum(node.inEdges, getEdgeValue);
  52768. var value = Math.max(value1, value2);
  52769. node.setLayout({value: value}, true);
  52770. });
  52771. }
  52772. /**
  52773. * Compute the x-position for each node.
  52774. *
  52775. * Here we use Kahn algorithm to detect cycle when we traverse
  52776. * the node to computer the initial x position.
  52777. *
  52778. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  52779. * @param {number} nodeWidth the dx of the node
  52780. * @param {number} width the whole width of the area to draw the view
  52781. */
  52782. function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient) {
  52783. // Used to mark whether the edge is deleted. if it is deleted,
  52784. // the value is 0, otherwise it is 1.
  52785. var remainEdges = [];
  52786. // Storage each node's indegree.
  52787. var indegreeArr = [];
  52788. //Used to storage the node with indegree is equal to 0.
  52789. var zeroIndegrees = [];
  52790. var nextNode = [];
  52791. var x = 0;
  52792. var kx = 0;
  52793. for (var i = 0; i < edges.length; i++) {
  52794. remainEdges[i] = 1;
  52795. }
  52796. for (i = 0; i < nodes.length; i++) {
  52797. indegreeArr[i] = nodes[i].inEdges.length;
  52798. if (indegreeArr[i] === 0) {
  52799. zeroIndegrees.push(nodes[i]);
  52800. }
  52801. }
  52802. while (zeroIndegrees.length) {
  52803. for (var idx = 0; idx < zeroIndegrees.length; idx++) {
  52804. var node = zeroIndegrees[idx];
  52805. if (orient === 'vertical') {
  52806. node.setLayout({y: x}, true);
  52807. node.setLayout({dy: nodeWidth}, true);
  52808. }
  52809. else {
  52810. node.setLayout({x: x}, true);
  52811. node.setLayout({dx: nodeWidth}, true);
  52812. }
  52813. for (var oidx = 0; oidx < node.outEdges.length; oidx++) {
  52814. var edge = node.outEdges[oidx];
  52815. var indexEdge = edges.indexOf(edge);
  52816. remainEdges[indexEdge] = 0;
  52817. var targetNode = edge.node2;
  52818. var nodeIndex = nodes.indexOf(targetNode);
  52819. if (--indegreeArr[nodeIndex] === 0) {
  52820. nextNode.push(targetNode);
  52821. }
  52822. }
  52823. }
  52824. ++x;
  52825. zeroIndegrees = nextNode;
  52826. nextNode = [];
  52827. }
  52828. for (i = 0; i < remainEdges.length; i++) {
  52829. if (__DEV__) {
  52830. if (remainEdges[i] === 1) {
  52831. throw new Error('Sankey is a DAG, the original data has cycle!');
  52832. }
  52833. }
  52834. }
  52835. moveSinksRight(nodes, x, orient);
  52836. if (orient === 'vertical') {
  52837. kx = (height - nodeWidth) / (x - 1);
  52838. }
  52839. else {
  52840. kx = (width - nodeWidth) / (x - 1);
  52841. }
  52842. scaleNodeBreadths(nodes, kx, orient);
  52843. }
  52844. /**
  52845. * All the node without outEgdes are assigned maximum x-position and
  52846. * be aligned in the last column.
  52847. *
  52848. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  52849. * @param {number} x value (x-1) use to assign to node without outEdges
  52850. * as x-position
  52851. */
  52852. function moveSinksRight(nodes, x, orient) {
  52853. each$1(nodes, function (node) {
  52854. if (!node.outEdges.length) {
  52855. if (orient === 'vertical') {
  52856. node.setLayout({y: x - 1}, true);
  52857. }
  52858. else {
  52859. node.setLayout({x: x - 1}, true);
  52860. }
  52861. }
  52862. });
  52863. }
  52864. /**
  52865. * Scale node x-position to the width
  52866. *
  52867. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  52868. * @param {number} kx multiple used to scale nodes
  52869. */
  52870. function scaleNodeBreadths(nodes, kx, orient) {
  52871. each$1(nodes, function (node) {
  52872. if (orient === 'vertical') {
  52873. var nodeY = node.getLayout().y * kx;
  52874. node.setLayout({y: nodeY}, true);
  52875. }
  52876. else {
  52877. var nodeX = node.getLayout().x * kx;
  52878. node.setLayout({x: nodeX}, true);
  52879. }
  52880. });
  52881. }
  52882. /**
  52883. * Using Gauss-Seidel iterations method to compute the node depth(y-position)
  52884. *
  52885. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  52886. * @param {module:echarts/data/Graph~Edge} edges edge of sankey view
  52887. * @param {number} height the whole height of the area to draw the view
  52888. * @param {number} nodeGap the vertical distance between two nodes
  52889. * in the same column.
  52890. * @param {number} iterations the number of iterations for the algorithm
  52891. */
  52892. function computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient) {
  52893. var nodesByBreadth = prepareNodesByBreadth(nodes, orient);
  52894. initializeNodeDepth(nodes, nodesByBreadth, edges, height, width, nodeGap, orient);
  52895. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  52896. for (var alpha = 1; iterations > 0; iterations--) {
  52897. // 0.99 is a experience parameter, ensure that each iterations of
  52898. // changes as small as possible.
  52899. alpha *= 0.99;
  52900. relaxRightToLeft(nodesByBreadth, alpha, orient);
  52901. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  52902. relaxLeftToRight(nodesByBreadth, alpha, orient);
  52903. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  52904. }
  52905. }
  52906. function prepareNodesByBreadth(nodes, orient) {
  52907. var nodesByBreadth = [];
  52908. var keyAttr = orient === 'vertical' ? 'y' : 'x';
  52909. var groupResult = groupData(nodes, function (node) {
  52910. return node.getLayout()[keyAttr];
  52911. });
  52912. groupResult.keys.sort(function (a, b) {
  52913. return a - b;
  52914. });
  52915. each$1(groupResult.keys, function (key) {
  52916. nodesByBreadth.push(groupResult.buckets.get(key));
  52917. });
  52918. return nodesByBreadth;
  52919. }
  52920. /**
  52921. * Compute the original y-position for each node
  52922. *
  52923. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  52924. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  52925. * group by the array of all sankey nodes based on the nodes x-position.
  52926. * @param {module:echarts/data/Graph~Edge} edges edge of sankey view
  52927. * @param {number} height the whole height of the area to draw the view
  52928. * @param {number} nodeGap the vertical distance between two nodes
  52929. */
  52930. function initializeNodeDepth(nodes, nodesByBreadth, edges, height, width, nodeGap, orient) {
  52931. var kyArray = [];
  52932. each$1(nodesByBreadth, function (nodes) {
  52933. var n = nodes.length;
  52934. var sum = 0;
  52935. var ky = 0;
  52936. each$1(nodes, function (node) {
  52937. sum += node.getLayout().value;
  52938. });
  52939. if (orient === 'vertical') {
  52940. ky = (width - (n - 1) * nodeGap) / sum;
  52941. }
  52942. else {
  52943. ky = (height - (n - 1) * nodeGap) / sum;
  52944. }
  52945. kyArray.push(ky);
  52946. });
  52947. kyArray.sort(function (a, b) {
  52948. return a - b;
  52949. });
  52950. var ky0 = kyArray[0];
  52951. each$1(nodesByBreadth, function (nodes) {
  52952. each$1(nodes, function (node, i) {
  52953. var nodeDy = node.getLayout().value * ky0;
  52954. if (orient === 'vertical') {
  52955. node.setLayout({x: i}, true);
  52956. node.setLayout({dx: nodeDy}, true);
  52957. }
  52958. else {
  52959. node.setLayout({y: i}, true);
  52960. node.setLayout({dy: nodeDy}, true);
  52961. }
  52962. });
  52963. });
  52964. each$1(edges, function (edge) {
  52965. var edgeDy = +edge.getValue() * ky0;
  52966. edge.setLayout({dy: edgeDy}, true);
  52967. });
  52968. }
  52969. /**
  52970. * Resolve the collision of initialized depth (y-position)
  52971. *
  52972. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  52973. * group by the array of all sankey nodes based on the nodes x-position.
  52974. * @param {number} nodeGap the vertical distance between two nodes
  52975. * @param {number} height the whole height of the area to draw the view
  52976. */
  52977. function resolveCollisions(nodesByBreadth, nodeGap, height, width, orient) {
  52978. each$1(nodesByBreadth, function (nodes) {
  52979. var node;
  52980. var dy;
  52981. var y0 = 0;
  52982. var n = nodes.length;
  52983. var i;
  52984. if (orient === 'vertical') {
  52985. var nodeX;
  52986. nodes.sort(function (a, b) {
  52987. return a.getLayout().x - b.getLayout().x;
  52988. });
  52989. for (i = 0; i < n; i++) {
  52990. node = nodes[i];
  52991. dy = y0 - node.getLayout().x;
  52992. if (dy > 0) {
  52993. nodeX = node.getLayout().x + dy;
  52994. node.setLayout({x: nodeX}, true);
  52995. }
  52996. y0 = node.getLayout().x + node.getLayout().dx + nodeGap;
  52997. }
  52998. // If the bottommost node goes outside the bounds, push it back up
  52999. dy = y0 - nodeGap - width;
  53000. if (dy > 0) {
  53001. nodeX = node.getLayout().x - dy;
  53002. node.setLayout({x: nodeX}, true);
  53003. y0 = nodeX;
  53004. for (i = n - 2; i >= 0; --i) {
  53005. node = nodes[i];
  53006. dy = node.getLayout().x + node.getLayout().dx + nodeGap - y0;
  53007. if (dy > 0) {
  53008. nodeX = node.getLayout().x - dy;
  53009. node.setLayout({x: nodeX}, true);
  53010. }
  53011. y0 = node.getLayout().x;
  53012. }
  53013. }
  53014. }
  53015. else {
  53016. var nodeY;
  53017. nodes.sort(function (a, b) {
  53018. return a.getLayout().y - b.getLayout().y;
  53019. });
  53020. for (i = 0; i < n; i++) {
  53021. node = nodes[i];
  53022. dy = y0 - node.getLayout().y;
  53023. if (dy > 0) {
  53024. nodeY = node.getLayout().y + dy;
  53025. node.setLayout({y: nodeY}, true);
  53026. }
  53027. y0 = node.getLayout().y + node.getLayout().dy + nodeGap;
  53028. }
  53029. // If the bottommost node goes outside the bounds, push it back up
  53030. dy = y0 - nodeGap - height;
  53031. if (dy > 0) {
  53032. nodeY = node.getLayout().y - dy;
  53033. node.setLayout({y: nodeY}, true);
  53034. y0 = nodeY;
  53035. for (i = n - 2; i >= 0; --i) {
  53036. node = nodes[i];
  53037. dy = node.getLayout().y + node.getLayout().dy + nodeGap - y0;
  53038. if (dy > 0) {
  53039. nodeY = node.getLayout().y - dy;
  53040. node.setLayout({y: nodeY}, true);
  53041. }
  53042. y0 = node.getLayout().y;
  53043. }
  53044. }
  53045. }
  53046. });
  53047. }
  53048. /**
  53049. * Change the y-position of the nodes, except most the right side nodes
  53050. *
  53051. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  53052. * group by the array of all sankey nodes based on the node x-position.
  53053. * @param {number} alpha parameter used to adjust the nodes y-position
  53054. */
  53055. function relaxRightToLeft(nodesByBreadth, alpha, orient) {
  53056. each$1(nodesByBreadth.slice().reverse(), function (nodes) {
  53057. each$1(nodes, function (node) {
  53058. if (node.outEdges.length) {
  53059. var y = sum(node.outEdges, weightedTarget, orient) / sum(node.outEdges, getEdgeValue, orient);
  53060. if (orient === 'vertical') {
  53061. var nodeX = node.getLayout().x + (y - center$1(node, orient)) * alpha;
  53062. node.setLayout({x: nodeX}, true);
  53063. }
  53064. else {
  53065. var nodeY = node.getLayout().y + (y - center$1(node, orient)) * alpha;
  53066. node.setLayout({y: nodeY}, true);
  53067. }
  53068. }
  53069. });
  53070. });
  53071. }
  53072. function weightedTarget(edge, orient) {
  53073. return center$1(edge.node2, orient) * edge.getValue();
  53074. }
  53075. function weightedSource(edge, orient) {
  53076. return center$1(edge.node1, orient) * edge.getValue();
  53077. }
  53078. function center$1(node, orient) {
  53079. if (orient === 'vertical') {
  53080. return node.getLayout().x + node.getLayout().dx / 2;
  53081. }
  53082. return node.getLayout().y + node.getLayout().dy / 2;
  53083. }
  53084. function getEdgeValue(edge) {
  53085. return edge.getValue();
  53086. }
  53087. function sum(array, f, orient) {
  53088. var sum = 0;
  53089. var len = array.length;
  53090. var i = -1;
  53091. while (++i < len) {
  53092. var value = +f.call(array, array[i], orient);
  53093. if (!isNaN(value)) {
  53094. sum += value;
  53095. }
  53096. }
  53097. return sum;
  53098. }
  53099. /**
  53100. * Change the y-position of the nodes, except most the left side nodes
  53101. *
  53102. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  53103. * group by the array of all sankey nodes based on the node x-position.
  53104. * @param {number} alpha parameter used to adjust the nodes y-position
  53105. */
  53106. function relaxLeftToRight(nodesByBreadth, alpha, orient) {
  53107. each$1(nodesByBreadth, function (nodes) {
  53108. each$1(nodes, function (node) {
  53109. if (node.inEdges.length) {
  53110. var y = sum(node.inEdges, weightedSource, orient) / sum(node.inEdges, getEdgeValue, orient);
  53111. if (orient === 'vertical') {
  53112. var nodeX = node.getLayout().x + (y - center$1(node, orient)) * alpha;
  53113. node.setLayout({x: nodeX}, true);
  53114. }
  53115. else {
  53116. var nodeY = node.getLayout().y + (y - center$1(node, orient)) * alpha;
  53117. node.setLayout({y: nodeY}, true);
  53118. }
  53119. }
  53120. });
  53121. });
  53122. }
  53123. /**
  53124. * Compute the depth(y-position) of each edge
  53125. *
  53126. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  53127. */
  53128. function computeEdgeDepths(nodes, orient) {
  53129. each$1(nodes, function (node) {
  53130. if (orient === 'vertical') {
  53131. node.outEdges.sort(function (a, b) {
  53132. return a.node2.getLayout().x - b.node2.getLayout().x;
  53133. });
  53134. node.inEdges.sort(function (a, b) {
  53135. return a.node1.getLayout().x - b.node1.getLayout().x;
  53136. });
  53137. }
  53138. else {
  53139. node.outEdges.sort(function (a, b) {
  53140. return a.node2.getLayout().y - b.node2.getLayout().y;
  53141. });
  53142. node.inEdges.sort(function (a, b) {
  53143. return a.node1.getLayout().y - b.node1.getLayout().y;
  53144. });
  53145. }
  53146. });
  53147. each$1(nodes, function (node) {
  53148. var sy = 0;
  53149. var ty = 0;
  53150. each$1(node.outEdges, function (edge) {
  53151. edge.setLayout({sy: sy}, true);
  53152. sy += edge.getLayout().dy;
  53153. });
  53154. each$1(node.inEdges, function (edge) {
  53155. edge.setLayout({ty: ty}, true);
  53156. ty += edge.getLayout().dy;
  53157. });
  53158. });
  53159. }
  53160. /*
  53161. * Licensed to the Apache Software Foundation (ASF) under one
  53162. * or more contributor license agreements. See the NOTICE file
  53163. * distributed with this work for additional information
  53164. * regarding copyright ownership. The ASF licenses this file
  53165. * to you under the Apache License, Version 2.0 (the
  53166. * "License"); you may not use this file except in compliance
  53167. * with the License. You may obtain a copy of the License at
  53168. *
  53169. * http://www.apache.org/licenses/LICENSE-2.0
  53170. *
  53171. * Unless required by applicable law or agreed to in writing,
  53172. * software distributed under the License is distributed on an
  53173. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53174. * KIND, either express or implied. See the License for the
  53175. * specific language governing permissions and limitations
  53176. * under the License.
  53177. */
  53178. /**
  53179. * @file Visual encoding for sankey view
  53180. * @author Deqing Li(annong035@gmail.com)
  53181. */
  53182. var sankeyVisual = function (ecModel, payload) {
  53183. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  53184. var graph = seriesModel.getGraph();
  53185. var nodes = graph.nodes;
  53186. if (nodes.length) {
  53187. var minValue = Infinity;
  53188. var maxValue = -Infinity;
  53189. each$1(nodes, function (node) {
  53190. var nodeValue = node.getLayout().value;
  53191. if (nodeValue < minValue) {
  53192. minValue = nodeValue;
  53193. }
  53194. if (nodeValue > maxValue) {
  53195. maxValue = nodeValue;
  53196. }
  53197. });
  53198. each$1(nodes, function (node) {
  53199. var mapping = new VisualMapping({
  53200. type: 'color',
  53201. mappingMethod: 'linear',
  53202. dataExtent: [minValue, maxValue],
  53203. visual: seriesModel.get('color')
  53204. });
  53205. var mapValueToColor = mapping.mapValueToVisual(node.getLayout().value);
  53206. node.setVisual('color', mapValueToColor);
  53207. // If set itemStyle.normal.color
  53208. var itemModel = node.getModel();
  53209. var customColor = itemModel.get('itemStyle.color');
  53210. if (customColor != null) {
  53211. node.setVisual('color', customColor);
  53212. }
  53213. });
  53214. }
  53215. });
  53216. };
  53217. /*
  53218. * Licensed to the Apache Software Foundation (ASF) under one
  53219. * or more contributor license agreements. See the NOTICE file
  53220. * distributed with this work for additional information
  53221. * regarding copyright ownership. The ASF licenses this file
  53222. * to you under the Apache License, Version 2.0 (the
  53223. * "License"); you may not use this file except in compliance
  53224. * with the License. You may obtain a copy of the License at
  53225. *
  53226. * http://www.apache.org/licenses/LICENSE-2.0
  53227. *
  53228. * Unless required by applicable law or agreed to in writing,
  53229. * software distributed under the License is distributed on an
  53230. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53231. * KIND, either express or implied. See the License for the
  53232. * specific language governing permissions and limitations
  53233. * under the License.
  53234. */
  53235. registerLayout(sankeyLayout);
  53236. registerVisual(sankeyVisual);
  53237. /*
  53238. * Licensed to the Apache Software Foundation (ASF) under one
  53239. * or more contributor license agreements. See the NOTICE file
  53240. * distributed with this work for additional information
  53241. * regarding copyright ownership. The ASF licenses this file
  53242. * to you under the Apache License, Version 2.0 (the
  53243. * "License"); you may not use this file except in compliance
  53244. * with the License. You may obtain a copy of the License at
  53245. *
  53246. * http://www.apache.org/licenses/LICENSE-2.0
  53247. *
  53248. * Unless required by applicable law or agreed to in writing,
  53249. * software distributed under the License is distributed on an
  53250. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53251. * KIND, either express or implied. See the License for the
  53252. * specific language governing permissions and limitations
  53253. * under the License.
  53254. */
  53255. var seriesModelMixin = {
  53256. /**
  53257. * @private
  53258. * @type {string}
  53259. */
  53260. _baseAxisDim: null,
  53261. /**
  53262. * @override
  53263. */
  53264. getInitialData: function (option, ecModel) {
  53265. // When both types of xAxis and yAxis are 'value', layout is
  53266. // needed to be specified by user. Otherwise, layout can be
  53267. // judged by which axis is category.
  53268. var ordinalMeta;
  53269. var xAxisModel = ecModel.getComponent('xAxis', this.get('xAxisIndex'));
  53270. var yAxisModel = ecModel.getComponent('yAxis', this.get('yAxisIndex'));
  53271. var xAxisType = xAxisModel.get('type');
  53272. var yAxisType = yAxisModel.get('type');
  53273. var addOrdinal;
  53274. // FIXME
  53275. // 考虑时间轴
  53276. if (xAxisType === 'category') {
  53277. option.layout = 'horizontal';
  53278. ordinalMeta = xAxisModel.getOrdinalMeta();
  53279. addOrdinal = true;
  53280. }
  53281. else if (yAxisType === 'category') {
  53282. option.layout = 'vertical';
  53283. ordinalMeta = yAxisModel.getOrdinalMeta();
  53284. addOrdinal = true;
  53285. }
  53286. else {
  53287. option.layout = option.layout || 'horizontal';
  53288. }
  53289. var coordDims = ['x', 'y'];
  53290. var baseAxisDimIndex = option.layout === 'horizontal' ? 0 : 1;
  53291. var baseAxisDim = this._baseAxisDim = coordDims[baseAxisDimIndex];
  53292. var otherAxisDim = coordDims[1 - baseAxisDimIndex];
  53293. var axisModels = [xAxisModel, yAxisModel];
  53294. var baseAxisType = axisModels[baseAxisDimIndex].get('type');
  53295. var otherAxisType = axisModels[1 - baseAxisDimIndex].get('type');
  53296. var data = option.data;
  53297. // ??? FIXME make a stage to perform data transfrom.
  53298. // MUST create a new data, consider setOption({}) again.
  53299. if (data && addOrdinal) {
  53300. var newOptionData = [];
  53301. each$1(data, function (item, index) {
  53302. var newItem;
  53303. if (item.value && isArray(item.value)) {
  53304. newItem = item.value.slice();
  53305. item.value.unshift(index);
  53306. }
  53307. else if (isArray(item)) {
  53308. newItem = item.slice();
  53309. item.unshift(index);
  53310. }
  53311. else {
  53312. newItem = item;
  53313. }
  53314. newOptionData.push(newItem);
  53315. });
  53316. option.data = newOptionData;
  53317. }
  53318. var defaultValueDimensions = this.defaultValueDimensions;
  53319. return createListSimply(
  53320. this,
  53321. {
  53322. coordDimensions: [{
  53323. name: baseAxisDim,
  53324. type: getDimensionTypeByAxis(baseAxisType),
  53325. ordinalMeta: ordinalMeta,
  53326. otherDims: {
  53327. tooltip: false,
  53328. itemName: 0
  53329. },
  53330. dimsDef: ['base']
  53331. }, {
  53332. name: otherAxisDim,
  53333. type: getDimensionTypeByAxis(otherAxisType),
  53334. dimsDef: defaultValueDimensions.slice()
  53335. }],
  53336. dimensionsCount: defaultValueDimensions.length + 1
  53337. }
  53338. );
  53339. },
  53340. /**
  53341. * If horizontal, base axis is x, otherwise y.
  53342. * @override
  53343. */
  53344. getBaseAxis: function () {
  53345. var dim = this._baseAxisDim;
  53346. return this.ecModel.getComponent(dim + 'Axis', this.get(dim + 'AxisIndex')).axis;
  53347. }
  53348. };
  53349. /*
  53350. * Licensed to the Apache Software Foundation (ASF) under one
  53351. * or more contributor license agreements. See the NOTICE file
  53352. * distributed with this work for additional information
  53353. * regarding copyright ownership. The ASF licenses this file
  53354. * to you under the Apache License, Version 2.0 (the
  53355. * "License"); you may not use this file except in compliance
  53356. * with the License. You may obtain a copy of the License at
  53357. *
  53358. * http://www.apache.org/licenses/LICENSE-2.0
  53359. *
  53360. * Unless required by applicable law or agreed to in writing,
  53361. * software distributed under the License is distributed on an
  53362. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53363. * KIND, either express or implied. See the License for the
  53364. * specific language governing permissions and limitations
  53365. * under the License.
  53366. */
  53367. var BoxplotSeries = SeriesModel.extend({
  53368. type: 'series.boxplot',
  53369. dependencies: ['xAxis', 'yAxis', 'grid'],
  53370. // TODO
  53371. // box width represents group size, so dimension should have 'size'.
  53372. /**
  53373. * @see <https://en.wikipedia.org/wiki/Box_plot>
  53374. * The meanings of 'min' and 'max' depend on user,
  53375. * and echarts do not need to know it.
  53376. * @readOnly
  53377. */
  53378. defaultValueDimensions: [
  53379. {name: 'min', defaultTooltip: true},
  53380. {name: 'Q1', defaultTooltip: true},
  53381. {name: 'median', defaultTooltip: true},
  53382. {name: 'Q3', defaultTooltip: true},
  53383. {name: 'max', defaultTooltip: true}
  53384. ],
  53385. /**
  53386. * @type {Array.<string>}
  53387. * @readOnly
  53388. */
  53389. dimensions: null,
  53390. /**
  53391. * @override
  53392. */
  53393. defaultOption: {
  53394. zlevel: 0, // 一级层叠
  53395. z: 2, // 二级层叠
  53396. coordinateSystem: 'cartesian2d',
  53397. legendHoverLink: true,
  53398. hoverAnimation: true,
  53399. // xAxisIndex: 0,
  53400. // yAxisIndex: 0,
  53401. layout: null, // 'horizontal' or 'vertical'
  53402. boxWidth: [7, 50], // [min, max] can be percent of band width.
  53403. itemStyle: {
  53404. color: '#fff',
  53405. borderWidth: 1
  53406. },
  53407. emphasis: {
  53408. itemStyle: {
  53409. borderWidth: 2,
  53410. shadowBlur: 5,
  53411. shadowOffsetX: 2,
  53412. shadowOffsetY: 2,
  53413. shadowColor: 'rgba(0,0,0,0.4)'
  53414. }
  53415. },
  53416. animationEasing: 'elasticOut',
  53417. animationDuration: 800
  53418. }
  53419. });
  53420. mixin(BoxplotSeries, seriesModelMixin, true);
  53421. /*
  53422. * Licensed to the Apache Software Foundation (ASF) under one
  53423. * or more contributor license agreements. See the NOTICE file
  53424. * distributed with this work for additional information
  53425. * regarding copyright ownership. The ASF licenses this file
  53426. * to you under the Apache License, Version 2.0 (the
  53427. * "License"); you may not use this file except in compliance
  53428. * with the License. You may obtain a copy of the License at
  53429. *
  53430. * http://www.apache.org/licenses/LICENSE-2.0
  53431. *
  53432. * Unless required by applicable law or agreed to in writing,
  53433. * software distributed under the License is distributed on an
  53434. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53435. * KIND, either express or implied. See the License for the
  53436. * specific language governing permissions and limitations
  53437. * under the License.
  53438. */
  53439. // Update common properties
  53440. var NORMAL_ITEM_STYLE_PATH = ['itemStyle'];
  53441. var EMPHASIS_ITEM_STYLE_PATH = ['emphasis', 'itemStyle'];
  53442. var BoxplotView = Chart.extend({
  53443. type: 'boxplot',
  53444. render: function (seriesModel, ecModel, api) {
  53445. var data = seriesModel.getData();
  53446. var group = this.group;
  53447. var oldData = this._data;
  53448. // There is no old data only when first rendering or switching from
  53449. // stream mode to normal mode, where previous elements should be removed.
  53450. if (!this._data) {
  53451. group.removeAll();
  53452. }
  53453. var constDim = seriesModel.get('layout') === 'horizontal' ? 1 : 0;
  53454. data.diff(oldData)
  53455. .add(function (newIdx) {
  53456. if (data.hasValue(newIdx)) {
  53457. var itemLayout = data.getItemLayout(newIdx);
  53458. var symbolEl = createNormalBox(itemLayout, data, newIdx, constDim, true);
  53459. data.setItemGraphicEl(newIdx, symbolEl);
  53460. group.add(symbolEl);
  53461. }
  53462. })
  53463. .update(function (newIdx, oldIdx) {
  53464. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  53465. // Empty data
  53466. if (!data.hasValue(newIdx)) {
  53467. group.remove(symbolEl);
  53468. return;
  53469. }
  53470. var itemLayout = data.getItemLayout(newIdx);
  53471. if (!symbolEl) {
  53472. symbolEl = createNormalBox(itemLayout, data, newIdx, constDim);
  53473. }
  53474. else {
  53475. updateNormalBoxData(itemLayout, symbolEl, data, newIdx);
  53476. }
  53477. group.add(symbolEl);
  53478. data.setItemGraphicEl(newIdx, symbolEl);
  53479. })
  53480. .remove(function (oldIdx) {
  53481. var el = oldData.getItemGraphicEl(oldIdx);
  53482. el && group.remove(el);
  53483. })
  53484. .execute();
  53485. this._data = data;
  53486. },
  53487. remove: function (ecModel) {
  53488. var group = this.group;
  53489. var data = this._data;
  53490. this._data = null;
  53491. data && data.eachItemGraphicEl(function (el) {
  53492. el && group.remove(el);
  53493. });
  53494. },
  53495. dispose: noop
  53496. });
  53497. var BoxPath = Path.extend({
  53498. type: 'boxplotBoxPath',
  53499. shape: {},
  53500. buildPath: function (ctx, shape) {
  53501. var ends = shape.points;
  53502. var i = 0;
  53503. ctx.moveTo(ends[i][0], ends[i][1]);
  53504. i++;
  53505. for (; i < 4; i++) {
  53506. ctx.lineTo(ends[i][0], ends[i][1]);
  53507. }
  53508. ctx.closePath();
  53509. for (; i < ends.length; i++) {
  53510. ctx.moveTo(ends[i][0], ends[i][1]);
  53511. i++;
  53512. ctx.lineTo(ends[i][0], ends[i][1]);
  53513. }
  53514. }
  53515. });
  53516. function createNormalBox(itemLayout, data, dataIndex, constDim, isInit) {
  53517. var ends = itemLayout.ends;
  53518. var el = new BoxPath({
  53519. shape: {
  53520. points: isInit
  53521. ? transInit(ends, constDim, itemLayout)
  53522. : ends
  53523. }
  53524. });
  53525. updateNormalBoxData(itemLayout, el, data, dataIndex, isInit);
  53526. return el;
  53527. }
  53528. function updateNormalBoxData(itemLayout, el, data, dataIndex, isInit) {
  53529. var seriesModel = data.hostModel;
  53530. var updateMethod = graphic[isInit ? 'initProps' : 'updateProps'];
  53531. updateMethod(
  53532. el,
  53533. {shape: {points: itemLayout.ends}},
  53534. seriesModel,
  53535. dataIndex
  53536. );
  53537. var itemModel = data.getItemModel(dataIndex);
  53538. var normalItemStyleModel = itemModel.getModel(NORMAL_ITEM_STYLE_PATH);
  53539. var borderColor = data.getItemVisual(dataIndex, 'color');
  53540. // Exclude borderColor.
  53541. var itemStyle = normalItemStyleModel.getItemStyle(['borderColor']);
  53542. itemStyle.stroke = borderColor;
  53543. itemStyle.strokeNoScale = true;
  53544. el.useStyle(itemStyle);
  53545. el.z2 = 100;
  53546. var hoverStyle = itemModel.getModel(EMPHASIS_ITEM_STYLE_PATH).getItemStyle();
  53547. setHoverStyle(el, hoverStyle);
  53548. }
  53549. function transInit(points, dim, itemLayout) {
  53550. return map(points, function (point) {
  53551. point = point.slice();
  53552. point[dim] = itemLayout.initBaseline;
  53553. return point;
  53554. });
  53555. }
  53556. /*
  53557. * Licensed to the Apache Software Foundation (ASF) under one
  53558. * or more contributor license agreements. See the NOTICE file
  53559. * distributed with this work for additional information
  53560. * regarding copyright ownership. The ASF licenses this file
  53561. * to you under the Apache License, Version 2.0 (the
  53562. * "License"); you may not use this file except in compliance
  53563. * with the License. You may obtain a copy of the License at
  53564. *
  53565. * http://www.apache.org/licenses/LICENSE-2.0
  53566. *
  53567. * Unless required by applicable law or agreed to in writing,
  53568. * software distributed under the License is distributed on an
  53569. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53570. * KIND, either express or implied. See the License for the
  53571. * specific language governing permissions and limitations
  53572. * under the License.
  53573. */
  53574. var borderColorQuery = ['itemStyle', 'borderColor'];
  53575. var boxplotVisual = function (ecModel, api) {
  53576. var globalColors = ecModel.get('color');
  53577. ecModel.eachRawSeriesByType('boxplot', function (seriesModel) {
  53578. var defaulColor = globalColors[seriesModel.seriesIndex % globalColors.length];
  53579. var data = seriesModel.getData();
  53580. data.setVisual({
  53581. legendSymbol: 'roundRect',
  53582. // Use name 'color' but not 'borderColor' for legend usage and
  53583. // visual coding from other component like dataRange.
  53584. color: seriesModel.get(borderColorQuery) || defaulColor
  53585. });
  53586. // Only visible series has each data be visual encoded
  53587. if (!ecModel.isSeriesFiltered(seriesModel)) {
  53588. data.each(function (idx) {
  53589. var itemModel = data.getItemModel(idx);
  53590. data.setItemVisual(
  53591. idx,
  53592. {color: itemModel.get(borderColorQuery, true)}
  53593. );
  53594. });
  53595. }
  53596. });
  53597. };
  53598. /*
  53599. * Licensed to the Apache Software Foundation (ASF) under one
  53600. * or more contributor license agreements. See the NOTICE file
  53601. * distributed with this work for additional information
  53602. * regarding copyright ownership. The ASF licenses this file
  53603. * to you under the Apache License, Version 2.0 (the
  53604. * "License"); you may not use this file except in compliance
  53605. * with the License. You may obtain a copy of the License at
  53606. *
  53607. * http://www.apache.org/licenses/LICENSE-2.0
  53608. *
  53609. * Unless required by applicable law or agreed to in writing,
  53610. * software distributed under the License is distributed on an
  53611. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53612. * KIND, either express or implied. See the License for the
  53613. * specific language governing permissions and limitations
  53614. * under the License.
  53615. */
  53616. var each$13 = each$1;
  53617. var boxplotLayout = function (ecModel) {
  53618. var groupResult = groupSeriesByAxis(ecModel);
  53619. each$13(groupResult, function (groupItem) {
  53620. var seriesModels = groupItem.seriesModels;
  53621. if (!seriesModels.length) {
  53622. return;
  53623. }
  53624. calculateBase(groupItem);
  53625. each$13(seriesModels, function (seriesModel, idx) {
  53626. layoutSingleSeries(
  53627. seriesModel,
  53628. groupItem.boxOffsetList[idx],
  53629. groupItem.boxWidthList[idx]
  53630. );
  53631. });
  53632. });
  53633. };
  53634. /**
  53635. * Group series by axis.
  53636. */
  53637. function groupSeriesByAxis(ecModel) {
  53638. var result = [];
  53639. var axisList = [];
  53640. ecModel.eachSeriesByType('boxplot', function (seriesModel) {
  53641. var baseAxis = seriesModel.getBaseAxis();
  53642. var idx = indexOf(axisList, baseAxis);
  53643. if (idx < 0) {
  53644. idx = axisList.length;
  53645. axisList[idx] = baseAxis;
  53646. result[idx] = {axis: baseAxis, seriesModels: []};
  53647. }
  53648. result[idx].seriesModels.push(seriesModel);
  53649. });
  53650. return result;
  53651. }
  53652. /**
  53653. * Calculate offset and box width for each series.
  53654. */
  53655. function calculateBase(groupItem) {
  53656. var extent;
  53657. var baseAxis = groupItem.axis;
  53658. var seriesModels = groupItem.seriesModels;
  53659. var seriesCount = seriesModels.length;
  53660. var boxWidthList = groupItem.boxWidthList = [];
  53661. var boxOffsetList = groupItem.boxOffsetList = [];
  53662. var boundList = [];
  53663. var bandWidth;
  53664. if (baseAxis.type === 'category') {
  53665. bandWidth = baseAxis.getBandWidth();
  53666. }
  53667. else {
  53668. var maxDataCount = 0;
  53669. each$13(seriesModels, function (seriesModel) {
  53670. maxDataCount = Math.max(maxDataCount, seriesModel.getData().count());
  53671. });
  53672. extent = baseAxis.getExtent(),
  53673. Math.abs(extent[1] - extent[0]) / maxDataCount;
  53674. }
  53675. each$13(seriesModels, function (seriesModel) {
  53676. var boxWidthBound = seriesModel.get('boxWidth');
  53677. if (!isArray(boxWidthBound)) {
  53678. boxWidthBound = [boxWidthBound, boxWidthBound];
  53679. }
  53680. boundList.push([
  53681. parsePercent$1(boxWidthBound[0], bandWidth) || 0,
  53682. parsePercent$1(boxWidthBound[1], bandWidth) || 0
  53683. ]);
  53684. });
  53685. var availableWidth = bandWidth * 0.8 - 2;
  53686. var boxGap = availableWidth / seriesCount * 0.3;
  53687. var boxWidth = (availableWidth - boxGap * (seriesCount - 1)) / seriesCount;
  53688. var base = boxWidth / 2 - availableWidth / 2;
  53689. each$13(seriesModels, function (seriesModel, idx) {
  53690. boxOffsetList.push(base);
  53691. base += boxGap + boxWidth;
  53692. boxWidthList.push(
  53693. Math.min(Math.max(boxWidth, boundList[idx][0]), boundList[idx][1])
  53694. );
  53695. });
  53696. }
  53697. /**
  53698. * Calculate points location for each series.
  53699. */
  53700. function layoutSingleSeries(seriesModel, offset, boxWidth) {
  53701. var coordSys = seriesModel.coordinateSystem;
  53702. var data = seriesModel.getData();
  53703. var halfWidth = boxWidth / 2;
  53704. var cDimIdx = seriesModel.get('layout') === 'horizontal' ? 0 : 1;
  53705. var vDimIdx = 1 - cDimIdx;
  53706. var coordDims = ['x', 'y'];
  53707. var cDim = data.mapDimension(coordDims[cDimIdx]);
  53708. var vDims = data.mapDimension(coordDims[vDimIdx], true);
  53709. if (cDim == null || vDims.length < 5) {
  53710. return;
  53711. }
  53712. for (var dataIndex = 0; dataIndex < data.count(); dataIndex++) {
  53713. var axisDimVal = data.get(cDim, dataIndex);
  53714. var median = getPoint(axisDimVal, vDims[2], dataIndex);
  53715. var end1 = getPoint(axisDimVal, vDims[0], dataIndex);
  53716. var end2 = getPoint(axisDimVal, vDims[1], dataIndex);
  53717. var end4 = getPoint(axisDimVal, vDims[3], dataIndex);
  53718. var end5 = getPoint(axisDimVal, vDims[4], dataIndex);
  53719. var ends = [];
  53720. addBodyEnd(ends, end2, 0);
  53721. addBodyEnd(ends, end4, 1);
  53722. ends.push(end1, end2, end5, end4);
  53723. layEndLine(ends, end1);
  53724. layEndLine(ends, end5);
  53725. layEndLine(ends, median);
  53726. data.setItemLayout(dataIndex, {
  53727. initBaseline: median[vDimIdx],
  53728. ends: ends
  53729. });
  53730. }
  53731. function getPoint(axisDimVal, dimIdx, dataIndex) {
  53732. var val = data.get(dimIdx, dataIndex);
  53733. var p = [];
  53734. p[cDimIdx] = axisDimVal;
  53735. p[vDimIdx] = val;
  53736. var point;
  53737. if (isNaN(axisDimVal) || isNaN(val)) {
  53738. point = [NaN, NaN];
  53739. }
  53740. else {
  53741. point = coordSys.dataToPoint(p);
  53742. point[cDimIdx] += offset;
  53743. }
  53744. return point;
  53745. }
  53746. function addBodyEnd(ends, point, start) {
  53747. var point1 = point.slice();
  53748. var point2 = point.slice();
  53749. point1[cDimIdx] += halfWidth;
  53750. point2[cDimIdx] -= halfWidth;
  53751. start
  53752. ? ends.push(point1, point2)
  53753. : ends.push(point2, point1);
  53754. }
  53755. function layEndLine(ends, endCenter) {
  53756. var from = endCenter.slice();
  53757. var to = endCenter.slice();
  53758. from[cDimIdx] -= halfWidth;
  53759. to[cDimIdx] += halfWidth;
  53760. ends.push(from, to);
  53761. }
  53762. }
  53763. /*
  53764. * Licensed to the Apache Software Foundation (ASF) under one
  53765. * or more contributor license agreements. See the NOTICE file
  53766. * distributed with this work for additional information
  53767. * regarding copyright ownership. The ASF licenses this file
  53768. * to you under the Apache License, Version 2.0 (the
  53769. * "License"); you may not use this file except in compliance
  53770. * with the License. You may obtain a copy of the License at
  53771. *
  53772. * http://www.apache.org/licenses/LICENSE-2.0
  53773. *
  53774. * Unless required by applicable law or agreed to in writing,
  53775. * software distributed under the License is distributed on an
  53776. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53777. * KIND, either express or implied. See the License for the
  53778. * specific language governing permissions and limitations
  53779. * under the License.
  53780. */
  53781. registerVisual(boxplotVisual);
  53782. registerLayout(boxplotLayout);
  53783. /*
  53784. * Licensed to the Apache Software Foundation (ASF) under one
  53785. * or more contributor license agreements. See the NOTICE file
  53786. * distributed with this work for additional information
  53787. * regarding copyright ownership. The ASF licenses this file
  53788. * to you under the Apache License, Version 2.0 (the
  53789. * "License"); you may not use this file except in compliance
  53790. * with the License. You may obtain a copy of the License at
  53791. *
  53792. * http://www.apache.org/licenses/LICENSE-2.0
  53793. *
  53794. * Unless required by applicable law or agreed to in writing,
  53795. * software distributed under the License is distributed on an
  53796. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53797. * KIND, either express or implied. See the License for the
  53798. * specific language governing permissions and limitations
  53799. * under the License.
  53800. */
  53801. var CandlestickSeries = SeriesModel.extend({
  53802. type: 'series.candlestick',
  53803. dependencies: ['xAxis', 'yAxis', 'grid'],
  53804. /**
  53805. * @readOnly
  53806. */
  53807. defaultValueDimensions: [
  53808. {name: 'open', defaultTooltip: true},
  53809. {name: 'close', defaultTooltip: true},
  53810. {name: 'lowest', defaultTooltip: true},
  53811. {name: 'highest', defaultTooltip: true}
  53812. ],
  53813. /**
  53814. * @type {Array.<string>}
  53815. * @readOnly
  53816. */
  53817. dimensions: null,
  53818. /**
  53819. * @override
  53820. */
  53821. defaultOption: {
  53822. zlevel: 0,
  53823. z: 2,
  53824. coordinateSystem: 'cartesian2d',
  53825. legendHoverLink: true,
  53826. hoverAnimation: true,
  53827. // xAxisIndex: 0,
  53828. // yAxisIndex: 0,
  53829. layout: null, // 'horizontal' or 'vertical'
  53830. itemStyle: {
  53831. color: '#c23531', // 阳线 positive
  53832. color0: '#314656', // 阴线 negative '#c23531', '#314656'
  53833. borderWidth: 1,
  53834. // FIXME
  53835. // ec2中使用的是lineStyle.color 和 lineStyle.color0
  53836. borderColor: '#c23531',
  53837. borderColor0: '#314656'
  53838. },
  53839. emphasis: {
  53840. itemStyle: {
  53841. borderWidth: 2
  53842. }
  53843. },
  53844. barMaxWidth: null,
  53845. barMinWidth: null,
  53846. barWidth: null,
  53847. large: true,
  53848. largeThreshold: 600,
  53849. progressive: 3e3,
  53850. progressiveThreshold: 1e4,
  53851. progressiveChunkMode: 'mod',
  53852. animationUpdate: false,
  53853. animationEasing: 'linear',
  53854. animationDuration: 300
  53855. },
  53856. /**
  53857. * Get dimension for shadow in dataZoom
  53858. * @return {string} dimension name
  53859. */
  53860. getShadowDim: function () {
  53861. return 'open';
  53862. },
  53863. brushSelector: function (dataIndex, data, selectors) {
  53864. var itemLayout = data.getItemLayout(dataIndex);
  53865. return itemLayout && selectors.rect(itemLayout.brushRect);
  53866. }
  53867. });
  53868. mixin(CandlestickSeries, seriesModelMixin, true);
  53869. /*
  53870. * Licensed to the Apache Software Foundation (ASF) under one
  53871. * or more contributor license agreements. See the NOTICE file
  53872. * distributed with this work for additional information
  53873. * regarding copyright ownership. The ASF licenses this file
  53874. * to you under the Apache License, Version 2.0 (the
  53875. * "License"); you may not use this file except in compliance
  53876. * with the License. You may obtain a copy of the License at
  53877. *
  53878. * http://www.apache.org/licenses/LICENSE-2.0
  53879. *
  53880. * Unless required by applicable law or agreed to in writing,
  53881. * software distributed under the License is distributed on an
  53882. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53883. * KIND, either express or implied. See the License for the
  53884. * specific language governing permissions and limitations
  53885. * under the License.
  53886. */
  53887. var NORMAL_ITEM_STYLE_PATH$1 = ['itemStyle'];
  53888. var EMPHASIS_ITEM_STYLE_PATH$1 = ['emphasis', 'itemStyle'];
  53889. var SKIP_PROPS = ['color', 'color0', 'borderColor', 'borderColor0'];
  53890. var CandlestickView = Chart.extend({
  53891. type: 'candlestick',
  53892. render: function (seriesModel, ecModel, api) {
  53893. this._updateDrawMode(seriesModel);
  53894. this._isLargeDraw
  53895. ? this._renderLarge(seriesModel)
  53896. : this._renderNormal(seriesModel);
  53897. },
  53898. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  53899. this._clear();
  53900. this._updateDrawMode(seriesModel);
  53901. },
  53902. incrementalRender: function (params, seriesModel, ecModel, api) {
  53903. this._isLargeDraw
  53904. ? this._incrementalRenderLarge(params, seriesModel)
  53905. : this._incrementalRenderNormal(params, seriesModel);
  53906. },
  53907. _updateDrawMode: function (seriesModel) {
  53908. var isLargeDraw = seriesModel.pipelineContext.large;
  53909. if (this._isLargeDraw == null || isLargeDraw ^ this._isLargeDraw) {
  53910. this._isLargeDraw = isLargeDraw;
  53911. this._clear();
  53912. }
  53913. },
  53914. _renderNormal: function (seriesModel) {
  53915. var data = seriesModel.getData();
  53916. var oldData = this._data;
  53917. var group = this.group;
  53918. var isSimpleBox = data.getLayout('isSimpleBox');
  53919. // There is no old data only when first rendering or switching from
  53920. // stream mode to normal mode, where previous elements should be removed.
  53921. if (!this._data) {
  53922. group.removeAll();
  53923. }
  53924. data.diff(oldData)
  53925. .add(function (newIdx) {
  53926. if (data.hasValue(newIdx)) {
  53927. var el;
  53928. var itemLayout = data.getItemLayout(newIdx);
  53929. el = createNormalBox$1(itemLayout, newIdx, true);
  53930. initProps(el, {shape: {points: itemLayout.ends}}, seriesModel, newIdx);
  53931. setBoxCommon(el, data, newIdx, isSimpleBox);
  53932. group.add(el);
  53933. data.setItemGraphicEl(newIdx, el);
  53934. }
  53935. })
  53936. .update(function (newIdx, oldIdx) {
  53937. var el = oldData.getItemGraphicEl(oldIdx);
  53938. // Empty data
  53939. if (!data.hasValue(newIdx)) {
  53940. group.remove(el);
  53941. return;
  53942. }
  53943. var itemLayout = data.getItemLayout(newIdx);
  53944. if (!el) {
  53945. el = createNormalBox$1(itemLayout, newIdx);
  53946. }
  53947. else {
  53948. updateProps(el, {shape: {points: itemLayout.ends}}, seriesModel, newIdx);
  53949. }
  53950. setBoxCommon(el, data, newIdx, isSimpleBox);
  53951. group.add(el);
  53952. data.setItemGraphicEl(newIdx, el);
  53953. })
  53954. .remove(function (oldIdx) {
  53955. var el = oldData.getItemGraphicEl(oldIdx);
  53956. el && group.remove(el);
  53957. })
  53958. .execute();
  53959. this._data = data;
  53960. },
  53961. _renderLarge: function (seriesModel) {
  53962. this._clear();
  53963. createLarge$1(seriesModel, this.group);
  53964. },
  53965. _incrementalRenderNormal: function (params, seriesModel) {
  53966. var data = seriesModel.getData();
  53967. var isSimpleBox = data.getLayout('isSimpleBox');
  53968. var dataIndex;
  53969. while ((dataIndex = params.next()) != null) {
  53970. var el;
  53971. var itemLayout = data.getItemLayout(dataIndex);
  53972. el = createNormalBox$1(itemLayout, dataIndex);
  53973. setBoxCommon(el, data, dataIndex, isSimpleBox);
  53974. el.incremental = true;
  53975. this.group.add(el);
  53976. }
  53977. },
  53978. _incrementalRenderLarge: function (params, seriesModel) {
  53979. createLarge$1(seriesModel, this.group, true);
  53980. },
  53981. remove: function (ecModel) {
  53982. this._clear();
  53983. },
  53984. _clear: function () {
  53985. this.group.removeAll();
  53986. this._data = null;
  53987. },
  53988. dispose: noop
  53989. });
  53990. var NormalBoxPath = Path.extend({
  53991. type: 'normalCandlestickBox',
  53992. shape: {},
  53993. buildPath: function (ctx, shape) {
  53994. var ends = shape.points;
  53995. if (this.__simpleBox) {
  53996. ctx.moveTo(ends[4][0], ends[4][1]);
  53997. ctx.lineTo(ends[6][0], ends[6][1]);
  53998. }
  53999. else {
  54000. ctx.moveTo(ends[0][0], ends[0][1]);
  54001. ctx.lineTo(ends[1][0], ends[1][1]);
  54002. ctx.lineTo(ends[2][0], ends[2][1]);
  54003. ctx.lineTo(ends[3][0], ends[3][1]);
  54004. ctx.closePath();
  54005. ctx.moveTo(ends[4][0], ends[4][1]);
  54006. ctx.lineTo(ends[5][0], ends[5][1]);
  54007. ctx.moveTo(ends[6][0], ends[6][1]);
  54008. ctx.lineTo(ends[7][0], ends[7][1]);
  54009. }
  54010. }
  54011. });
  54012. function createNormalBox$1(itemLayout, dataIndex, isInit) {
  54013. var ends = itemLayout.ends;
  54014. return new NormalBoxPath({
  54015. shape: {
  54016. points: isInit
  54017. ? transInit$1(ends, itemLayout)
  54018. : ends
  54019. },
  54020. z2: 100
  54021. });
  54022. }
  54023. function setBoxCommon(el, data, dataIndex, isSimpleBox) {
  54024. var itemModel = data.getItemModel(dataIndex);
  54025. var normalItemStyleModel = itemModel.getModel(NORMAL_ITEM_STYLE_PATH$1);
  54026. var color = data.getItemVisual(dataIndex, 'color');
  54027. var borderColor = data.getItemVisual(dataIndex, 'borderColor') || color;
  54028. // Color must be excluded.
  54029. // Because symbol provide setColor individually to set fill and stroke
  54030. var itemStyle = normalItemStyleModel.getItemStyle(SKIP_PROPS);
  54031. el.useStyle(itemStyle);
  54032. el.style.strokeNoScale = true;
  54033. el.style.fill = color;
  54034. el.style.stroke = borderColor;
  54035. el.__simpleBox = isSimpleBox;
  54036. var hoverStyle = itemModel.getModel(EMPHASIS_ITEM_STYLE_PATH$1).getItemStyle();
  54037. setHoverStyle(el, hoverStyle);
  54038. }
  54039. function transInit$1(points, itemLayout) {
  54040. return map(points, function (point) {
  54041. point = point.slice();
  54042. point[1] = itemLayout.initBaseline;
  54043. return point;
  54044. });
  54045. }
  54046. var LargeBoxPath = Path.extend({
  54047. type: 'largeCandlestickBox',
  54048. shape: {},
  54049. buildPath: function (ctx, shape) {
  54050. // Drawing lines is more efficient than drawing
  54051. // a whole line or drawing rects.
  54052. var points = shape.points;
  54053. for (var i = 0; i < points.length;) {
  54054. if (this.__sign === points[i++]) {
  54055. var x = points[i++];
  54056. ctx.moveTo(x, points[i++]);
  54057. ctx.lineTo(x, points[i++]);
  54058. }
  54059. else {
  54060. i += 3;
  54061. }
  54062. }
  54063. }
  54064. });
  54065. function createLarge$1(seriesModel, group, incremental) {
  54066. var data = seriesModel.getData();
  54067. var largePoints = data.getLayout('largePoints');
  54068. var elP = new LargeBoxPath({
  54069. shape: {points: largePoints},
  54070. __sign: 1
  54071. });
  54072. group.add(elP);
  54073. var elN = new LargeBoxPath({
  54074. shape: {points: largePoints},
  54075. __sign: -1
  54076. });
  54077. group.add(elN);
  54078. setLargeStyle$1(1, elP, seriesModel, data);
  54079. setLargeStyle$1(-1, elN, seriesModel, data);
  54080. if (incremental) {
  54081. elP.incremental = true;
  54082. elN.incremental = true;
  54083. }
  54084. }
  54085. function setLargeStyle$1(sign, el, seriesModel, data) {
  54086. var suffix = sign > 0 ? 'P' : 'N';
  54087. var borderColor = data.getVisual('borderColor' + suffix)
  54088. || data.getVisual('color' + suffix);
  54089. // Color must be excluded.
  54090. // Because symbol provide setColor individually to set fill and stroke
  54091. var itemStyle = seriesModel.getModel(NORMAL_ITEM_STYLE_PATH$1).getItemStyle(SKIP_PROPS);
  54092. el.useStyle(itemStyle);
  54093. el.style.fill = null;
  54094. el.style.stroke = borderColor;
  54095. // No different
  54096. // el.style.lineWidth = .5;
  54097. }
  54098. /*
  54099. * Licensed to the Apache Software Foundation (ASF) under one
  54100. * or more contributor license agreements. See the NOTICE file
  54101. * distributed with this work for additional information
  54102. * regarding copyright ownership. The ASF licenses this file
  54103. * to you under the Apache License, Version 2.0 (the
  54104. * "License"); you may not use this file except in compliance
  54105. * with the License. You may obtain a copy of the License at
  54106. *
  54107. * http://www.apache.org/licenses/LICENSE-2.0
  54108. *
  54109. * Unless required by applicable law or agreed to in writing,
  54110. * software distributed under the License is distributed on an
  54111. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54112. * KIND, either express or implied. See the License for the
  54113. * specific language governing permissions and limitations
  54114. * under the License.
  54115. */
  54116. var preprocessor = function (option) {
  54117. if (!option || !isArray(option.series)) {
  54118. return;
  54119. }
  54120. // Translate 'k' to 'candlestick'.
  54121. each$1(option.series, function (seriesItem) {
  54122. if (isObject$1(seriesItem) && seriesItem.type === 'k') {
  54123. seriesItem.type = 'candlestick';
  54124. }
  54125. });
  54126. };
  54127. /*
  54128. * Licensed to the Apache Software Foundation (ASF) under one
  54129. * or more contributor license agreements. See the NOTICE file
  54130. * distributed with this work for additional information
  54131. * regarding copyright ownership. The ASF licenses this file
  54132. * to you under the Apache License, Version 2.0 (the
  54133. * "License"); you may not use this file except in compliance
  54134. * with the License. You may obtain a copy of the License at
  54135. *
  54136. * http://www.apache.org/licenses/LICENSE-2.0
  54137. *
  54138. * Unless required by applicable law or agreed to in writing,
  54139. * software distributed under the License is distributed on an
  54140. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54141. * KIND, either express or implied. See the License for the
  54142. * specific language governing permissions and limitations
  54143. * under the License.
  54144. */
  54145. var positiveBorderColorQuery = ['itemStyle', 'borderColor'];
  54146. var negativeBorderColorQuery = ['itemStyle', 'borderColor0'];
  54147. var positiveColorQuery = ['itemStyle', 'color'];
  54148. var negativeColorQuery = ['itemStyle', 'color0'];
  54149. var candlestickVisual = {
  54150. seriesType: 'candlestick',
  54151. plan: createRenderPlanner(),
  54152. // For legend.
  54153. performRawSeries: true,
  54154. reset: function (seriesModel, ecModel) {
  54155. var data = seriesModel.getData();
  54156. var isLargeRender = seriesModel.pipelineContext.large;
  54157. data.setVisual({
  54158. legendSymbol: 'roundRect',
  54159. colorP: getColor(1, seriesModel),
  54160. colorN: getColor(-1, seriesModel),
  54161. borderColorP: getBorderColor(1, seriesModel),
  54162. borderColorN: getBorderColor(-1, seriesModel)
  54163. });
  54164. // Only visible series has each data be visual encoded
  54165. if (ecModel.isSeriesFiltered(seriesModel)) {
  54166. return;
  54167. }
  54168. return !isLargeRender && {progress: progress};
  54169. function progress(params, data) {
  54170. var dataIndex;
  54171. while ((dataIndex = params.next()) != null) {
  54172. var itemModel = data.getItemModel(dataIndex);
  54173. var sign = data.getItemLayout(dataIndex).sign;
  54174. data.setItemVisual(
  54175. dataIndex,
  54176. {
  54177. color: getColor(sign, itemModel),
  54178. borderColor: getBorderColor(sign, itemModel)
  54179. }
  54180. );
  54181. }
  54182. }
  54183. function getColor(sign, model) {
  54184. return model.get(
  54185. sign > 0 ? positiveColorQuery : negativeColorQuery
  54186. );
  54187. }
  54188. function getBorderColor(sign, model) {
  54189. return model.get(
  54190. sign > 0 ? positiveBorderColorQuery : negativeBorderColorQuery
  54191. );
  54192. }
  54193. }
  54194. };
  54195. /*
  54196. * Licensed to the Apache Software Foundation (ASF) under one
  54197. * or more contributor license agreements. See the NOTICE file
  54198. * distributed with this work for additional information
  54199. * regarding copyright ownership. The ASF licenses this file
  54200. * to you under the Apache License, Version 2.0 (the
  54201. * "License"); you may not use this file except in compliance
  54202. * with the License. You may obtain a copy of the License at
  54203. *
  54204. * http://www.apache.org/licenses/LICENSE-2.0
  54205. *
  54206. * Unless required by applicable law or agreed to in writing,
  54207. * software distributed under the License is distributed on an
  54208. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54209. * KIND, either express or implied. See the License for the
  54210. * specific language governing permissions and limitations
  54211. * under the License.
  54212. */
  54213. /* global Float32Array */
  54214. var LargeArr$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  54215. var candlestickLayout = {
  54216. seriesType: 'candlestick',
  54217. plan: createRenderPlanner(),
  54218. reset: function (seriesModel) {
  54219. var coordSys = seriesModel.coordinateSystem;
  54220. var data = seriesModel.getData();
  54221. var candleWidth = calculateCandleWidth(seriesModel, data);
  54222. var cDimIdx = 0;
  54223. var vDimIdx = 1;
  54224. var coordDims = ['x', 'y'];
  54225. var cDim = data.mapDimension(coordDims[cDimIdx]);
  54226. var vDims = data.mapDimension(coordDims[vDimIdx], true);
  54227. var openDim = vDims[0];
  54228. var closeDim = vDims[1];
  54229. var lowestDim = vDims[2];
  54230. var highestDim = vDims[3];
  54231. data.setLayout({
  54232. candleWidth: candleWidth,
  54233. // The value is experimented visually.
  54234. isSimpleBox: candleWidth <= 1.3
  54235. });
  54236. if (cDim == null || vDims.length < 4) {
  54237. return;
  54238. }
  54239. return {
  54240. progress: seriesModel.pipelineContext.large
  54241. ? largeProgress : normalProgress
  54242. };
  54243. function normalProgress(params, data) {
  54244. var dataIndex;
  54245. while ((dataIndex = params.next()) != null) {
  54246. var axisDimVal = data.get(cDim, dataIndex);
  54247. var openVal = data.get(openDim, dataIndex);
  54248. var closeVal = data.get(closeDim, dataIndex);
  54249. var lowestVal = data.get(lowestDim, dataIndex);
  54250. var highestVal = data.get(highestDim, dataIndex);
  54251. var ocLow = Math.min(openVal, closeVal);
  54252. var ocHigh = Math.max(openVal, closeVal);
  54253. var ocLowPoint = getPoint(ocLow, axisDimVal);
  54254. var ocHighPoint = getPoint(ocHigh, axisDimVal);
  54255. var lowestPoint = getPoint(lowestVal, axisDimVal);
  54256. var highestPoint = getPoint(highestVal, axisDimVal);
  54257. var ends = [];
  54258. addBodyEnd(ends, ocHighPoint, 0);
  54259. addBodyEnd(ends, ocLowPoint, 1);
  54260. ends.push(
  54261. subPixelOptimizePoint(highestPoint),
  54262. subPixelOptimizePoint(ocHighPoint),
  54263. subPixelOptimizePoint(lowestPoint),
  54264. subPixelOptimizePoint(ocLowPoint)
  54265. );
  54266. data.setItemLayout(dataIndex, {
  54267. sign: getSign(data, dataIndex, openVal, closeVal, closeDim),
  54268. initBaseline: openVal > closeVal
  54269. ? ocHighPoint[vDimIdx] : ocLowPoint[vDimIdx], // open point.
  54270. ends: ends,
  54271. brushRect: makeBrushRect(lowestVal, highestVal, axisDimVal)
  54272. });
  54273. }
  54274. function getPoint(val, axisDimVal) {
  54275. var p = [];
  54276. p[cDimIdx] = axisDimVal;
  54277. p[vDimIdx] = val;
  54278. return (isNaN(axisDimVal) || isNaN(val))
  54279. ? [NaN, NaN]
  54280. : coordSys.dataToPoint(p);
  54281. }
  54282. function addBodyEnd(ends, point, start) {
  54283. var point1 = point.slice();
  54284. var point2 = point.slice();
  54285. point1[cDimIdx] = subPixelOptimize(
  54286. point1[cDimIdx] + candleWidth / 2, 1, false
  54287. );
  54288. point2[cDimIdx] = subPixelOptimize(
  54289. point2[cDimIdx] - candleWidth / 2, 1, true
  54290. );
  54291. start
  54292. ? ends.push(point1, point2)
  54293. : ends.push(point2, point1);
  54294. }
  54295. function makeBrushRect(lowestVal, highestVal, axisDimVal) {
  54296. var pmin = getPoint(lowestVal, axisDimVal);
  54297. var pmax = getPoint(highestVal, axisDimVal);
  54298. pmin[cDimIdx] -= candleWidth / 2;
  54299. pmax[cDimIdx] -= candleWidth / 2;
  54300. return {
  54301. x: pmin[0],
  54302. y: pmin[1],
  54303. width: vDimIdx ? candleWidth : pmax[0] - pmin[0],
  54304. height: vDimIdx ? pmax[1] - pmin[1] : candleWidth
  54305. };
  54306. }
  54307. function subPixelOptimizePoint(point) {
  54308. point[cDimIdx] = subPixelOptimize(point[cDimIdx], 1);
  54309. return point;
  54310. }
  54311. }
  54312. function largeProgress(params, data) {
  54313. // Structure: [sign, x, yhigh, ylow, sign, x, yhigh, ylow, ...]
  54314. var points = new LargeArr$1(params.count * 5);
  54315. var offset = 0;
  54316. var point;
  54317. var tmpIn = [];
  54318. var tmpOut = [];
  54319. var dataIndex;
  54320. while ((dataIndex = params.next()) != null) {
  54321. var axisDimVal = data.get(cDim, dataIndex);
  54322. var openVal = data.get(openDim, dataIndex);
  54323. var closeVal = data.get(closeDim, dataIndex);
  54324. var lowestVal = data.get(lowestDim, dataIndex);
  54325. var highestVal = data.get(highestDim, dataIndex);
  54326. if (isNaN(axisDimVal) || isNaN(lowestVal) || isNaN(highestVal)) {
  54327. points[offset++] = NaN;
  54328. offset += 4;
  54329. continue;
  54330. }
  54331. points[offset++] = getSign(data, dataIndex, openVal, closeVal, closeDim);
  54332. tmpIn[cDimIdx] = axisDimVal;
  54333. tmpIn[vDimIdx] = lowestVal;
  54334. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  54335. points[offset++] = point ? point[0] : NaN;
  54336. points[offset++] = point ? point[1] : NaN;
  54337. tmpIn[vDimIdx] = highestVal;
  54338. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  54339. points[offset++] = point ? point[1] : NaN;
  54340. }
  54341. data.setLayout('largePoints', points);
  54342. }
  54343. }
  54344. };
  54345. function getSign(data, dataIndex, openVal, closeVal, closeDim) {
  54346. var sign;
  54347. if (openVal > closeVal) {
  54348. sign = -1;
  54349. }
  54350. else if (openVal < closeVal) {
  54351. sign = 1;
  54352. }
  54353. else {
  54354. sign = dataIndex > 0
  54355. // If close === open, compare with close of last record
  54356. ? (data.get(closeDim, dataIndex - 1) <= closeVal ? 1 : -1)
  54357. // No record of previous, set to be positive
  54358. : 1;
  54359. }
  54360. return sign;
  54361. }
  54362. function calculateCandleWidth(seriesModel, data) {
  54363. var baseAxis = seriesModel.getBaseAxis();
  54364. var extent;
  54365. var bandWidth = baseAxis.type === 'category'
  54366. ? baseAxis.getBandWidth()
  54367. : (
  54368. extent = baseAxis.getExtent(),
  54369. Math.abs(extent[1] - extent[0]) / data.count()
  54370. );
  54371. var barMaxWidth = parsePercent$1(
  54372. retrieve2(seriesModel.get('barMaxWidth'), bandWidth),
  54373. bandWidth
  54374. );
  54375. var barMinWidth = parsePercent$1(
  54376. retrieve2(seriesModel.get('barMinWidth'), 1),
  54377. bandWidth
  54378. );
  54379. var barWidth = seriesModel.get('barWidth');
  54380. return barWidth != null
  54381. ? parsePercent$1(barWidth, bandWidth)
  54382. // Put max outer to ensure bar visible in spite of overlap.
  54383. : Math.max(Math.min(bandWidth / 2, barMaxWidth), barMinWidth);
  54384. }
  54385. /*
  54386. * Licensed to the Apache Software Foundation (ASF) under one
  54387. * or more contributor license agreements. See the NOTICE file
  54388. * distributed with this work for additional information
  54389. * regarding copyright ownership. The ASF licenses this file
  54390. * to you under the Apache License, Version 2.0 (the
  54391. * "License"); you may not use this file except in compliance
  54392. * with the License. You may obtain a copy of the License at
  54393. *
  54394. * http://www.apache.org/licenses/LICENSE-2.0
  54395. *
  54396. * Unless required by applicable law or agreed to in writing,
  54397. * software distributed under the License is distributed on an
  54398. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54399. * KIND, either express or implied. See the License for the
  54400. * specific language governing permissions and limitations
  54401. * under the License.
  54402. */
  54403. registerPreprocessor(preprocessor);
  54404. registerVisual(candlestickVisual);
  54405. registerLayout(candlestickLayout);
  54406. /*
  54407. * Licensed to the Apache Software Foundation (ASF) under one
  54408. * or more contributor license agreements. See the NOTICE file
  54409. * distributed with this work for additional information
  54410. * regarding copyright ownership. The ASF licenses this file
  54411. * to you under the Apache License, Version 2.0 (the
  54412. * "License"); you may not use this file except in compliance
  54413. * with the License. You may obtain a copy of the License at
  54414. *
  54415. * http://www.apache.org/licenses/LICENSE-2.0
  54416. *
  54417. * Unless required by applicable law or agreed to in writing,
  54418. * software distributed under the License is distributed on an
  54419. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54420. * KIND, either express or implied. See the License for the
  54421. * specific language governing permissions and limitations
  54422. * under the License.
  54423. */
  54424. SeriesModel.extend({
  54425. type: 'series.effectScatter',
  54426. dependencies: ['grid', 'polar'],
  54427. getInitialData: function (option, ecModel) {
  54428. return createListFromArray(this.getSource(), this);
  54429. },
  54430. brushSelector: 'point',
  54431. defaultOption: {
  54432. coordinateSystem: 'cartesian2d',
  54433. zlevel: 0,
  54434. z: 2,
  54435. legendHoverLink: true,
  54436. effectType: 'ripple',
  54437. progressive: 0,
  54438. // When to show the effect, option: 'render'|'emphasis'
  54439. showEffectOn: 'render',
  54440. // Ripple effect config
  54441. rippleEffect: {
  54442. period: 4,
  54443. // Scale of ripple
  54444. scale: 2.5,
  54445. // Brush type can be fill or stroke
  54446. brushType: 'fill'
  54447. },
  54448. // Cartesian coordinate system
  54449. // xAxisIndex: 0,
  54450. // yAxisIndex: 0,
  54451. // Polar coordinate system
  54452. // polarIndex: 0,
  54453. // Geo coordinate system
  54454. // geoIndex: 0,
  54455. // symbol: null, // 图形类型
  54456. symbolSize: 10 // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  54457. // symbolRotate: null, // 图形旋转控制
  54458. // large: false,
  54459. // Available when large is true
  54460. // largeThreshold: 2000,
  54461. // itemStyle: {
  54462. // opacity: 1
  54463. // }
  54464. }
  54465. });
  54466. /*
  54467. * Licensed to the Apache Software Foundation (ASF) under one
  54468. * or more contributor license agreements. See the NOTICE file
  54469. * distributed with this work for additional information
  54470. * regarding copyright ownership. The ASF licenses this file
  54471. * to you under the Apache License, Version 2.0 (the
  54472. * "License"); you may not use this file except in compliance
  54473. * with the License. You may obtain a copy of the License at
  54474. *
  54475. * http://www.apache.org/licenses/LICENSE-2.0
  54476. *
  54477. * Unless required by applicable law or agreed to in writing,
  54478. * software distributed under the License is distributed on an
  54479. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54480. * KIND, either express or implied. See the License for the
  54481. * specific language governing permissions and limitations
  54482. * under the License.
  54483. */
  54484. /**
  54485. * Symbol with ripple effect
  54486. * @module echarts/chart/helper/EffectSymbol
  54487. */
  54488. var EFFECT_RIPPLE_NUMBER = 3;
  54489. function normalizeSymbolSize$1(symbolSize) {
  54490. if (!isArray(symbolSize)) {
  54491. symbolSize = [+symbolSize, +symbolSize];
  54492. }
  54493. return symbolSize;
  54494. }
  54495. function updateRipplePath(rippleGroup, effectCfg) {
  54496. rippleGroup.eachChild(function (ripplePath) {
  54497. ripplePath.attr({
  54498. z: effectCfg.z,
  54499. zlevel: effectCfg.zlevel,
  54500. style: {
  54501. stroke: effectCfg.brushType === 'stroke' ? effectCfg.color : null,
  54502. fill: effectCfg.brushType === 'fill' ? effectCfg.color : null
  54503. }
  54504. });
  54505. });
  54506. }
  54507. /**
  54508. * @constructor
  54509. * @param {module:echarts/data/List} data
  54510. * @param {number} idx
  54511. * @extends {module:zrender/graphic/Group}
  54512. */
  54513. function EffectSymbol(data, idx) {
  54514. Group.call(this);
  54515. var symbol = new SymbolClz$1(data, idx);
  54516. var rippleGroup = new Group();
  54517. this.add(symbol);
  54518. this.add(rippleGroup);
  54519. rippleGroup.beforeUpdate = function () {
  54520. this.attr(symbol.getScale());
  54521. };
  54522. this.updateData(data, idx);
  54523. }
  54524. var effectSymbolProto = EffectSymbol.prototype;
  54525. effectSymbolProto.stopEffectAnimation = function () {
  54526. this.childAt(1).removeAll();
  54527. };
  54528. effectSymbolProto.startEffectAnimation = function (effectCfg) {
  54529. var symbolType = effectCfg.symbolType;
  54530. var color = effectCfg.color;
  54531. var rippleGroup = this.childAt(1);
  54532. for (var i = 0; i < EFFECT_RIPPLE_NUMBER; i++) {
  54533. // var ripplePath = createSymbol(
  54534. // symbolType, -0.5, -0.5, 1, 1, color
  54535. // );
  54536. // If width/height are set too small (e.g., set to 1) on ios10
  54537. // and macOS Sierra, a circle stroke become a rect, no matter what
  54538. // the scale is set. So we set width/height as 2. See #4136.
  54539. var ripplePath = createSymbol(
  54540. symbolType, -1, -1, 2, 2, color
  54541. );
  54542. ripplePath.attr({
  54543. style: {
  54544. strokeNoScale: true
  54545. },
  54546. z2: 99,
  54547. silent: true,
  54548. scale: [0.5, 0.5]
  54549. });
  54550. var delay = -i / EFFECT_RIPPLE_NUMBER * effectCfg.period + effectCfg.effectOffset;
  54551. // TODO Configurable effectCfg.period
  54552. ripplePath.animate('', true)
  54553. .when(effectCfg.period, {
  54554. scale: [effectCfg.rippleScale / 2, effectCfg.rippleScale / 2]
  54555. })
  54556. .delay(delay)
  54557. .start();
  54558. ripplePath.animateStyle(true)
  54559. .when(effectCfg.period, {
  54560. opacity: 0
  54561. })
  54562. .delay(delay)
  54563. .start();
  54564. rippleGroup.add(ripplePath);
  54565. }
  54566. updateRipplePath(rippleGroup, effectCfg);
  54567. };
  54568. /**
  54569. * Update effect symbol
  54570. */
  54571. effectSymbolProto.updateEffectAnimation = function (effectCfg) {
  54572. var oldEffectCfg = this._effectCfg;
  54573. var rippleGroup = this.childAt(1);
  54574. // Must reinitialize effect if following configuration changed
  54575. var DIFFICULT_PROPS = ['symbolType', 'period', 'rippleScale'];
  54576. for (var i = 0; i < DIFFICULT_PROPS.length; i++) {
  54577. var propName = DIFFICULT_PROPS[i];
  54578. if (oldEffectCfg[propName] !== effectCfg[propName]) {
  54579. this.stopEffectAnimation();
  54580. this.startEffectAnimation(effectCfg);
  54581. return;
  54582. }
  54583. }
  54584. updateRipplePath(rippleGroup, effectCfg);
  54585. };
  54586. /**
  54587. * Highlight symbol
  54588. */
  54589. effectSymbolProto.highlight = function () {
  54590. this.trigger('emphasis');
  54591. };
  54592. /**
  54593. * Downplay symbol
  54594. */
  54595. effectSymbolProto.downplay = function () {
  54596. this.trigger('normal');
  54597. };
  54598. /**
  54599. * Update symbol properties
  54600. * @param {module:echarts/data/List} data
  54601. * @param {number} idx
  54602. */
  54603. effectSymbolProto.updateData = function (data, idx) {
  54604. var seriesModel = data.hostModel;
  54605. this.childAt(0).updateData(data, idx);
  54606. var rippleGroup = this.childAt(1);
  54607. var itemModel = data.getItemModel(idx);
  54608. var symbolType = data.getItemVisual(idx, 'symbol');
  54609. var symbolSize = normalizeSymbolSize$1(data.getItemVisual(idx, 'symbolSize'));
  54610. var color = data.getItemVisual(idx, 'color');
  54611. rippleGroup.attr('scale', symbolSize);
  54612. rippleGroup.traverse(function (ripplePath) {
  54613. ripplePath.attr({
  54614. fill: color
  54615. });
  54616. });
  54617. var symbolOffset = itemModel.getShallow('symbolOffset');
  54618. if (symbolOffset) {
  54619. var pos = rippleGroup.position;
  54620. pos[0] = parsePercent$1(symbolOffset[0], symbolSize[0]);
  54621. pos[1] = parsePercent$1(symbolOffset[1], symbolSize[1]);
  54622. }
  54623. rippleGroup.rotation = (itemModel.getShallow('symbolRotate') || 0) * Math.PI / 180 || 0;
  54624. var effectCfg = {};
  54625. effectCfg.showEffectOn = seriesModel.get('showEffectOn');
  54626. effectCfg.rippleScale = itemModel.get('rippleEffect.scale');
  54627. effectCfg.brushType = itemModel.get('rippleEffect.brushType');
  54628. effectCfg.period = itemModel.get('rippleEffect.period') * 1000;
  54629. effectCfg.effectOffset = idx / data.count();
  54630. effectCfg.z = itemModel.getShallow('z') || 0;
  54631. effectCfg.zlevel = itemModel.getShallow('zlevel') || 0;
  54632. effectCfg.symbolType = symbolType;
  54633. effectCfg.color = color;
  54634. this.off('mouseover').off('mouseout').off('emphasis').off('normal');
  54635. if (effectCfg.showEffectOn === 'render') {
  54636. this._effectCfg
  54637. ? this.updateEffectAnimation(effectCfg)
  54638. : this.startEffectAnimation(effectCfg);
  54639. this._effectCfg = effectCfg;
  54640. }
  54641. else {
  54642. // Not keep old effect config
  54643. this._effectCfg = null;
  54644. this.stopEffectAnimation();
  54645. var symbol = this.childAt(0);
  54646. var onEmphasis = function () {
  54647. symbol.highlight();
  54648. if (effectCfg.showEffectOn !== 'render') {
  54649. this.startEffectAnimation(effectCfg);
  54650. }
  54651. };
  54652. var onNormal = function () {
  54653. symbol.downplay();
  54654. if (effectCfg.showEffectOn !== 'render') {
  54655. this.stopEffectAnimation();
  54656. }
  54657. };
  54658. this.on('mouseover', onEmphasis, this)
  54659. .on('mouseout', onNormal, this)
  54660. .on('emphasis', onEmphasis, this)
  54661. .on('normal', onNormal, this);
  54662. }
  54663. this._effectCfg = effectCfg;
  54664. };
  54665. effectSymbolProto.fadeOut = function (cb) {
  54666. this.off('mouseover').off('mouseout').off('emphasis').off('normal');
  54667. cb && cb();
  54668. };
  54669. inherits(EffectSymbol, Group);
  54670. /*
  54671. * Licensed to the Apache Software Foundation (ASF) under one
  54672. * or more contributor license agreements. See the NOTICE file
  54673. * distributed with this work for additional information
  54674. * regarding copyright ownership. The ASF licenses this file
  54675. * to you under the Apache License, Version 2.0 (the
  54676. * "License"); you may not use this file except in compliance
  54677. * with the License. You may obtain a copy of the License at
  54678. *
  54679. * http://www.apache.org/licenses/LICENSE-2.0
  54680. *
  54681. * Unless required by applicable law or agreed to in writing,
  54682. * software distributed under the License is distributed on an
  54683. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54684. * KIND, either express or implied. See the License for the
  54685. * specific language governing permissions and limitations
  54686. * under the License.
  54687. */
  54688. extendChartView({
  54689. type: 'effectScatter',
  54690. init: function () {
  54691. this._symbolDraw = new SymbolDraw(EffectSymbol);
  54692. },
  54693. render: function (seriesModel, ecModel, api) {
  54694. var data = seriesModel.getData();
  54695. var effectSymbolDraw = this._symbolDraw;
  54696. effectSymbolDraw.updateData(data);
  54697. this.group.add(effectSymbolDraw.group);
  54698. },
  54699. updateTransform: function (seriesModel, ecModel, api) {
  54700. var data = seriesModel.getData();
  54701. this.group.dirty();
  54702. var res = pointsLayout().reset(seriesModel);
  54703. if (res.progress) {
  54704. res.progress({ start: 0, end: data.count() }, data);
  54705. }
  54706. this._symbolDraw.updateLayout(data);
  54707. },
  54708. _updateGroupTransform: function (seriesModel) {
  54709. var coordSys = seriesModel.coordinateSystem;
  54710. if (coordSys && coordSys.getRoamTransform) {
  54711. this.group.transform = clone$2(coordSys.getRoamTransform());
  54712. this.group.decomposeTransform();
  54713. }
  54714. },
  54715. remove: function (ecModel, api) {
  54716. this._symbolDraw && this._symbolDraw.remove(api);
  54717. },
  54718. dispose: function () {}
  54719. });
  54720. /*
  54721. * Licensed to the Apache Software Foundation (ASF) under one
  54722. * or more contributor license agreements. See the NOTICE file
  54723. * distributed with this work for additional information
  54724. * regarding copyright ownership. The ASF licenses this file
  54725. * to you under the Apache License, Version 2.0 (the
  54726. * "License"); you may not use this file except in compliance
  54727. * with the License. You may obtain a copy of the License at
  54728. *
  54729. * http://www.apache.org/licenses/LICENSE-2.0
  54730. *
  54731. * Unless required by applicable law or agreed to in writing,
  54732. * software distributed under the License is distributed on an
  54733. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54734. * KIND, either express or implied. See the License for the
  54735. * specific language governing permissions and limitations
  54736. * under the License.
  54737. */
  54738. registerVisual(visualSymbol('effectScatter', 'circle'));
  54739. registerLayout(pointsLayout('effectScatter'));
  54740. /*
  54741. * Licensed to the Apache Software Foundation (ASF) under one
  54742. * or more contributor license agreements. See the NOTICE file
  54743. * distributed with this work for additional information
  54744. * regarding copyright ownership. The ASF licenses this file
  54745. * to you under the Apache License, Version 2.0 (the
  54746. * "License"); you may not use this file except in compliance
  54747. * with the License. You may obtain a copy of the License at
  54748. *
  54749. * http://www.apache.org/licenses/LICENSE-2.0
  54750. *
  54751. * Unless required by applicable law or agreed to in writing,
  54752. * software distributed under the License is distributed on an
  54753. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54754. * KIND, either express or implied. See the License for the
  54755. * specific language governing permissions and limitations
  54756. * under the License.
  54757. */
  54758. /* global Uint32Array, Float64Array, Float32Array */
  54759. var Uint32Arr = typeof Uint32Array === 'undefined' ? Array : Uint32Array;
  54760. var Float64Arr = typeof Float64Array === 'undefined' ? Array : Float64Array;
  54761. function compatEc2(seriesOpt) {
  54762. var data = seriesOpt.data;
  54763. if (data && data[0] && data[0][0] && data[0][0].coord) {
  54764. if (__DEV__) {
  54765. console.warn('Lines data configuration has been changed to'
  54766. + ' { coords:[[1,2],[2,3]] }');
  54767. }
  54768. seriesOpt.data = map(data, function (itemOpt) {
  54769. var coords = [
  54770. itemOpt[0].coord, itemOpt[1].coord
  54771. ];
  54772. var target = {
  54773. coords: coords
  54774. };
  54775. if (itemOpt[0].name) {
  54776. target.fromName = itemOpt[0].name;
  54777. }
  54778. if (itemOpt[1].name) {
  54779. target.toName = itemOpt[1].name;
  54780. }
  54781. return mergeAll([target, itemOpt[0], itemOpt[1]]);
  54782. });
  54783. }
  54784. }
  54785. var LinesSeries = SeriesModel.extend({
  54786. type: 'series.lines',
  54787. dependencies: ['grid', 'polar'],
  54788. visualColorAccessPath: 'lineStyle.color',
  54789. init: function (option) {
  54790. // The input data may be null/undefined.
  54791. option.data = option.data || [];
  54792. // Not using preprocessor because mergeOption may not have series.type
  54793. compatEc2(option);
  54794. var result = this._processFlatCoordsArray(option.data);
  54795. this._flatCoords = result.flatCoords;
  54796. this._flatCoordsOffset = result.flatCoordsOffset;
  54797. if (result.flatCoords) {
  54798. option.data = new Float32Array(result.count);
  54799. }
  54800. LinesSeries.superApply(this, 'init', arguments);
  54801. },
  54802. mergeOption: function (option) {
  54803. // The input data may be null/undefined.
  54804. option.data = option.data || [];
  54805. compatEc2(option);
  54806. if (option.data) {
  54807. // Only update when have option data to merge.
  54808. var result = this._processFlatCoordsArray(option.data);
  54809. this._flatCoords = result.flatCoords;
  54810. this._flatCoordsOffset = result.flatCoordsOffset;
  54811. if (result.flatCoords) {
  54812. option.data = new Float32Array(result.count);
  54813. }
  54814. }
  54815. LinesSeries.superApply(this, 'mergeOption', arguments);
  54816. },
  54817. appendData: function (params) {
  54818. var result = this._processFlatCoordsArray(params.data);
  54819. if (result.flatCoords) {
  54820. if (!this._flatCoords) {
  54821. this._flatCoords = result.flatCoords;
  54822. this._flatCoordsOffset = result.flatCoordsOffset;
  54823. }
  54824. else {
  54825. this._flatCoords = concatArray(this._flatCoords, result.flatCoords);
  54826. this._flatCoordsOffset = concatArray(this._flatCoordsOffset, result.flatCoordsOffset);
  54827. }
  54828. params.data = new Float32Array(result.count);
  54829. }
  54830. this.getRawData().appendData(params.data);
  54831. },
  54832. _getCoordsFromItemModel: function (idx) {
  54833. var itemModel = this.getData().getItemModel(idx);
  54834. var coords = (itemModel.option instanceof Array)
  54835. ? itemModel.option : itemModel.getShallow('coords');
  54836. if (__DEV__) {
  54837. if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
  54838. throw new Error(
  54839. 'Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.'
  54840. );
  54841. }
  54842. }
  54843. return coords;
  54844. },
  54845. getLineCoordsCount: function (idx) {
  54846. if (this._flatCoordsOffset) {
  54847. return this._flatCoordsOffset[idx * 2 + 1];
  54848. }
  54849. else {
  54850. return this._getCoordsFromItemModel(idx).length;
  54851. }
  54852. },
  54853. getLineCoords: function (idx, out) {
  54854. if (this._flatCoordsOffset) {
  54855. var offset = this._flatCoordsOffset[idx * 2];
  54856. var len = this._flatCoordsOffset[idx * 2 + 1];
  54857. for (var i = 0; i < len; i++) {
  54858. out[i] = out[i] || [];
  54859. out[i][0] = this._flatCoords[offset + i * 2];
  54860. out[i][1] = this._flatCoords[offset + i * 2 + 1];
  54861. }
  54862. return len;
  54863. }
  54864. else {
  54865. var coords = this._getCoordsFromItemModel(idx);
  54866. for (var i = 0; i < coords.length; i++) {
  54867. out[i] = out[i] || [];
  54868. out[i][0] = coords[i][0];
  54869. out[i][1] = coords[i][1];
  54870. }
  54871. return coords.length;
  54872. }
  54873. },
  54874. _processFlatCoordsArray: function (data) {
  54875. var startOffset = 0;
  54876. if (this._flatCoords) {
  54877. startOffset = this._flatCoords.length;
  54878. }
  54879. // Stored as a typed array. In format
  54880. // Points Count(2) | x | y | x | y | Points Count(3) | x | y | x | y | x | y |
  54881. if (typeof data[0] === 'number') {
  54882. var len = data.length;
  54883. // Store offset and len of each segment
  54884. var coordsOffsetAndLenStorage = new Uint32Arr(len);
  54885. var coordsStorage = new Float64Arr(len);
  54886. var coordsCursor = 0;
  54887. var offsetCursor = 0;
  54888. var dataCount = 0;
  54889. for (var i = 0; i < len;) {
  54890. dataCount++;
  54891. var count = data[i++];
  54892. // Offset
  54893. coordsOffsetAndLenStorage[offsetCursor++] = coordsCursor + startOffset;
  54894. // Len
  54895. coordsOffsetAndLenStorage[offsetCursor++] = count;
  54896. for (var k = 0; k < count; k++) {
  54897. var x = data[i++];
  54898. var y = data[i++];
  54899. coordsStorage[coordsCursor++] = x;
  54900. coordsStorage[coordsCursor++] = y;
  54901. if (i > len) {
  54902. if (__DEV__) {
  54903. throw new Error('Invalid data format.');
  54904. }
  54905. }
  54906. }
  54907. }
  54908. return {
  54909. flatCoordsOffset: new Uint32Array(coordsOffsetAndLenStorage.buffer, 0, offsetCursor),
  54910. flatCoords: coordsStorage,
  54911. count: dataCount
  54912. };
  54913. }
  54914. return {
  54915. flatCoordsOffset: null,
  54916. flatCoords: null,
  54917. count: data.length
  54918. };
  54919. },
  54920. getInitialData: function (option, ecModel) {
  54921. if (__DEV__) {
  54922. var CoordSys = CoordinateSystemManager.get(option.coordinateSystem);
  54923. if (!CoordSys) {
  54924. throw new Error('Unkown coordinate system ' + option.coordinateSystem);
  54925. }
  54926. }
  54927. var lineData = new List(['value'], this);
  54928. lineData.hasItemOption = false;
  54929. lineData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
  54930. // dataItem is simply coords
  54931. if (dataItem instanceof Array) {
  54932. return NaN;
  54933. }
  54934. else {
  54935. lineData.hasItemOption = true;
  54936. var value = dataItem.value;
  54937. if (value != null) {
  54938. return value instanceof Array ? value[dimIndex] : value;
  54939. }
  54940. }
  54941. });
  54942. return lineData;
  54943. },
  54944. formatTooltip: function (dataIndex) {
  54945. var data = this.getData();
  54946. var itemModel = data.getItemModel(dataIndex);
  54947. var name = itemModel.get('name');
  54948. if (name) {
  54949. return name;
  54950. }
  54951. var fromName = itemModel.get('fromName');
  54952. var toName = itemModel.get('toName');
  54953. var html = [];
  54954. fromName != null && html.push(fromName);
  54955. toName != null && html.push(toName);
  54956. return encodeHTML(html.join(' > '));
  54957. },
  54958. preventIncremental: function () {
  54959. return !!this.get('effect.show');
  54960. },
  54961. getProgressive: function () {
  54962. var progressive = this.option.progressive;
  54963. if (progressive == null) {
  54964. return this.option.large ? 1e4 : this.get('progressive');
  54965. }
  54966. return progressive;
  54967. },
  54968. getProgressiveThreshold: function () {
  54969. var progressiveThreshold = this.option.progressiveThreshold;
  54970. if (progressiveThreshold == null) {
  54971. return this.option.large ? 2e4 : this.get('progressiveThreshold');
  54972. }
  54973. return progressiveThreshold;
  54974. },
  54975. defaultOption: {
  54976. coordinateSystem: 'geo',
  54977. zlevel: 0,
  54978. z: 2,
  54979. legendHoverLink: true,
  54980. hoverAnimation: true,
  54981. // Cartesian coordinate system
  54982. xAxisIndex: 0,
  54983. yAxisIndex: 0,
  54984. symbol: ['none', 'none'],
  54985. symbolSize: [10, 10],
  54986. // Geo coordinate system
  54987. geoIndex: 0,
  54988. effect: {
  54989. show: false,
  54990. period: 4,
  54991. // Animation delay. support callback
  54992. // delay: 0,
  54993. // If move with constant speed px/sec
  54994. // period will be ignored if this property is > 0,
  54995. constantSpeed: 0,
  54996. symbol: 'circle',
  54997. symbolSize: 3,
  54998. loop: true,
  54999. // Length of trail, 0 - 1
  55000. trailLength: 0.2
  55001. // Same with lineStyle.color
  55002. // color
  55003. },
  55004. large: false,
  55005. // Available when large is true
  55006. largeThreshold: 2000,
  55007. // If lines are polyline
  55008. // polyline not support curveness, label, animation
  55009. polyline: false,
  55010. label: {
  55011. show: false,
  55012. position: 'end'
  55013. // distance: 5,
  55014. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  55015. },
  55016. lineStyle: {
  55017. opacity: 0.5
  55018. }
  55019. }
  55020. });
  55021. /*
  55022. * Licensed to the Apache Software Foundation (ASF) under one
  55023. * or more contributor license agreements. See the NOTICE file
  55024. * distributed with this work for additional information
  55025. * regarding copyright ownership. The ASF licenses this file
  55026. * to you under the Apache License, Version 2.0 (the
  55027. * "License"); you may not use this file except in compliance
  55028. * with the License. You may obtain a copy of the License at
  55029. *
  55030. * http://www.apache.org/licenses/LICENSE-2.0
  55031. *
  55032. * Unless required by applicable law or agreed to in writing,
  55033. * software distributed under the License is distributed on an
  55034. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55035. * KIND, either express or implied. See the License for the
  55036. * specific language governing permissions and limitations
  55037. * under the License.
  55038. */
  55039. /**
  55040. * Provide effect for line
  55041. * @module echarts/chart/helper/EffectLine
  55042. */
  55043. /**
  55044. * @constructor
  55045. * @extends {module:zrender/graphic/Group}
  55046. * @alias {module:echarts/chart/helper/Line}
  55047. */
  55048. function EffectLine(lineData, idx, seriesScope) {
  55049. Group.call(this);
  55050. this.add(this.createLine(lineData, idx, seriesScope));
  55051. this._updateEffectSymbol(lineData, idx);
  55052. }
  55053. var effectLineProto = EffectLine.prototype;
  55054. effectLineProto.createLine = function (lineData, idx, seriesScope) {
  55055. return new Line$1(lineData, idx, seriesScope);
  55056. };
  55057. effectLineProto._updateEffectSymbol = function (lineData, idx) {
  55058. var itemModel = lineData.getItemModel(idx);
  55059. var effectModel = itemModel.getModel('effect');
  55060. var size = effectModel.get('symbolSize');
  55061. var symbolType = effectModel.get('symbol');
  55062. if (!isArray(size)) {
  55063. size = [size, size];
  55064. }
  55065. var color = effectModel.get('color') || lineData.getItemVisual(idx, 'color');
  55066. var symbol = this.childAt(1);
  55067. if (this._symbolType !== symbolType) {
  55068. // Remove previous
  55069. this.remove(symbol);
  55070. symbol = createSymbol(
  55071. symbolType, -0.5, -0.5, 1, 1, color
  55072. );
  55073. symbol.z2 = 100;
  55074. symbol.culling = true;
  55075. this.add(symbol);
  55076. }
  55077. // Symbol may be removed if loop is false
  55078. if (!symbol) {
  55079. return;
  55080. }
  55081. // Shadow color is same with color in default
  55082. symbol.setStyle('shadowColor', color);
  55083. symbol.setStyle(effectModel.getItemStyle(['color']));
  55084. symbol.attr('scale', size);
  55085. symbol.setColor(color);
  55086. symbol.attr('scale', size);
  55087. this._symbolType = symbolType;
  55088. this._updateEffectAnimation(lineData, effectModel, idx);
  55089. };
  55090. effectLineProto._updateEffectAnimation = function (lineData, effectModel, idx) {
  55091. var symbol = this.childAt(1);
  55092. if (!symbol) {
  55093. return;
  55094. }
  55095. var self = this;
  55096. var points = lineData.getItemLayout(idx);
  55097. var period = effectModel.get('period') * 1000;
  55098. var loop = effectModel.get('loop');
  55099. var constantSpeed = effectModel.get('constantSpeed');
  55100. var delayExpr = retrieve(effectModel.get('delay'), function (idx) {
  55101. return idx / lineData.count() * period / 3;
  55102. });
  55103. var isDelayFunc = typeof delayExpr === 'function';
  55104. // Ignore when updating
  55105. symbol.ignore = true;
  55106. this.updateAnimationPoints(symbol, points);
  55107. if (constantSpeed > 0) {
  55108. period = this.getLineLength(symbol) / constantSpeed * 1000;
  55109. }
  55110. if (period !== this._period || loop !== this._loop) {
  55111. symbol.stopAnimation();
  55112. var delay = delayExpr;
  55113. if (isDelayFunc) {
  55114. delay = delayExpr(idx);
  55115. }
  55116. if (symbol.__t > 0) {
  55117. delay = -period * symbol.__t;
  55118. }
  55119. symbol.__t = 0;
  55120. var animator = symbol.animate('', loop)
  55121. .when(period, {
  55122. __t: 1
  55123. })
  55124. .delay(delay)
  55125. .during(function () {
  55126. self.updateSymbolPosition(symbol);
  55127. });
  55128. if (!loop) {
  55129. animator.done(function () {
  55130. self.remove(symbol);
  55131. });
  55132. }
  55133. animator.start();
  55134. }
  55135. this._period = period;
  55136. this._loop = loop;
  55137. };
  55138. effectLineProto.getLineLength = function (symbol) {
  55139. // Not so accurate
  55140. return (dist(symbol.__p1, symbol.__cp1)
  55141. + dist(symbol.__cp1, symbol.__p2));
  55142. };
  55143. effectLineProto.updateAnimationPoints = function (symbol, points) {
  55144. symbol.__p1 = points[0];
  55145. symbol.__p2 = points[1];
  55146. symbol.__cp1 = points[2] || [
  55147. (points[0][0] + points[1][0]) / 2,
  55148. (points[0][1] + points[1][1]) / 2
  55149. ];
  55150. };
  55151. effectLineProto.updateData = function (lineData, idx, seriesScope) {
  55152. this.childAt(0).updateData(lineData, idx, seriesScope);
  55153. this._updateEffectSymbol(lineData, idx);
  55154. };
  55155. effectLineProto.updateSymbolPosition = function (symbol) {
  55156. var p1 = symbol.__p1;
  55157. var p2 = symbol.__p2;
  55158. var cp1 = symbol.__cp1;
  55159. var t = symbol.__t;
  55160. var pos = symbol.position;
  55161. var quadraticAt$$1 = quadraticAt;
  55162. var quadraticDerivativeAt$$1 = quadraticDerivativeAt;
  55163. pos[0] = quadraticAt$$1(p1[0], cp1[0], p2[0], t);
  55164. pos[1] = quadraticAt$$1(p1[1], cp1[1], p2[1], t);
  55165. // Tangent
  55166. var tx = quadraticDerivativeAt$$1(p1[0], cp1[0], p2[0], t);
  55167. var ty = quadraticDerivativeAt$$1(p1[1], cp1[1], p2[1], t);
  55168. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  55169. symbol.ignore = false;
  55170. };
  55171. effectLineProto.updateLayout = function (lineData, idx) {
  55172. this.childAt(0).updateLayout(lineData, idx);
  55173. var effectModel = lineData.getItemModel(idx).getModel('effect');
  55174. this._updateEffectAnimation(lineData, effectModel, idx);
  55175. };
  55176. inherits(EffectLine, Group);
  55177. /*
  55178. * Licensed to the Apache Software Foundation (ASF) under one
  55179. * or more contributor license agreements. See the NOTICE file
  55180. * distributed with this work for additional information
  55181. * regarding copyright ownership. The ASF licenses this file
  55182. * to you under the Apache License, Version 2.0 (the
  55183. * "License"); you may not use this file except in compliance
  55184. * with the License. You may obtain a copy of the License at
  55185. *
  55186. * http://www.apache.org/licenses/LICENSE-2.0
  55187. *
  55188. * Unless required by applicable law or agreed to in writing,
  55189. * software distributed under the License is distributed on an
  55190. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55191. * KIND, either express or implied. See the License for the
  55192. * specific language governing permissions and limitations
  55193. * under the License.
  55194. */
  55195. /**
  55196. * @module echarts/chart/helper/Line
  55197. */
  55198. /**
  55199. * @constructor
  55200. * @extends {module:zrender/graphic/Group}
  55201. * @alias {module:echarts/chart/helper/Polyline}
  55202. */
  55203. function Polyline$2(lineData, idx, seriesScope) {
  55204. Group.call(this);
  55205. this._createPolyline(lineData, idx, seriesScope);
  55206. }
  55207. var polylineProto = Polyline$2.prototype;
  55208. polylineProto._createPolyline = function (lineData, idx, seriesScope) {
  55209. // var seriesModel = lineData.hostModel;
  55210. var points = lineData.getItemLayout(idx);
  55211. var line = new Polyline({
  55212. shape: {
  55213. points: points
  55214. }
  55215. });
  55216. this.add(line);
  55217. this._updateCommonStl(lineData, idx, seriesScope);
  55218. };
  55219. polylineProto.updateData = function (lineData, idx, seriesScope) {
  55220. var seriesModel = lineData.hostModel;
  55221. var line = this.childAt(0);
  55222. var target = {
  55223. shape: {
  55224. points: lineData.getItemLayout(idx)
  55225. }
  55226. };
  55227. updateProps(line, target, seriesModel, idx);
  55228. this._updateCommonStl(lineData, idx, seriesScope);
  55229. };
  55230. polylineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  55231. var line = this.childAt(0);
  55232. var itemModel = lineData.getItemModel(idx);
  55233. var visualColor = lineData.getItemVisual(idx, 'color');
  55234. var lineStyle = seriesScope && seriesScope.lineStyle;
  55235. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  55236. if (!seriesScope || lineData.hasItemOption) {
  55237. lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  55238. hoverLineStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
  55239. }
  55240. line.useStyle(defaults(
  55241. {
  55242. strokeNoScale: true,
  55243. fill: 'none',
  55244. stroke: visualColor
  55245. },
  55246. lineStyle
  55247. ));
  55248. line.hoverStyle = hoverLineStyle;
  55249. setHoverStyle(this);
  55250. };
  55251. polylineProto.updateLayout = function (lineData, idx) {
  55252. var polyline = this.childAt(0);
  55253. polyline.setShape('points', lineData.getItemLayout(idx));
  55254. };
  55255. inherits(Polyline$2, Group);
  55256. /*
  55257. * Licensed to the Apache Software Foundation (ASF) under one
  55258. * or more contributor license agreements. See the NOTICE file
  55259. * distributed with this work for additional information
  55260. * regarding copyright ownership. The ASF licenses this file
  55261. * to you under the Apache License, Version 2.0 (the
  55262. * "License"); you may not use this file except in compliance
  55263. * with the License. You may obtain a copy of the License at
  55264. *
  55265. * http://www.apache.org/licenses/LICENSE-2.0
  55266. *
  55267. * Unless required by applicable law or agreed to in writing,
  55268. * software distributed under the License is distributed on an
  55269. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55270. * KIND, either express or implied. See the License for the
  55271. * specific language governing permissions and limitations
  55272. * under the License.
  55273. */
  55274. /**
  55275. * Provide effect for line
  55276. * @module echarts/chart/helper/EffectLine
  55277. */
  55278. /**
  55279. * @constructor
  55280. * @extends {module:echarts/chart/helper/EffectLine}
  55281. * @alias {module:echarts/chart/helper/Polyline}
  55282. */
  55283. function EffectPolyline(lineData, idx, seriesScope) {
  55284. EffectLine.call(this, lineData, idx, seriesScope);
  55285. this._lastFrame = 0;
  55286. this._lastFramePercent = 0;
  55287. }
  55288. var effectPolylineProto = EffectPolyline.prototype;
  55289. // Overwrite
  55290. effectPolylineProto.createLine = function (lineData, idx, seriesScope) {
  55291. return new Polyline$2(lineData, idx, seriesScope);
  55292. };
  55293. // Overwrite
  55294. effectPolylineProto.updateAnimationPoints = function (symbol, points) {
  55295. this._points = points;
  55296. var accLenArr = [0];
  55297. var len$$1 = 0;
  55298. for (var i = 1; i < points.length; i++) {
  55299. var p1 = points[i - 1];
  55300. var p2 = points[i];
  55301. len$$1 += dist(p1, p2);
  55302. accLenArr.push(len$$1);
  55303. }
  55304. if (len$$1 === 0) {
  55305. return;
  55306. }
  55307. for (var i = 0; i < accLenArr.length; i++) {
  55308. accLenArr[i] /= len$$1;
  55309. }
  55310. this._offsets = accLenArr;
  55311. this._length = len$$1;
  55312. };
  55313. // Overwrite
  55314. effectPolylineProto.getLineLength = function (symbol) {
  55315. return this._length;
  55316. };
  55317. // Overwrite
  55318. effectPolylineProto.updateSymbolPosition = function (symbol) {
  55319. var t = symbol.__t;
  55320. var points = this._points;
  55321. var offsets = this._offsets;
  55322. var len$$1 = points.length;
  55323. if (!offsets) {
  55324. // Has length 0
  55325. return;
  55326. }
  55327. var lastFrame = this._lastFrame;
  55328. var frame;
  55329. if (t < this._lastFramePercent) {
  55330. // Start from the next frame
  55331. // PENDING start from lastFrame ?
  55332. var start = Math.min(lastFrame + 1, len$$1 - 1);
  55333. for (frame = start; frame >= 0; frame--) {
  55334. if (offsets[frame] <= t) {
  55335. break;
  55336. }
  55337. }
  55338. // PENDING really need to do this ?
  55339. frame = Math.min(frame, len$$1 - 2);
  55340. }
  55341. else {
  55342. for (var frame = lastFrame; frame < len$$1; frame++) {
  55343. if (offsets[frame] > t) {
  55344. break;
  55345. }
  55346. }
  55347. frame = Math.min(frame - 1, len$$1 - 2);
  55348. }
  55349. lerp(
  55350. symbol.position, points[frame], points[frame + 1],
  55351. (t - offsets[frame]) / (offsets[frame + 1] - offsets[frame])
  55352. );
  55353. var tx = points[frame + 1][0] - points[frame][0];
  55354. var ty = points[frame + 1][1] - points[frame][1];
  55355. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  55356. this._lastFrame = frame;
  55357. this._lastFramePercent = t;
  55358. symbol.ignore = false;
  55359. };
  55360. inherits(EffectPolyline, EffectLine);
  55361. /*
  55362. * Licensed to the Apache Software Foundation (ASF) under one
  55363. * or more contributor license agreements. See the NOTICE file
  55364. * distributed with this work for additional information
  55365. * regarding copyright ownership. The ASF licenses this file
  55366. * to you under the Apache License, Version 2.0 (the
  55367. * "License"); you may not use this file except in compliance
  55368. * with the License. You may obtain a copy of the License at
  55369. *
  55370. * http://www.apache.org/licenses/LICENSE-2.0
  55371. *
  55372. * Unless required by applicable law or agreed to in writing,
  55373. * software distributed under the License is distributed on an
  55374. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55375. * KIND, either express or implied. See the License for the
  55376. * specific language governing permissions and limitations
  55377. * under the License.
  55378. */
  55379. // TODO Batch by color
  55380. var LargeLineShape = extendShape({
  55381. shape: {
  55382. polyline: false,
  55383. curveness: 0,
  55384. segs: []
  55385. },
  55386. buildPath: function (path, shape) {
  55387. var segs = shape.segs;
  55388. var curveness = shape.curveness;
  55389. if (shape.polyline) {
  55390. for (var i = 0; i < segs.length;) {
  55391. var count = segs[i++];
  55392. if (count > 0) {
  55393. path.moveTo(segs[i++], segs[i++]);
  55394. for (var k = 1; k < count; k++) {
  55395. path.lineTo(segs[i++], segs[i++]);
  55396. }
  55397. }
  55398. }
  55399. }
  55400. else {
  55401. for (var i = 0; i < segs.length;) {
  55402. var x0 = segs[i++];
  55403. var y0 = segs[i++];
  55404. var x1 = segs[i++];
  55405. var y1 = segs[i++];
  55406. path.moveTo(x0, y0);
  55407. if (curveness > 0) {
  55408. var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
  55409. var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
  55410. path.quadraticCurveTo(x2, y2, x1, y1);
  55411. }
  55412. else {
  55413. path.lineTo(x1, y1);
  55414. }
  55415. }
  55416. }
  55417. },
  55418. findDataIndex: function (x, y) {
  55419. var shape = this.shape;
  55420. var segs = shape.segs;
  55421. var curveness = shape.curveness;
  55422. if (shape.polyline) {
  55423. var dataIndex = 0;
  55424. for (var i = 0; i < segs.length;) {
  55425. var count = segs[i++];
  55426. if (count > 0) {
  55427. var x0 = segs[i++];
  55428. var y0 = segs[i++];
  55429. for (var k = 1; k < count; k++) {
  55430. var x1 = segs[i++];
  55431. var y1 = segs[i++];
  55432. if (containStroke$1(x0, y0, x1, y1)) {
  55433. return dataIndex;
  55434. }
  55435. }
  55436. }
  55437. dataIndex++;
  55438. }
  55439. }
  55440. else {
  55441. var dataIndex = 0;
  55442. for (var i = 0; i < segs.length;) {
  55443. var x0 = segs[i++];
  55444. var y0 = segs[i++];
  55445. var x1 = segs[i++];
  55446. var y1 = segs[i++];
  55447. if (curveness > 0) {
  55448. var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
  55449. var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
  55450. if (containStroke$3(x0, y0, x2, y2, x1, y1)) {
  55451. return dataIndex;
  55452. }
  55453. }
  55454. else {
  55455. if (containStroke$1(x0, y0, x1, y1)) {
  55456. return dataIndex;
  55457. }
  55458. }
  55459. dataIndex++;
  55460. }
  55461. }
  55462. return -1;
  55463. }
  55464. });
  55465. function LargeLineDraw() {
  55466. this.group = new Group();
  55467. }
  55468. var largeLineProto = LargeLineDraw.prototype;
  55469. largeLineProto.isPersistent = function () {
  55470. return !this._incremental;
  55471. };
  55472. /**
  55473. * Update symbols draw by new data
  55474. * @param {module:echarts/data/List} data
  55475. */
  55476. largeLineProto.updateData = function (data) {
  55477. this.group.removeAll();
  55478. var lineEl = new LargeLineShape({
  55479. rectHover: true,
  55480. cursor: 'default'
  55481. });
  55482. lineEl.setShape({
  55483. segs: data.getLayout('linesPoints')
  55484. });
  55485. this._setCommon(lineEl, data);
  55486. // Add back
  55487. this.group.add(lineEl);
  55488. this._incremental = null;
  55489. };
  55490. /**
  55491. * @override
  55492. */
  55493. largeLineProto.incrementalPrepareUpdate = function (data) {
  55494. this.group.removeAll();
  55495. this._clearIncremental();
  55496. if (data.count() > 5e5) {
  55497. if (!this._incremental) {
  55498. this._incremental = new IncrementalDisplayble({
  55499. silent: true
  55500. });
  55501. }
  55502. this.group.add(this._incremental);
  55503. }
  55504. else {
  55505. this._incremental = null;
  55506. }
  55507. };
  55508. /**
  55509. * @override
  55510. */
  55511. largeLineProto.incrementalUpdate = function (taskParams, data) {
  55512. var lineEl = new LargeLineShape();
  55513. lineEl.setShape({
  55514. segs: data.getLayout('linesPoints')
  55515. });
  55516. this._setCommon(lineEl, data, !!this._incremental);
  55517. if (!this._incremental) {
  55518. lineEl.rectHover = true;
  55519. lineEl.cursor = 'default';
  55520. lineEl.__startIndex = taskParams.start;
  55521. this.group.add(lineEl);
  55522. }
  55523. else {
  55524. this._incremental.addDisplayable(lineEl, true);
  55525. }
  55526. };
  55527. /**
  55528. * @override
  55529. */
  55530. largeLineProto.remove = function () {
  55531. this._clearIncremental();
  55532. this._incremental = null;
  55533. this.group.removeAll();
  55534. };
  55535. largeLineProto._setCommon = function (lineEl, data, isIncremental) {
  55536. var hostModel = data.hostModel;
  55537. lineEl.setShape({
  55538. polyline: hostModel.get('polyline'),
  55539. curveness: hostModel.get('lineStyle.curveness')
  55540. });
  55541. lineEl.useStyle(
  55542. hostModel.getModel('lineStyle').getLineStyle()
  55543. );
  55544. lineEl.style.strokeNoScale = true;
  55545. var visualColor = data.getVisual('color');
  55546. if (visualColor) {
  55547. lineEl.setStyle('stroke', visualColor);
  55548. }
  55549. lineEl.setStyle('fill');
  55550. if (!isIncremental) {
  55551. // Enable tooltip
  55552. // PENDING May have performance issue when path is extremely large
  55553. lineEl.seriesIndex = hostModel.seriesIndex;
  55554. lineEl.on('mousemove', function (e) {
  55555. lineEl.dataIndex = null;
  55556. var dataIndex = lineEl.findDataIndex(e.offsetX, e.offsetY);
  55557. if (dataIndex > 0) {
  55558. // Provide dataIndex for tooltip
  55559. lineEl.dataIndex = dataIndex + lineEl.__startIndex;
  55560. }
  55561. });
  55562. }
  55563. };
  55564. largeLineProto._clearIncremental = function () {
  55565. var incremental = this._incremental;
  55566. if (incremental) {
  55567. incremental.clearDisplaybles();
  55568. }
  55569. };
  55570. /*
  55571. * Licensed to the Apache Software Foundation (ASF) under one
  55572. * or more contributor license agreements. See the NOTICE file
  55573. * distributed with this work for additional information
  55574. * regarding copyright ownership. The ASF licenses this file
  55575. * to you under the Apache License, Version 2.0 (the
  55576. * "License"); you may not use this file except in compliance
  55577. * with the License. You may obtain a copy of the License at
  55578. *
  55579. * http://www.apache.org/licenses/LICENSE-2.0
  55580. *
  55581. * Unless required by applicable law or agreed to in writing,
  55582. * software distributed under the License is distributed on an
  55583. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55584. * KIND, either express or implied. See the License for the
  55585. * specific language governing permissions and limitations
  55586. * under the License.
  55587. */
  55588. /* global Float32Array */
  55589. var linesLayout = {
  55590. seriesType: 'lines',
  55591. plan: createRenderPlanner(),
  55592. reset: function (seriesModel) {
  55593. var coordSys = seriesModel.coordinateSystem;
  55594. var isPolyline = seriesModel.get('polyline');
  55595. var isLarge = seriesModel.pipelineContext.large;
  55596. function progress(params, lineData) {
  55597. var lineCoords = [];
  55598. if (isLarge) {
  55599. var points;
  55600. var segCount = params.end - params.start;
  55601. if (isPolyline) {
  55602. var totalCoordsCount = 0;
  55603. for (var i = params.start; i < params.end; i++) {
  55604. totalCoordsCount += seriesModel.getLineCoordsCount(i);
  55605. }
  55606. points = new Float32Array(segCount + totalCoordsCount * 2);
  55607. }
  55608. else {
  55609. points = new Float32Array(segCount * 4);
  55610. }
  55611. var offset = 0;
  55612. var pt = [];
  55613. for (var i = params.start; i < params.end; i++) {
  55614. var len = seriesModel.getLineCoords(i, lineCoords);
  55615. if (isPolyline) {
  55616. points[offset++] = len;
  55617. }
  55618. for (var k = 0; k < len; k++) {
  55619. pt = coordSys.dataToPoint(lineCoords[k], false, pt);
  55620. points[offset++] = pt[0];
  55621. points[offset++] = pt[1];
  55622. }
  55623. }
  55624. lineData.setLayout('linesPoints', points);
  55625. }
  55626. else {
  55627. for (var i = params.start; i < params.end; i++) {
  55628. var itemModel = lineData.getItemModel(i);
  55629. var len = seriesModel.getLineCoords(i, lineCoords);
  55630. var pts = [];
  55631. if (isPolyline) {
  55632. for (var j = 0; j < len; j++) {
  55633. pts.push(coordSys.dataToPoint(lineCoords[j]));
  55634. }
  55635. }
  55636. else {
  55637. pts[0] = coordSys.dataToPoint(lineCoords[0]);
  55638. pts[1] = coordSys.dataToPoint(lineCoords[1]);
  55639. var curveness = itemModel.get('lineStyle.curveness');
  55640. if (+curveness) {
  55641. pts[2] = [
  55642. (pts[0][0] + pts[1][0]) / 2 - (pts[0][1] - pts[1][1]) * curveness,
  55643. (pts[0][1] + pts[1][1]) / 2 - (pts[1][0] - pts[0][0]) * curveness
  55644. ];
  55645. }
  55646. }
  55647. lineData.setItemLayout(i, pts);
  55648. }
  55649. }
  55650. }
  55651. return { progress: progress };
  55652. }
  55653. };
  55654. /*
  55655. * Licensed to the Apache Software Foundation (ASF) under one
  55656. * or more contributor license agreements. See the NOTICE file
  55657. * distributed with this work for additional information
  55658. * regarding copyright ownership. The ASF licenses this file
  55659. * to you under the Apache License, Version 2.0 (the
  55660. * "License"); you may not use this file except in compliance
  55661. * with the License. You may obtain a copy of the License at
  55662. *
  55663. * http://www.apache.org/licenses/LICENSE-2.0
  55664. *
  55665. * Unless required by applicable law or agreed to in writing,
  55666. * software distributed under the License is distributed on an
  55667. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55668. * KIND, either express or implied. See the License for the
  55669. * specific language governing permissions and limitations
  55670. * under the License.
  55671. */
  55672. extendChartView({
  55673. type: 'lines',
  55674. init: function () {},
  55675. render: function (seriesModel, ecModel, api) {
  55676. var data = seriesModel.getData();
  55677. var lineDraw = this._updateLineDraw(data, seriesModel);
  55678. var zlevel = seriesModel.get('zlevel');
  55679. var trailLength = seriesModel.get('effect.trailLength');
  55680. var zr = api.getZr();
  55681. // Avoid the drag cause ghost shadow
  55682. // FIXME Better way ?
  55683. // SVG doesn't support
  55684. var isSvg = zr.painter.getType() === 'svg';
  55685. if (!isSvg) {
  55686. zr.painter.getLayer(zlevel).clear(true);
  55687. }
  55688. // Config layer with motion blur
  55689. if (this._lastZlevel != null && !isSvg) {
  55690. zr.configLayer(this._lastZlevel, {
  55691. motionBlur: false
  55692. });
  55693. }
  55694. if (this._showEffect(seriesModel) && trailLength) {
  55695. if (__DEV__) {
  55696. var notInIndividual = false;
  55697. ecModel.eachSeries(function (otherSeriesModel) {
  55698. if (otherSeriesModel !== seriesModel && otherSeriesModel.get('zlevel') === zlevel) {
  55699. notInIndividual = true;
  55700. }
  55701. });
  55702. notInIndividual && console.warn('Lines with trail effect should have an individual zlevel');
  55703. }
  55704. if (!isSvg) {
  55705. zr.configLayer(zlevel, {
  55706. motionBlur: true,
  55707. lastFrameAlpha: Math.max(Math.min(trailLength / 10 + 0.9, 1), 0)
  55708. });
  55709. }
  55710. }
  55711. lineDraw.updateData(data);
  55712. this._lastZlevel = zlevel;
  55713. this._finished = true;
  55714. },
  55715. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  55716. var data = seriesModel.getData();
  55717. var lineDraw = this._updateLineDraw(data, seriesModel);
  55718. lineDraw.incrementalPrepareUpdate(data);
  55719. this._clearLayer(api);
  55720. this._finished = false;
  55721. },
  55722. incrementalRender: function (taskParams, seriesModel, ecModel) {
  55723. this._lineDraw.incrementalUpdate(taskParams, seriesModel.getData());
  55724. this._finished = taskParams.end === seriesModel.getData().count();
  55725. },
  55726. updateTransform: function (seriesModel, ecModel, api) {
  55727. var data = seriesModel.getData();
  55728. var pipelineContext = seriesModel.pipelineContext;
  55729. if (!this._finished || pipelineContext.large || pipelineContext.progressiveRender) {
  55730. // TODO Don't have to do update in large mode. Only do it when there are millions of data.
  55731. return {
  55732. update: true
  55733. };
  55734. }
  55735. else {
  55736. // TODO Use same logic with ScatterView.
  55737. // Manually update layout
  55738. var res = linesLayout.reset(seriesModel);
  55739. if (res.progress) {
  55740. res.progress({ start: 0, end: data.count() }, data);
  55741. }
  55742. this._lineDraw.updateLayout();
  55743. this._clearLayer(api);
  55744. }
  55745. },
  55746. _updateLineDraw: function (data, seriesModel) {
  55747. var lineDraw = this._lineDraw;
  55748. var hasEffect = this._showEffect(seriesModel);
  55749. var isPolyline = !!seriesModel.get('polyline');
  55750. var pipelineContext = seriesModel.pipelineContext;
  55751. var isLargeDraw = pipelineContext.large;
  55752. if (__DEV__) {
  55753. if (hasEffect && isLargeDraw) {
  55754. console.warn('Large lines not support effect');
  55755. }
  55756. }
  55757. if (!lineDraw
  55758. || hasEffect !== this._hasEffet
  55759. || isPolyline !== this._isPolyline
  55760. || isLargeDraw !== this._isLargeDraw
  55761. ) {
  55762. if (lineDraw) {
  55763. lineDraw.remove();
  55764. }
  55765. lineDraw = this._lineDraw = isLargeDraw
  55766. ? new LargeLineDraw()
  55767. : new LineDraw(
  55768. isPolyline
  55769. ? (hasEffect ? EffectPolyline : Polyline$2)
  55770. : (hasEffect ? EffectLine : Line$1)
  55771. );
  55772. this._hasEffet = hasEffect;
  55773. this._isPolyline = isPolyline;
  55774. this._isLargeDraw = isLargeDraw;
  55775. this.group.removeAll();
  55776. }
  55777. this.group.add(lineDraw.group);
  55778. return lineDraw;
  55779. },
  55780. _showEffect: function (seriesModel) {
  55781. return !!seriesModel.get('effect.show');
  55782. },
  55783. _clearLayer: function (api) {
  55784. // Not use motion when dragging or zooming
  55785. var zr = api.getZr();
  55786. var isSvg = zr.painter.getType() === 'svg';
  55787. if (!isSvg && this._lastZlevel != null) {
  55788. zr.painter.getLayer(this._lastZlevel).clear(true);
  55789. }
  55790. },
  55791. remove: function (ecModel, api) {
  55792. this._lineDraw && this._lineDraw.remove();
  55793. this._lineDraw = null;
  55794. // Clear motion when lineDraw is removed
  55795. this._clearLayer(api);
  55796. },
  55797. dispose: function () {}
  55798. });
  55799. /*
  55800. * Licensed to the Apache Software Foundation (ASF) under one
  55801. * or more contributor license agreements. See the NOTICE file
  55802. * distributed with this work for additional information
  55803. * regarding copyright ownership. The ASF licenses this file
  55804. * to you under the Apache License, Version 2.0 (the
  55805. * "License"); you may not use this file except in compliance
  55806. * with the License. You may obtain a copy of the License at
  55807. *
  55808. * http://www.apache.org/licenses/LICENSE-2.0
  55809. *
  55810. * Unless required by applicable law or agreed to in writing,
  55811. * software distributed under the License is distributed on an
  55812. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55813. * KIND, either express or implied. See the License for the
  55814. * specific language governing permissions and limitations
  55815. * under the License.
  55816. */
  55817. function normalize$2(a) {
  55818. if (!(a instanceof Array)) {
  55819. a = [a, a];
  55820. }
  55821. return a;
  55822. }
  55823. var opacityQuery = 'lineStyle.opacity'.split('.');
  55824. var linesVisual = {
  55825. seriesType: 'lines',
  55826. reset: function (seriesModel, ecModel, api) {
  55827. var symbolType = normalize$2(seriesModel.get('symbol'));
  55828. var symbolSize = normalize$2(seriesModel.get('symbolSize'));
  55829. var data = seriesModel.getData();
  55830. data.setVisual('fromSymbol', symbolType && symbolType[0]);
  55831. data.setVisual('toSymbol', symbolType && symbolType[1]);
  55832. data.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  55833. data.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  55834. data.setVisual('opacity', seriesModel.get(opacityQuery));
  55835. function dataEach(data, idx) {
  55836. var itemModel = data.getItemModel(idx);
  55837. var symbolType = normalize$2(itemModel.getShallow('symbol', true));
  55838. var symbolSize = normalize$2(itemModel.getShallow('symbolSize', true));
  55839. var opacity = itemModel.get(opacityQuery);
  55840. symbolType[0] && data.setItemVisual(idx, 'fromSymbol', symbolType[0]);
  55841. symbolType[1] && data.setItemVisual(idx, 'toSymbol', symbolType[1]);
  55842. symbolSize[0] && data.setItemVisual(idx, 'fromSymbolSize', symbolSize[0]);
  55843. symbolSize[1] && data.setItemVisual(idx, 'toSymbolSize', symbolSize[1]);
  55844. data.setItemVisual(idx, 'opacity', opacity);
  55845. }
  55846. return {dataEach: data.hasItemOption ? dataEach : null};
  55847. }
  55848. };
  55849. /*
  55850. * Licensed to the Apache Software Foundation (ASF) under one
  55851. * or more contributor license agreements. See the NOTICE file
  55852. * distributed with this work for additional information
  55853. * regarding copyright ownership. The ASF licenses this file
  55854. * to you under the Apache License, Version 2.0 (the
  55855. * "License"); you may not use this file except in compliance
  55856. * with the License. You may obtain a copy of the License at
  55857. *
  55858. * http://www.apache.org/licenses/LICENSE-2.0
  55859. *
  55860. * Unless required by applicable law or agreed to in writing,
  55861. * software distributed under the License is distributed on an
  55862. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55863. * KIND, either express or implied. See the License for the
  55864. * specific language governing permissions and limitations
  55865. * under the License.
  55866. */
  55867. registerLayout(linesLayout);
  55868. registerVisual(linesVisual);
  55869. /*
  55870. * Licensed to the Apache Software Foundation (ASF) under one
  55871. * or more contributor license agreements. See the NOTICE file
  55872. * distributed with this work for additional information
  55873. * regarding copyright ownership. The ASF licenses this file
  55874. * to you under the Apache License, Version 2.0 (the
  55875. * "License"); you may not use this file except in compliance
  55876. * with the License. You may obtain a copy of the License at
  55877. *
  55878. * http://www.apache.org/licenses/LICENSE-2.0
  55879. *
  55880. * Unless required by applicable law or agreed to in writing,
  55881. * software distributed under the License is distributed on an
  55882. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55883. * KIND, either express or implied. See the License for the
  55884. * specific language governing permissions and limitations
  55885. * under the License.
  55886. */
  55887. SeriesModel.extend({
  55888. type: 'series.heatmap',
  55889. getInitialData: function (option, ecModel) {
  55890. return createListFromArray(this.getSource(), this, {
  55891. generateCoord: 'value'
  55892. });
  55893. },
  55894. preventIncremental: function () {
  55895. var coordSysCreator = CoordinateSystemManager.get(this.get('coordinateSystem'));
  55896. if (coordSysCreator && coordSysCreator.dimensions) {
  55897. return coordSysCreator.dimensions[0] === 'lng' && coordSysCreator.dimensions[1] === 'lat';
  55898. }
  55899. },
  55900. defaultOption: {
  55901. // Cartesian2D or geo
  55902. coordinateSystem: 'cartesian2d',
  55903. zlevel: 0,
  55904. z: 2,
  55905. // Cartesian coordinate system
  55906. // xAxisIndex: 0,
  55907. // yAxisIndex: 0,
  55908. // Geo coordinate system
  55909. geoIndex: 0,
  55910. blurSize: 30,
  55911. pointSize: 20,
  55912. maxOpacity: 1,
  55913. minOpacity: 0
  55914. }
  55915. });
  55916. /*
  55917. * Licensed to the Apache Software Foundation (ASF) under one
  55918. * or more contributor license agreements. See the NOTICE file
  55919. * distributed with this work for additional information
  55920. * regarding copyright ownership. The ASF licenses this file
  55921. * to you under the Apache License, Version 2.0 (the
  55922. * "License"); you may not use this file except in compliance
  55923. * with the License. You may obtain a copy of the License at
  55924. *
  55925. * http://www.apache.org/licenses/LICENSE-2.0
  55926. *
  55927. * Unless required by applicable law or agreed to in writing,
  55928. * software distributed under the License is distributed on an
  55929. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55930. * KIND, either express or implied. See the License for the
  55931. * specific language governing permissions and limitations
  55932. * under the License.
  55933. */
  55934. /* global Uint8ClampedArray */
  55935. /**
  55936. * @file defines echarts Heatmap Chart
  55937. * @author Ovilia (me@zhangwenli.com)
  55938. * Inspired by https://github.com/mourner/simpleheat
  55939. *
  55940. * @module
  55941. */
  55942. var GRADIENT_LEVELS = 256;
  55943. /**
  55944. * Heatmap Chart
  55945. *
  55946. * @class
  55947. */
  55948. function Heatmap() {
  55949. var canvas = createCanvas();
  55950. this.canvas = canvas;
  55951. this.blurSize = 30;
  55952. this.pointSize = 20;
  55953. this.maxOpacity = 1;
  55954. this.minOpacity = 0;
  55955. this._gradientPixels = {};
  55956. }
  55957. Heatmap.prototype = {
  55958. /**
  55959. * Renders Heatmap and returns the rendered canvas
  55960. * @param {Array} data array of data, each has x, y, value
  55961. * @param {number} width canvas width
  55962. * @param {number} height canvas height
  55963. */
  55964. update: function (data, width, height, normalize, colorFunc, isInRange) {
  55965. var brush = this._getBrush();
  55966. var gradientInRange = this._getGradient(data, colorFunc, 'inRange');
  55967. var gradientOutOfRange = this._getGradient(data, colorFunc, 'outOfRange');
  55968. var r = this.pointSize + this.blurSize;
  55969. var canvas = this.canvas;
  55970. var ctx = canvas.getContext('2d');
  55971. var len = data.length;
  55972. canvas.width = width;
  55973. canvas.height = height;
  55974. for (var i = 0; i < len; ++i) {
  55975. var p = data[i];
  55976. var x = p[0];
  55977. var y = p[1];
  55978. var value = p[2];
  55979. // calculate alpha using value
  55980. var alpha = normalize(value);
  55981. // draw with the circle brush with alpha
  55982. ctx.globalAlpha = alpha;
  55983. ctx.drawImage(brush, x - r, y - r);
  55984. }
  55985. if (!canvas.width || !canvas.height) {
  55986. // Avoid "Uncaught DOMException: Failed to execute 'getImageData' on
  55987. // 'CanvasRenderingContext2D': The source height is 0."
  55988. return canvas;
  55989. }
  55990. // colorize the canvas using alpha value and set with gradient
  55991. var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  55992. var pixels = imageData.data;
  55993. var offset = 0;
  55994. var pixelLen = pixels.length;
  55995. var minOpacity = this.minOpacity;
  55996. var maxOpacity = this.maxOpacity;
  55997. var diffOpacity = maxOpacity - minOpacity;
  55998. while (offset < pixelLen) {
  55999. var alpha = pixels[offset + 3] / 256;
  56000. var gradientOffset = Math.floor(alpha * (GRADIENT_LEVELS - 1)) * 4;
  56001. // Simple optimize to ignore the empty data
  56002. if (alpha > 0) {
  56003. var gradient = isInRange(alpha) ? gradientInRange : gradientOutOfRange;
  56004. // Any alpha > 0 will be mapped to [minOpacity, maxOpacity]
  56005. alpha > 0 && (alpha = alpha * diffOpacity + minOpacity);
  56006. pixels[offset++] = gradient[gradientOffset];
  56007. pixels[offset++] = gradient[gradientOffset + 1];
  56008. pixels[offset++] = gradient[gradientOffset + 2];
  56009. pixels[offset++] = gradient[gradientOffset + 3] * alpha * 256;
  56010. }
  56011. else {
  56012. offset += 4;
  56013. }
  56014. }
  56015. ctx.putImageData(imageData, 0, 0);
  56016. return canvas;
  56017. },
  56018. /**
  56019. * get canvas of a black circle brush used for canvas to draw later
  56020. * @private
  56021. * @returns {Object} circle brush canvas
  56022. */
  56023. _getBrush: function () {
  56024. var brushCanvas = this._brushCanvas || (this._brushCanvas = createCanvas());
  56025. // set brush size
  56026. var r = this.pointSize + this.blurSize;
  56027. var d = r * 2;
  56028. brushCanvas.width = d;
  56029. brushCanvas.height = d;
  56030. var ctx = brushCanvas.getContext('2d');
  56031. ctx.clearRect(0, 0, d, d);
  56032. // in order to render shadow without the distinct circle,
  56033. // draw the distinct circle in an invisible place,
  56034. // and use shadowOffset to draw shadow in the center of the canvas
  56035. ctx.shadowOffsetX = d;
  56036. ctx.shadowBlur = this.blurSize;
  56037. // draw the shadow in black, and use alpha and shadow blur to generate
  56038. // color in color map
  56039. ctx.shadowColor = '#000';
  56040. // draw circle in the left to the canvas
  56041. ctx.beginPath();
  56042. ctx.arc(-r, r, this.pointSize, 0, Math.PI * 2, true);
  56043. ctx.closePath();
  56044. ctx.fill();
  56045. return brushCanvas;
  56046. },
  56047. /**
  56048. * get gradient color map
  56049. * @private
  56050. */
  56051. _getGradient: function (data, colorFunc, state) {
  56052. var gradientPixels = this._gradientPixels;
  56053. var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
  56054. var color = [0, 0, 0, 0];
  56055. var off = 0;
  56056. for (var i = 0; i < 256; i++) {
  56057. colorFunc[state](i / 255, true, color);
  56058. pixelsSingleState[off++] = color[0];
  56059. pixelsSingleState[off++] = color[1];
  56060. pixelsSingleState[off++] = color[2];
  56061. pixelsSingleState[off++] = color[3];
  56062. }
  56063. return pixelsSingleState;
  56064. }
  56065. };
  56066. /*
  56067. * Licensed to the Apache Software Foundation (ASF) under one
  56068. * or more contributor license agreements. See the NOTICE file
  56069. * distributed with this work for additional information
  56070. * regarding copyright ownership. The ASF licenses this file
  56071. * to you under the Apache License, Version 2.0 (the
  56072. * "License"); you may not use this file except in compliance
  56073. * with the License. You may obtain a copy of the License at
  56074. *
  56075. * http://www.apache.org/licenses/LICENSE-2.0
  56076. *
  56077. * Unless required by applicable law or agreed to in writing,
  56078. * software distributed under the License is distributed on an
  56079. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56080. * KIND, either express or implied. See the License for the
  56081. * specific language governing permissions and limitations
  56082. * under the License.
  56083. */
  56084. function getIsInPiecewiseRange(dataExtent, pieceList, selected) {
  56085. var dataSpan = dataExtent[1] - dataExtent[0];
  56086. pieceList = map(pieceList, function (piece) {
  56087. return {
  56088. interval: [
  56089. (piece.interval[0] - dataExtent[0]) / dataSpan,
  56090. (piece.interval[1] - dataExtent[0]) / dataSpan
  56091. ]
  56092. };
  56093. });
  56094. var len = pieceList.length;
  56095. var lastIndex = 0;
  56096. return function (val) {
  56097. // Try to find in the location of the last found
  56098. for (var i = lastIndex; i < len; i++) {
  56099. var interval = pieceList[i].interval;
  56100. if (interval[0] <= val && val <= interval[1]) {
  56101. lastIndex = i;
  56102. break;
  56103. }
  56104. }
  56105. if (i === len) { // Not found, back interation
  56106. for (var i = lastIndex - 1; i >= 0; i--) {
  56107. var interval = pieceList[i].interval;
  56108. if (interval[0] <= val && val <= interval[1]) {
  56109. lastIndex = i;
  56110. break;
  56111. }
  56112. }
  56113. }
  56114. return i >= 0 && i < len && selected[i];
  56115. };
  56116. }
  56117. function getIsInContinuousRange(dataExtent, range) {
  56118. var dataSpan = dataExtent[1] - dataExtent[0];
  56119. range = [
  56120. (range[0] - dataExtent[0]) / dataSpan,
  56121. (range[1] - dataExtent[0]) / dataSpan
  56122. ];
  56123. return function (val) {
  56124. return val >= range[0] && val <= range[1];
  56125. };
  56126. }
  56127. function isGeoCoordSys(coordSys) {
  56128. var dimensions = coordSys.dimensions;
  56129. // Not use coorSys.type === 'geo' because coordSys maybe extended
  56130. return dimensions[0] === 'lng' && dimensions[1] === 'lat';
  56131. }
  56132. extendChartView({
  56133. type: 'heatmap',
  56134. render: function (seriesModel, ecModel, api) {
  56135. var visualMapOfThisSeries;
  56136. ecModel.eachComponent('visualMap', function (visualMap) {
  56137. visualMap.eachTargetSeries(function (targetSeries) {
  56138. if (targetSeries === seriesModel) {
  56139. visualMapOfThisSeries = visualMap;
  56140. }
  56141. });
  56142. });
  56143. if (__DEV__) {
  56144. if (!visualMapOfThisSeries) {
  56145. throw new Error('Heatmap must use with visualMap');
  56146. }
  56147. }
  56148. this.group.removeAll();
  56149. this._incrementalDisplayable = null;
  56150. var coordSys = seriesModel.coordinateSystem;
  56151. if (coordSys.type === 'cartesian2d' || coordSys.type === 'calendar') {
  56152. this._renderOnCartesianAndCalendar(seriesModel, api, 0, seriesModel.getData().count());
  56153. }
  56154. else if (isGeoCoordSys(coordSys)) {
  56155. this._renderOnGeo(
  56156. coordSys, seriesModel, visualMapOfThisSeries, api
  56157. );
  56158. }
  56159. },
  56160. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  56161. this.group.removeAll();
  56162. },
  56163. incrementalRender: function (params, seriesModel, ecModel, api) {
  56164. var coordSys = seriesModel.coordinateSystem;
  56165. if (coordSys) {
  56166. this._renderOnCartesianAndCalendar(seriesModel, api, params.start, params.end, true);
  56167. }
  56168. },
  56169. _renderOnCartesianAndCalendar: function (seriesModel, api, start, end, incremental) {
  56170. var coordSys = seriesModel.coordinateSystem;
  56171. var width;
  56172. var height;
  56173. if (coordSys.type === 'cartesian2d') {
  56174. var xAxis = coordSys.getAxis('x');
  56175. var yAxis = coordSys.getAxis('y');
  56176. if (__DEV__) {
  56177. if (!(xAxis.type === 'category' && yAxis.type === 'category')) {
  56178. throw new Error('Heatmap on cartesian must have two category axes');
  56179. }
  56180. if (!(xAxis.onBand && yAxis.onBand)) {
  56181. throw new Error('Heatmap on cartesian must have two axes with boundaryGap true');
  56182. }
  56183. }
  56184. width = xAxis.getBandWidth();
  56185. height = yAxis.getBandWidth();
  56186. }
  56187. var group = this.group;
  56188. var data = seriesModel.getData();
  56189. var itemStyleQuery = 'itemStyle';
  56190. var hoverItemStyleQuery = 'emphasis.itemStyle';
  56191. var labelQuery = 'label';
  56192. var hoverLabelQuery = 'emphasis.label';
  56193. var style = seriesModel.getModel(itemStyleQuery).getItemStyle(['color']);
  56194. var hoverStl = seriesModel.getModel(hoverItemStyleQuery).getItemStyle();
  56195. var labelModel = seriesModel.getModel(labelQuery);
  56196. var hoverLabelModel = seriesModel.getModel(hoverLabelQuery);
  56197. var coordSysType = coordSys.type;
  56198. var dataDims = coordSysType === 'cartesian2d'
  56199. ? [
  56200. data.mapDimension('x'),
  56201. data.mapDimension('y'),
  56202. data.mapDimension('value')
  56203. ]
  56204. : [
  56205. data.mapDimension('time'),
  56206. data.mapDimension('value')
  56207. ];
  56208. for (var idx = start; idx < end; idx++) {
  56209. var rect;
  56210. if (coordSysType === 'cartesian2d') {
  56211. // Ignore empty data
  56212. if (isNaN(data.get(dataDims[2], idx))) {
  56213. continue;
  56214. }
  56215. var point = coordSys.dataToPoint([
  56216. data.get(dataDims[0], idx),
  56217. data.get(dataDims[1], idx)
  56218. ]);
  56219. rect = new Rect({
  56220. shape: {
  56221. x: point[0] - width / 2,
  56222. y: point[1] - height / 2,
  56223. width: width,
  56224. height: height
  56225. },
  56226. style: {
  56227. fill: data.getItemVisual(idx, 'color'),
  56228. opacity: data.getItemVisual(idx, 'opacity')
  56229. }
  56230. });
  56231. }
  56232. else {
  56233. // Ignore empty data
  56234. if (isNaN(data.get(dataDims[1], idx))) {
  56235. continue;
  56236. }
  56237. rect = new Rect({
  56238. z2: 1,
  56239. shape: coordSys.dataToRect([data.get(dataDims[0], idx)]).contentShape,
  56240. style: {
  56241. fill: data.getItemVisual(idx, 'color'),
  56242. opacity: data.getItemVisual(idx, 'opacity')
  56243. }
  56244. });
  56245. }
  56246. var itemModel = data.getItemModel(idx);
  56247. // Optimization for large datset
  56248. if (data.hasItemOption) {
  56249. style = itemModel.getModel(itemStyleQuery).getItemStyle(['color']);
  56250. hoverStl = itemModel.getModel(hoverItemStyleQuery).getItemStyle();
  56251. labelModel = itemModel.getModel(labelQuery);
  56252. hoverLabelModel = itemModel.getModel(hoverLabelQuery);
  56253. }
  56254. var rawValue = seriesModel.getRawValue(idx);
  56255. var defaultText = '-';
  56256. if (rawValue && rawValue[2] != null) {
  56257. defaultText = rawValue[2];
  56258. }
  56259. setLabelStyle(
  56260. style, hoverStl, labelModel, hoverLabelModel,
  56261. {
  56262. labelFetcher: seriesModel,
  56263. labelDataIndex: idx,
  56264. defaultText: defaultText,
  56265. isRectText: true
  56266. }
  56267. );
  56268. rect.setStyle(style);
  56269. setHoverStyle(rect, data.hasItemOption ? hoverStl : extend({}, hoverStl));
  56270. rect.incremental = incremental;
  56271. // PENDING
  56272. if (incremental) {
  56273. // Rect must use hover layer if it's incremental.
  56274. rect.useHoverLayer = true;
  56275. }
  56276. group.add(rect);
  56277. data.setItemGraphicEl(idx, rect);
  56278. }
  56279. },
  56280. _renderOnGeo: function (geo, seriesModel, visualMapModel, api) {
  56281. var inRangeVisuals = visualMapModel.targetVisuals.inRange;
  56282. var outOfRangeVisuals = visualMapModel.targetVisuals.outOfRange;
  56283. // if (!visualMapping) {
  56284. // throw new Error('Data range must have color visuals');
  56285. // }
  56286. var data = seriesModel.getData();
  56287. var hmLayer = this._hmLayer || (this._hmLayer || new Heatmap());
  56288. hmLayer.blurSize = seriesModel.get('blurSize');
  56289. hmLayer.pointSize = seriesModel.get('pointSize');
  56290. hmLayer.minOpacity = seriesModel.get('minOpacity');
  56291. hmLayer.maxOpacity = seriesModel.get('maxOpacity');
  56292. var rect = geo.getViewRect().clone();
  56293. var roamTransform = geo.getRoamTransform();
  56294. rect.applyTransform(roamTransform);
  56295. // Clamp on viewport
  56296. var x = Math.max(rect.x, 0);
  56297. var y = Math.max(rect.y, 0);
  56298. var x2 = Math.min(rect.width + rect.x, api.getWidth());
  56299. var y2 = Math.min(rect.height + rect.y, api.getHeight());
  56300. var width = x2 - x;
  56301. var height = y2 - y;
  56302. var dims = [
  56303. data.mapDimension('lng'),
  56304. data.mapDimension('lat'),
  56305. data.mapDimension('value')
  56306. ];
  56307. var points = data.mapArray(dims, function (lng, lat, value) {
  56308. var pt = geo.dataToPoint([lng, lat]);
  56309. pt[0] -= x;
  56310. pt[1] -= y;
  56311. pt.push(value);
  56312. return pt;
  56313. });
  56314. var dataExtent = visualMapModel.getExtent();
  56315. var isInRange = visualMapModel.type === 'visualMap.continuous'
  56316. ? getIsInContinuousRange(dataExtent, visualMapModel.option.range)
  56317. : getIsInPiecewiseRange(
  56318. dataExtent, visualMapModel.getPieceList(), visualMapModel.option.selected
  56319. );
  56320. hmLayer.update(
  56321. points, width, height,
  56322. inRangeVisuals.color.getNormalizer(),
  56323. {
  56324. inRange: inRangeVisuals.color.getColorMapper(),
  56325. outOfRange: outOfRangeVisuals.color.getColorMapper()
  56326. },
  56327. isInRange
  56328. );
  56329. var img = new ZImage({
  56330. style: {
  56331. width: width,
  56332. height: height,
  56333. x: x,
  56334. y: y,
  56335. image: hmLayer.canvas
  56336. },
  56337. silent: true
  56338. });
  56339. this.group.add(img);
  56340. },
  56341. dispose: function () {}
  56342. });
  56343. /*
  56344. * Licensed to the Apache Software Foundation (ASF) under one
  56345. * or more contributor license agreements. See the NOTICE file
  56346. * distributed with this work for additional information
  56347. * regarding copyright ownership. The ASF licenses this file
  56348. * to you under the Apache License, Version 2.0 (the
  56349. * "License"); you may not use this file except in compliance
  56350. * with the License. You may obtain a copy of the License at
  56351. *
  56352. * http://www.apache.org/licenses/LICENSE-2.0
  56353. *
  56354. * Unless required by applicable law or agreed to in writing,
  56355. * software distributed under the License is distributed on an
  56356. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56357. * KIND, either express or implied. See the License for the
  56358. * specific language governing permissions and limitations
  56359. * under the License.
  56360. */
  56361. /*
  56362. * Licensed to the Apache Software Foundation (ASF) under one
  56363. * or more contributor license agreements. See the NOTICE file
  56364. * distributed with this work for additional information
  56365. * regarding copyright ownership. The ASF licenses this file
  56366. * to you under the Apache License, Version 2.0 (the
  56367. * "License"); you may not use this file except in compliance
  56368. * with the License. You may obtain a copy of the License at
  56369. *
  56370. * http://www.apache.org/licenses/LICENSE-2.0
  56371. *
  56372. * Unless required by applicable law or agreed to in writing,
  56373. * software distributed under the License is distributed on an
  56374. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56375. * KIND, either express or implied. See the License for the
  56376. * specific language governing permissions and limitations
  56377. * under the License.
  56378. */
  56379. var PictorialBarSeries = BaseBarSeries.extend({
  56380. type: 'series.pictorialBar',
  56381. dependencies: ['grid'],
  56382. defaultOption: {
  56383. symbol: 'circle', // Customized bar shape
  56384. symbolSize: null, // Can be ['100%', '100%'], null means auto.
  56385. symbolRotate: null,
  56386. symbolPosition: null, // 'start' or 'end' or 'center', null means auto.
  56387. symbolOffset: null,
  56388. symbolMargin: null, // start margin and end margin. Can be a number or a percent string.
  56389. // Auto margin by defualt.
  56390. symbolRepeat: false, // false/null/undefined, means no repeat.
  56391. // Can be true, means auto calculate repeat times and cut by data.
  56392. // Can be a number, specifies repeat times, and do not cut by data.
  56393. // Can be 'fixed', means auto calculate repeat times but do not cut by data.
  56394. symbolRepeatDirection: 'end', // 'end' means from 'start' to 'end'.
  56395. symbolClip: false,
  56396. symbolBoundingData: null, // Can be 60 or -40 or [-40, 60]
  56397. symbolPatternSize: 400, // 400 * 400 px
  56398. barGap: '-100%', // In most case, overlap is needed.
  56399. // z can be set in data item, which is z2 actually.
  56400. // Disable progressive
  56401. progressive: 0,
  56402. hoverAnimation: false // Open only when needed.
  56403. },
  56404. getInitialData: function (option) {
  56405. // Disable stack.
  56406. option.stack = null;
  56407. return PictorialBarSeries.superApply(this, 'getInitialData', arguments);
  56408. }
  56409. });
  56410. /*
  56411. * Licensed to the Apache Software Foundation (ASF) under one
  56412. * or more contributor license agreements. See the NOTICE file
  56413. * distributed with this work for additional information
  56414. * regarding copyright ownership. The ASF licenses this file
  56415. * to you under the Apache License, Version 2.0 (the
  56416. * "License"); you may not use this file except in compliance
  56417. * with the License. You may obtain a copy of the License at
  56418. *
  56419. * http://www.apache.org/licenses/LICENSE-2.0
  56420. *
  56421. * Unless required by applicable law or agreed to in writing,
  56422. * software distributed under the License is distributed on an
  56423. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56424. * KIND, either express or implied. See the License for the
  56425. * specific language governing permissions and limitations
  56426. * under the License.
  56427. */
  56428. var BAR_BORDER_WIDTH_QUERY$1 = ['itemStyle', 'borderWidth'];
  56429. // index: +isHorizontal
  56430. var LAYOUT_ATTRS = [
  56431. {xy: 'x', wh: 'width', index: 0, posDesc: ['left', 'right']},
  56432. {xy: 'y', wh: 'height', index: 1, posDesc: ['top', 'bottom']}
  56433. ];
  56434. var pathForLineWidth = new Circle();
  56435. var BarView$1 = extendChartView({
  56436. type: 'pictorialBar',
  56437. render: function (seriesModel, ecModel, api) {
  56438. var group = this.group;
  56439. var data = seriesModel.getData();
  56440. var oldData = this._data;
  56441. var cartesian = seriesModel.coordinateSystem;
  56442. var baseAxis = cartesian.getBaseAxis();
  56443. var isHorizontal = !!baseAxis.isHorizontal();
  56444. var coordSysRect = cartesian.grid.getRect();
  56445. var opt = {
  56446. ecSize: {width: api.getWidth(), height: api.getHeight()},
  56447. seriesModel: seriesModel,
  56448. coordSys: cartesian,
  56449. coordSysExtent: [
  56450. [coordSysRect.x, coordSysRect.x + coordSysRect.width],
  56451. [coordSysRect.y, coordSysRect.y + coordSysRect.height]
  56452. ],
  56453. isHorizontal: isHorizontal,
  56454. valueDim: LAYOUT_ATTRS[+isHorizontal],
  56455. categoryDim: LAYOUT_ATTRS[1 - isHorizontal]
  56456. };
  56457. data.diff(oldData)
  56458. .add(function (dataIndex) {
  56459. if (!data.hasValue(dataIndex)) {
  56460. return;
  56461. }
  56462. var itemModel = getItemModel(data, dataIndex);
  56463. var symbolMeta = getSymbolMeta(data, dataIndex, itemModel, opt);
  56464. var bar = createBar(data, opt, symbolMeta);
  56465. data.setItemGraphicEl(dataIndex, bar);
  56466. group.add(bar);
  56467. updateCommon$1(bar, opt, symbolMeta);
  56468. })
  56469. .update(function (newIndex, oldIndex) {
  56470. var bar = oldData.getItemGraphicEl(oldIndex);
  56471. if (!data.hasValue(newIndex)) {
  56472. group.remove(bar);
  56473. return;
  56474. }
  56475. var itemModel = getItemModel(data, newIndex);
  56476. var symbolMeta = getSymbolMeta(data, newIndex, itemModel, opt);
  56477. var pictorialShapeStr = getShapeStr(data, symbolMeta);
  56478. if (bar && pictorialShapeStr !== bar.__pictorialShapeStr) {
  56479. group.remove(bar);
  56480. data.setItemGraphicEl(newIndex, null);
  56481. bar = null;
  56482. }
  56483. if (bar) {
  56484. updateBar(bar, opt, symbolMeta);
  56485. }
  56486. else {
  56487. bar = createBar(data, opt, symbolMeta, true);
  56488. }
  56489. data.setItemGraphicEl(newIndex, bar);
  56490. bar.__pictorialSymbolMeta = symbolMeta;
  56491. // Add back
  56492. group.add(bar);
  56493. updateCommon$1(bar, opt, symbolMeta);
  56494. })
  56495. .remove(function (dataIndex) {
  56496. var bar = oldData.getItemGraphicEl(dataIndex);
  56497. bar && removeBar(oldData, dataIndex, bar.__pictorialSymbolMeta.animationModel, bar);
  56498. })
  56499. .execute();
  56500. this._data = data;
  56501. return this.group;
  56502. },
  56503. dispose: noop,
  56504. remove: function (ecModel, api) {
  56505. var group = this.group;
  56506. var data = this._data;
  56507. if (ecModel.get('animation')) {
  56508. if (data) {
  56509. data.eachItemGraphicEl(function (bar) {
  56510. removeBar(data, bar.dataIndex, ecModel, bar);
  56511. });
  56512. }
  56513. }
  56514. else {
  56515. group.removeAll();
  56516. }
  56517. }
  56518. });
  56519. // Set or calculate default value about symbol, and calculate layout info.
  56520. function getSymbolMeta(data, dataIndex, itemModel, opt) {
  56521. var layout = data.getItemLayout(dataIndex);
  56522. var symbolRepeat = itemModel.get('symbolRepeat');
  56523. var symbolClip = itemModel.get('symbolClip');
  56524. var symbolPosition = itemModel.get('symbolPosition') || 'start';
  56525. var symbolRotate = itemModel.get('symbolRotate');
  56526. var rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  56527. var symbolPatternSize = itemModel.get('symbolPatternSize') || 2;
  56528. var isAnimationEnabled = itemModel.isAnimationEnabled();
  56529. var symbolMeta = {
  56530. dataIndex: dataIndex,
  56531. layout: layout,
  56532. itemModel: itemModel,
  56533. symbolType: data.getItemVisual(dataIndex, 'symbol') || 'circle',
  56534. color: data.getItemVisual(dataIndex, 'color'),
  56535. symbolClip: symbolClip,
  56536. symbolRepeat: symbolRepeat,
  56537. symbolRepeatDirection: itemModel.get('symbolRepeatDirection'),
  56538. symbolPatternSize: symbolPatternSize,
  56539. rotation: rotation,
  56540. animationModel: isAnimationEnabled ? itemModel : null,
  56541. hoverAnimation: isAnimationEnabled && itemModel.get('hoverAnimation'),
  56542. z2: itemModel.getShallow('z', true) || 0
  56543. };
  56544. prepareBarLength(itemModel, symbolRepeat, layout, opt, symbolMeta);
  56545. prepareSymbolSize(
  56546. data, dataIndex, layout, symbolRepeat, symbolClip, symbolMeta.boundingLength,
  56547. symbolMeta.pxSign, symbolPatternSize, opt, symbolMeta
  56548. );
  56549. prepareLineWidth(itemModel, symbolMeta.symbolScale, rotation, opt, symbolMeta);
  56550. var symbolSize = symbolMeta.symbolSize;
  56551. var symbolOffset = itemModel.get('symbolOffset');
  56552. if (isArray(symbolOffset)) {
  56553. symbolOffset = [
  56554. parsePercent$1(symbolOffset[0], symbolSize[0]),
  56555. parsePercent$1(symbolOffset[1], symbolSize[1])
  56556. ];
  56557. }
  56558. prepareLayoutInfo(
  56559. itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset,
  56560. symbolPosition, symbolMeta.valueLineWidth, symbolMeta.boundingLength, symbolMeta.repeatCutLength,
  56561. opt, symbolMeta
  56562. );
  56563. return symbolMeta;
  56564. }
  56565. // bar length can be negative.
  56566. function prepareBarLength(itemModel, symbolRepeat, layout, opt, output) {
  56567. var valueDim = opt.valueDim;
  56568. var symbolBoundingData = itemModel.get('symbolBoundingData');
  56569. var valueAxis = opt.coordSys.getOtherAxis(opt.coordSys.getBaseAxis());
  56570. var zeroPx = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
  56571. var pxSignIdx = 1 - +(layout[valueDim.wh] <= 0);
  56572. var boundingLength;
  56573. if (isArray(symbolBoundingData)) {
  56574. var symbolBoundingExtent = [
  56575. convertToCoordOnAxis(valueAxis, symbolBoundingData[0]) - zeroPx,
  56576. convertToCoordOnAxis(valueAxis, symbolBoundingData[1]) - zeroPx
  56577. ];
  56578. symbolBoundingExtent[1] < symbolBoundingExtent[0] && (symbolBoundingExtent.reverse());
  56579. boundingLength = symbolBoundingExtent[pxSignIdx];
  56580. }
  56581. else if (symbolBoundingData != null) {
  56582. boundingLength = convertToCoordOnAxis(valueAxis, symbolBoundingData) - zeroPx;
  56583. }
  56584. else if (symbolRepeat) {
  56585. boundingLength = opt.coordSysExtent[valueDim.index][pxSignIdx] - zeroPx;
  56586. }
  56587. else {
  56588. boundingLength = layout[valueDim.wh];
  56589. }
  56590. output.boundingLength = boundingLength;
  56591. if (symbolRepeat) {
  56592. output.repeatCutLength = layout[valueDim.wh];
  56593. }
  56594. output.pxSign = boundingLength > 0 ? 1 : boundingLength < 0 ? -1 : 0;
  56595. }
  56596. function convertToCoordOnAxis(axis, value) {
  56597. return axis.toGlobalCoord(axis.dataToCoord(axis.scale.parse(value)));
  56598. }
  56599. // Support ['100%', '100%']
  56600. function prepareSymbolSize(
  56601. data, dataIndex, layout, symbolRepeat, symbolClip, boundingLength,
  56602. pxSign, symbolPatternSize, opt, output
  56603. ) {
  56604. var valueDim = opt.valueDim;
  56605. var categoryDim = opt.categoryDim;
  56606. var categorySize = Math.abs(layout[categoryDim.wh]);
  56607. var symbolSize = data.getItemVisual(dataIndex, 'symbolSize');
  56608. if (isArray(symbolSize)) {
  56609. symbolSize = symbolSize.slice();
  56610. }
  56611. else {
  56612. if (symbolSize == null) {
  56613. symbolSize = '100%';
  56614. }
  56615. symbolSize = [symbolSize, symbolSize];
  56616. }
  56617. // Note: percentage symbolSize (like '100%') do not consider lineWidth, because it is
  56618. // to complicated to calculate real percent value if considering scaled lineWidth.
  56619. // So the actual size will bigger than layout size if lineWidth is bigger than zero,
  56620. // which can be tolerated in pictorial chart.
  56621. symbolSize[categoryDim.index] = parsePercent$1(
  56622. symbolSize[categoryDim.index],
  56623. categorySize
  56624. );
  56625. symbolSize[valueDim.index] = parsePercent$1(
  56626. symbolSize[valueDim.index],
  56627. symbolRepeat ? categorySize : Math.abs(boundingLength)
  56628. );
  56629. output.symbolSize = symbolSize;
  56630. // If x or y is less than zero, show reversed shape.
  56631. var symbolScale = output.symbolScale = [
  56632. symbolSize[0] / symbolPatternSize,
  56633. symbolSize[1] / symbolPatternSize
  56634. ];
  56635. // Follow convention, 'right' and 'top' is the normal scale.
  56636. symbolScale[valueDim.index] *= (opt.isHorizontal ? -1 : 1) * pxSign;
  56637. }
  56638. function prepareLineWidth(itemModel, symbolScale, rotation, opt, output) {
  56639. // In symbols are drawn with scale, so do not need to care about the case that width
  56640. // or height are too small. But symbol use strokeNoScale, where acture lineWidth should
  56641. // be calculated.
  56642. var valueLineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY$1) || 0;
  56643. if (valueLineWidth) {
  56644. pathForLineWidth.attr({
  56645. scale: symbolScale.slice(),
  56646. rotation: rotation
  56647. });
  56648. pathForLineWidth.updateTransform();
  56649. valueLineWidth /= pathForLineWidth.getLineScale();
  56650. valueLineWidth *= symbolScale[opt.valueDim.index];
  56651. }
  56652. output.valueLineWidth = valueLineWidth;
  56653. }
  56654. function prepareLayoutInfo(
  56655. itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset,
  56656. symbolPosition, valueLineWidth, boundingLength, repeatCutLength, opt, output
  56657. ) {
  56658. var categoryDim = opt.categoryDim;
  56659. var valueDim = opt.valueDim;
  56660. var pxSign = output.pxSign;
  56661. var unitLength = Math.max(symbolSize[valueDim.index] + valueLineWidth, 0);
  56662. var pathLen = unitLength;
  56663. // Note: rotation will not effect the layout of symbols, because user may
  56664. // want symbols to rotate on its center, which should not be translated
  56665. // when rotating.
  56666. if (symbolRepeat) {
  56667. var absBoundingLength = Math.abs(boundingLength);
  56668. var symbolMargin = retrieve(itemModel.get('symbolMargin'), '15%') + '';
  56669. var hasEndGap = false;
  56670. if (symbolMargin.lastIndexOf('!') === symbolMargin.length - 1) {
  56671. hasEndGap = true;
  56672. symbolMargin = symbolMargin.slice(0, symbolMargin.length - 1);
  56673. }
  56674. symbolMargin = parsePercent$1(symbolMargin, symbolSize[valueDim.index]);
  56675. var uLenWithMargin = Math.max(unitLength + symbolMargin * 2, 0);
  56676. // When symbol margin is less than 0, margin at both ends will be subtracted
  56677. // to ensure that all of the symbols will not be overflow the given area.
  56678. var endFix = hasEndGap ? 0 : symbolMargin * 2;
  56679. // Both final repeatTimes and final symbolMargin area calculated based on
  56680. // boundingLength.
  56681. var repeatSpecified = isNumeric(symbolRepeat);
  56682. var repeatTimes = repeatSpecified
  56683. ? symbolRepeat
  56684. : toIntTimes((absBoundingLength + endFix) / uLenWithMargin);
  56685. // Adjust calculate margin, to ensure each symbol is displayed
  56686. // entirely in the given layout area.
  56687. var mDiff = absBoundingLength - repeatTimes * unitLength;
  56688. symbolMargin = mDiff / 2 / (hasEndGap ? repeatTimes : repeatTimes - 1);
  56689. uLenWithMargin = unitLength + symbolMargin * 2;
  56690. endFix = hasEndGap ? 0 : symbolMargin * 2;
  56691. // Update repeatTimes when not all symbol will be shown.
  56692. if (!repeatSpecified && symbolRepeat !== 'fixed') {
  56693. repeatTimes = repeatCutLength
  56694. ? toIntTimes((Math.abs(repeatCutLength) + endFix) / uLenWithMargin)
  56695. : 0;
  56696. }
  56697. pathLen = repeatTimes * uLenWithMargin - endFix;
  56698. output.repeatTimes = repeatTimes;
  56699. output.symbolMargin = symbolMargin;
  56700. }
  56701. var sizeFix = pxSign * (pathLen / 2);
  56702. var pathPosition = output.pathPosition = [];
  56703. pathPosition[categoryDim.index] = layout[categoryDim.wh] / 2;
  56704. pathPosition[valueDim.index] = symbolPosition === 'start'
  56705. ? sizeFix
  56706. : symbolPosition === 'end'
  56707. ? boundingLength - sizeFix
  56708. : boundingLength / 2; // 'center'
  56709. if (symbolOffset) {
  56710. pathPosition[0] += symbolOffset[0];
  56711. pathPosition[1] += symbolOffset[1];
  56712. }
  56713. var bundlePosition = output.bundlePosition = [];
  56714. bundlePosition[categoryDim.index] = layout[categoryDim.xy];
  56715. bundlePosition[valueDim.index] = layout[valueDim.xy];
  56716. var barRectShape = output.barRectShape = extend({}, layout);
  56717. barRectShape[valueDim.wh] = pxSign * Math.max(
  56718. Math.abs(layout[valueDim.wh]), Math.abs(pathPosition[valueDim.index] + sizeFix)
  56719. );
  56720. barRectShape[categoryDim.wh] = layout[categoryDim.wh];
  56721. var clipShape = output.clipShape = {};
  56722. // Consider that symbol may be overflow layout rect.
  56723. clipShape[categoryDim.xy] = -layout[categoryDim.xy];
  56724. clipShape[categoryDim.wh] = opt.ecSize[categoryDim.wh];
  56725. clipShape[valueDim.xy] = 0;
  56726. clipShape[valueDim.wh] = layout[valueDim.wh];
  56727. }
  56728. function createPath(symbolMeta) {
  56729. var symbolPatternSize = symbolMeta.symbolPatternSize;
  56730. var path = createSymbol(
  56731. // Consider texture img, make a big size.
  56732. symbolMeta.symbolType,
  56733. -symbolPatternSize / 2,
  56734. -symbolPatternSize / 2,
  56735. symbolPatternSize,
  56736. symbolPatternSize,
  56737. symbolMeta.color
  56738. );
  56739. path.attr({
  56740. culling: true
  56741. });
  56742. path.type !== 'image' && path.setStyle({
  56743. strokeNoScale: true
  56744. });
  56745. return path;
  56746. }
  56747. function createOrUpdateRepeatSymbols(bar, opt, symbolMeta, isUpdate) {
  56748. var bundle = bar.__pictorialBundle;
  56749. var symbolSize = symbolMeta.symbolSize;
  56750. var valueLineWidth = symbolMeta.valueLineWidth;
  56751. var pathPosition = symbolMeta.pathPosition;
  56752. var valueDim = opt.valueDim;
  56753. var repeatTimes = symbolMeta.repeatTimes || 0;
  56754. var index = 0;
  56755. var unit = symbolSize[opt.valueDim.index] + valueLineWidth + symbolMeta.symbolMargin * 2;
  56756. eachPath(bar, function (path) {
  56757. path.__pictorialAnimationIndex = index;
  56758. path.__pictorialRepeatTimes = repeatTimes;
  56759. if (index < repeatTimes) {
  56760. updateAttr(path, null, makeTarget(index), symbolMeta, isUpdate);
  56761. }
  56762. else {
  56763. updateAttr(path, null, {scale: [0, 0]}, symbolMeta, isUpdate, function () {
  56764. bundle.remove(path);
  56765. });
  56766. }
  56767. updateHoverAnimation(path, symbolMeta);
  56768. index++;
  56769. });
  56770. for (; index < repeatTimes; index++) {
  56771. var path = createPath(symbolMeta);
  56772. path.__pictorialAnimationIndex = index;
  56773. path.__pictorialRepeatTimes = repeatTimes;
  56774. bundle.add(path);
  56775. var target = makeTarget(index);
  56776. updateAttr(
  56777. path,
  56778. {
  56779. position: target.position,
  56780. scale: [0, 0]
  56781. },
  56782. {
  56783. scale: target.scale,
  56784. rotation: target.rotation
  56785. },
  56786. symbolMeta,
  56787. isUpdate
  56788. );
  56789. // FIXME
  56790. // If all emphasis/normal through action.
  56791. path
  56792. .on('mouseover', onMouseOver)
  56793. .on('mouseout', onMouseOut);
  56794. updateHoverAnimation(path, symbolMeta);
  56795. }
  56796. function makeTarget(index) {
  56797. var position = pathPosition.slice();
  56798. // (start && pxSign > 0) || (end && pxSign < 0): i = repeatTimes - index
  56799. // Otherwise: i = index;
  56800. var pxSign = symbolMeta.pxSign;
  56801. var i = index;
  56802. if (symbolMeta.symbolRepeatDirection === 'start' ? pxSign > 0 : pxSign < 0) {
  56803. i = repeatTimes - 1 - index;
  56804. }
  56805. position[valueDim.index] = unit * (i - repeatTimes / 2 + 0.5) + pathPosition[valueDim.index];
  56806. return {
  56807. position: position,
  56808. scale: symbolMeta.symbolScale.slice(),
  56809. rotation: symbolMeta.rotation
  56810. };
  56811. }
  56812. function onMouseOver() {
  56813. eachPath(bar, function (path) {
  56814. path.trigger('emphasis');
  56815. });
  56816. }
  56817. function onMouseOut() {
  56818. eachPath(bar, function (path) {
  56819. path.trigger('normal');
  56820. });
  56821. }
  56822. }
  56823. function createOrUpdateSingleSymbol(bar, opt, symbolMeta, isUpdate) {
  56824. var bundle = bar.__pictorialBundle;
  56825. var mainPath = bar.__pictorialMainPath;
  56826. if (!mainPath) {
  56827. mainPath = bar.__pictorialMainPath = createPath(symbolMeta);
  56828. bundle.add(mainPath);
  56829. updateAttr(
  56830. mainPath,
  56831. {
  56832. position: symbolMeta.pathPosition.slice(),
  56833. scale: [0, 0],
  56834. rotation: symbolMeta.rotation
  56835. },
  56836. {
  56837. scale: symbolMeta.symbolScale.slice()
  56838. },
  56839. symbolMeta,
  56840. isUpdate
  56841. );
  56842. mainPath
  56843. .on('mouseover', onMouseOver)
  56844. .on('mouseout', onMouseOut);
  56845. }
  56846. else {
  56847. updateAttr(
  56848. mainPath,
  56849. null,
  56850. {
  56851. position: symbolMeta.pathPosition.slice(),
  56852. scale: symbolMeta.symbolScale.slice(),
  56853. rotation: symbolMeta.rotation
  56854. },
  56855. symbolMeta,
  56856. isUpdate
  56857. );
  56858. }
  56859. updateHoverAnimation(mainPath, symbolMeta);
  56860. function onMouseOver() {
  56861. this.trigger('emphasis');
  56862. }
  56863. function onMouseOut() {
  56864. this.trigger('normal');
  56865. }
  56866. }
  56867. // bar rect is used for label.
  56868. function createOrUpdateBarRect(bar, symbolMeta, isUpdate) {
  56869. var rectShape = extend({}, symbolMeta.barRectShape);
  56870. var barRect = bar.__pictorialBarRect;
  56871. if (!barRect) {
  56872. barRect = bar.__pictorialBarRect = new Rect({
  56873. z2: 2,
  56874. shape: rectShape,
  56875. silent: true,
  56876. style: {
  56877. stroke: 'transparent',
  56878. fill: 'transparent',
  56879. lineWidth: 0
  56880. }
  56881. });
  56882. bar.add(barRect);
  56883. }
  56884. else {
  56885. updateAttr(barRect, null, {shape: rectShape}, symbolMeta, isUpdate);
  56886. }
  56887. }
  56888. function createOrUpdateClip(bar, opt, symbolMeta, isUpdate) {
  56889. // If not clip, symbol will be remove and rebuilt.
  56890. if (symbolMeta.symbolClip) {
  56891. var clipPath = bar.__pictorialClipPath;
  56892. var clipShape = extend({}, symbolMeta.clipShape);
  56893. var valueDim = opt.valueDim;
  56894. var animationModel = symbolMeta.animationModel;
  56895. var dataIndex = symbolMeta.dataIndex;
  56896. if (clipPath) {
  56897. updateProps(
  56898. clipPath, {shape: clipShape}, animationModel, dataIndex
  56899. );
  56900. }
  56901. else {
  56902. clipShape[valueDim.wh] = 0;
  56903. clipPath = new Rect({shape: clipShape});
  56904. bar.__pictorialBundle.setClipPath(clipPath);
  56905. bar.__pictorialClipPath = clipPath;
  56906. var target = {};
  56907. target[valueDim.wh] = symbolMeta.clipShape[valueDim.wh];
  56908. graphic[isUpdate ? 'updateProps' : 'initProps'](
  56909. clipPath, {shape: target}, animationModel, dataIndex
  56910. );
  56911. }
  56912. }
  56913. }
  56914. function getItemModel(data, dataIndex) {
  56915. var itemModel = data.getItemModel(dataIndex);
  56916. itemModel.getAnimationDelayParams = getAnimationDelayParams;
  56917. itemModel.isAnimationEnabled = isAnimationEnabled;
  56918. return itemModel;
  56919. }
  56920. function getAnimationDelayParams(path) {
  56921. // The order is the same as the z-order, see `symbolRepeatDiretion`.
  56922. return {
  56923. index: path.__pictorialAnimationIndex,
  56924. count: path.__pictorialRepeatTimes
  56925. };
  56926. }
  56927. function isAnimationEnabled() {
  56928. // `animation` prop can be set on itemModel in pictorial bar chart.
  56929. return this.parentModel.isAnimationEnabled() && !!this.getShallow('animation');
  56930. }
  56931. function updateHoverAnimation(path, symbolMeta) {
  56932. path.off('emphasis').off('normal');
  56933. var scale = symbolMeta.symbolScale.slice();
  56934. symbolMeta.hoverAnimation && path
  56935. .on('emphasis', function () {
  56936. this.animateTo({
  56937. scale: [scale[0] * 1.1, scale[1] * 1.1]
  56938. }, 400, 'elasticOut');
  56939. })
  56940. .on('normal', function () {
  56941. this.animateTo({
  56942. scale: scale.slice()
  56943. }, 400, 'elasticOut');
  56944. });
  56945. }
  56946. function createBar(data, opt, symbolMeta, isUpdate) {
  56947. // bar is the main element for each data.
  56948. var bar = new Group();
  56949. // bundle is used for location and clip.
  56950. var bundle = new Group();
  56951. bar.add(bundle);
  56952. bar.__pictorialBundle = bundle;
  56953. bundle.attr('position', symbolMeta.bundlePosition.slice());
  56954. if (symbolMeta.symbolRepeat) {
  56955. createOrUpdateRepeatSymbols(bar, opt, symbolMeta);
  56956. }
  56957. else {
  56958. createOrUpdateSingleSymbol(bar, opt, symbolMeta);
  56959. }
  56960. createOrUpdateBarRect(bar, symbolMeta, isUpdate);
  56961. createOrUpdateClip(bar, opt, symbolMeta, isUpdate);
  56962. bar.__pictorialShapeStr = getShapeStr(data, symbolMeta);
  56963. bar.__pictorialSymbolMeta = symbolMeta;
  56964. return bar;
  56965. }
  56966. function updateBar(bar, opt, symbolMeta) {
  56967. var animationModel = symbolMeta.animationModel;
  56968. var dataIndex = symbolMeta.dataIndex;
  56969. var bundle = bar.__pictorialBundle;
  56970. updateProps(
  56971. bundle, {position: symbolMeta.bundlePosition.slice()}, animationModel, dataIndex
  56972. );
  56973. if (symbolMeta.symbolRepeat) {
  56974. createOrUpdateRepeatSymbols(bar, opt, symbolMeta, true);
  56975. }
  56976. else {
  56977. createOrUpdateSingleSymbol(bar, opt, symbolMeta, true);
  56978. }
  56979. createOrUpdateBarRect(bar, symbolMeta, true);
  56980. createOrUpdateClip(bar, opt, symbolMeta, true);
  56981. }
  56982. function removeBar(data, dataIndex, animationModel, bar) {
  56983. // Not show text when animating
  56984. var labelRect = bar.__pictorialBarRect;
  56985. labelRect && (labelRect.style.text = null);
  56986. var pathes = [];
  56987. eachPath(bar, function (path) {
  56988. pathes.push(path);
  56989. });
  56990. bar.__pictorialMainPath && pathes.push(bar.__pictorialMainPath);
  56991. // I do not find proper remove animation for clip yet.
  56992. bar.__pictorialClipPath && (animationModel = null);
  56993. each$1(pathes, function (path) {
  56994. updateProps(
  56995. path, {scale: [0, 0]}, animationModel, dataIndex,
  56996. function () {
  56997. bar.parent && bar.parent.remove(bar);
  56998. }
  56999. );
  57000. });
  57001. data.setItemGraphicEl(dataIndex, null);
  57002. }
  57003. function getShapeStr(data, symbolMeta) {
  57004. return [
  57005. data.getItemVisual(symbolMeta.dataIndex, 'symbol') || 'none',
  57006. !!symbolMeta.symbolRepeat,
  57007. !!symbolMeta.symbolClip
  57008. ].join(':');
  57009. }
  57010. function eachPath(bar, cb, context) {
  57011. // Do not use Group#eachChild, because it do not support remove.
  57012. each$1(bar.__pictorialBundle.children(), function (el) {
  57013. el !== bar.__pictorialBarRect && cb.call(context, el);
  57014. });
  57015. }
  57016. function updateAttr(el, immediateAttrs, animationAttrs, symbolMeta, isUpdate, cb) {
  57017. immediateAttrs && el.attr(immediateAttrs);
  57018. // when symbolCip used, only clip path has init animation, otherwise it would be weird effect.
  57019. if (symbolMeta.symbolClip && !isUpdate) {
  57020. animationAttrs && el.attr(animationAttrs);
  57021. }
  57022. else {
  57023. animationAttrs && graphic[isUpdate ? 'updateProps' : 'initProps'](
  57024. el, animationAttrs, symbolMeta.animationModel, symbolMeta.dataIndex, cb
  57025. );
  57026. }
  57027. }
  57028. function updateCommon$1(bar, opt, symbolMeta) {
  57029. var color = symbolMeta.color;
  57030. var dataIndex = symbolMeta.dataIndex;
  57031. var itemModel = symbolMeta.itemModel;
  57032. // Color must be excluded.
  57033. // Because symbol provide setColor individually to set fill and stroke
  57034. var normalStyle = itemModel.getModel('itemStyle').getItemStyle(['color']);
  57035. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  57036. var cursorStyle = itemModel.getShallow('cursor');
  57037. eachPath(bar, function (path) {
  57038. // PENDING setColor should be before setStyle!!!
  57039. path.setColor(color);
  57040. path.setStyle(defaults(
  57041. {
  57042. fill: color,
  57043. opacity: symbolMeta.opacity
  57044. },
  57045. normalStyle
  57046. ));
  57047. setHoverStyle(path, hoverStyle);
  57048. cursorStyle && (path.cursor = cursorStyle);
  57049. path.z2 = symbolMeta.z2;
  57050. });
  57051. var barRectHoverStyle = {};
  57052. var barPositionOutside = opt.valueDim.posDesc[+(symbolMeta.boundingLength > 0)];
  57053. var barRect = bar.__pictorialBarRect;
  57054. setLabel(
  57055. barRect.style, barRectHoverStyle, itemModel,
  57056. color, opt.seriesModel, dataIndex, barPositionOutside
  57057. );
  57058. setHoverStyle(barRect, barRectHoverStyle);
  57059. }
  57060. function toIntTimes(times) {
  57061. var roundedTimes = Math.round(times);
  57062. // Escapse accurate error
  57063. return Math.abs(times - roundedTimes) < 1e-4
  57064. ? roundedTimes
  57065. : Math.ceil(times);
  57066. }
  57067. /*
  57068. * Licensed to the Apache Software Foundation (ASF) under one
  57069. * or more contributor license agreements. See the NOTICE file
  57070. * distributed with this work for additional information
  57071. * regarding copyright ownership. The ASF licenses this file
  57072. * to you under the Apache License, Version 2.0 (the
  57073. * "License"); you may not use this file except in compliance
  57074. * with the License. You may obtain a copy of the License at
  57075. *
  57076. * http://www.apache.org/licenses/LICENSE-2.0
  57077. *
  57078. * Unless required by applicable law or agreed to in writing,
  57079. * software distributed under the License is distributed on an
  57080. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57081. * KIND, either express or implied. See the License for the
  57082. * specific language governing permissions and limitations
  57083. * under the License.
  57084. */
  57085. // In case developer forget to include grid component
  57086. registerLayout(curry(
  57087. layout, 'pictorialBar'
  57088. ));
  57089. registerVisual(visualSymbol('pictorialBar', 'roundRect'));
  57090. /*
  57091. * Licensed to the Apache Software Foundation (ASF) under one
  57092. * or more contributor license agreements. See the NOTICE file
  57093. * distributed with this work for additional information
  57094. * regarding copyright ownership. The ASF licenses this file
  57095. * to you under the Apache License, Version 2.0 (the
  57096. * "License"); you may not use this file except in compliance
  57097. * with the License. You may obtain a copy of the License at
  57098. *
  57099. * http://www.apache.org/licenses/LICENSE-2.0
  57100. *
  57101. * Unless required by applicable law or agreed to in writing,
  57102. * software distributed under the License is distributed on an
  57103. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57104. * KIND, either express or implied. See the License for the
  57105. * specific language governing permissions and limitations
  57106. * under the License.
  57107. */
  57108. /**
  57109. * @constructor module:echarts/coord/single/SingleAxis
  57110. * @extends {module:echarts/coord/Axis}
  57111. * @param {string} dim
  57112. * @param {*} scale
  57113. * @param {Array.<number>} coordExtent
  57114. * @param {string} axisType
  57115. * @param {string} position
  57116. */
  57117. var SingleAxis = function (dim, scale, coordExtent, axisType, position) {
  57118. Axis.call(this, dim, scale, coordExtent);
  57119. /**
  57120. * Axis type
  57121. * - 'category'
  57122. * - 'value'
  57123. * - 'time'
  57124. * - 'log'
  57125. * @type {string}
  57126. */
  57127. this.type = axisType || 'value';
  57128. /**
  57129. * Axis position
  57130. * - 'top'
  57131. * - 'bottom'
  57132. * - 'left'
  57133. * - 'right'
  57134. * @type {string}
  57135. */
  57136. this.position = position || 'bottom';
  57137. /**
  57138. * Axis orient
  57139. * - 'horizontal'
  57140. * - 'vertical'
  57141. * @type {[type]}
  57142. */
  57143. this.orient = null;
  57144. };
  57145. SingleAxis.prototype = {
  57146. constructor: SingleAxis,
  57147. /**
  57148. * Axis model
  57149. * @type {module:echarts/coord/single/AxisModel}
  57150. */
  57151. model: null,
  57152. /**
  57153. * Judge the orient of the axis.
  57154. * @return {boolean}
  57155. */
  57156. isHorizontal: function () {
  57157. var position = this.position;
  57158. return position === 'top' || position === 'bottom';
  57159. },
  57160. /**
  57161. * @override
  57162. */
  57163. pointToData: function (point, clamp) {
  57164. return this.coordinateSystem.pointToData(point, clamp)[0];
  57165. },
  57166. /**
  57167. * Convert the local coord(processed by dataToCoord())
  57168. * to global coord(concrete pixel coord).
  57169. * designated by module:echarts/coord/single/Single.
  57170. * @type {Function}
  57171. */
  57172. toGlobalCoord: null,
  57173. /**
  57174. * Convert the global coord to local coord.
  57175. * designated by module:echarts/coord/single/Single.
  57176. * @type {Function}
  57177. */
  57178. toLocalCoord: null
  57179. };
  57180. inherits(SingleAxis, Axis);
  57181. /*
  57182. * Licensed to the Apache Software Foundation (ASF) under one
  57183. * or more contributor license agreements. See the NOTICE file
  57184. * distributed with this work for additional information
  57185. * regarding copyright ownership. The ASF licenses this file
  57186. * to you under the Apache License, Version 2.0 (the
  57187. * "License"); you may not use this file except in compliance
  57188. * with the License. You may obtain a copy of the License at
  57189. *
  57190. * http://www.apache.org/licenses/LICENSE-2.0
  57191. *
  57192. * Unless required by applicable law or agreed to in writing,
  57193. * software distributed under the License is distributed on an
  57194. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57195. * KIND, either express or implied. See the License for the
  57196. * specific language governing permissions and limitations
  57197. * under the License.
  57198. */
  57199. /**
  57200. * Single coordinates system.
  57201. */
  57202. /**
  57203. * Create a single coordinates system.
  57204. *
  57205. * @param {module:echarts/coord/single/AxisModel} axisModel
  57206. * @param {module:echarts/model/Global} ecModel
  57207. * @param {module:echarts/ExtensionAPI} api
  57208. */
  57209. function Single(axisModel, ecModel, api) {
  57210. /**
  57211. * @type {string}
  57212. * @readOnly
  57213. */
  57214. this.dimension = 'single';
  57215. /**
  57216. * Add it just for draw tooltip.
  57217. *
  57218. * @type {Array.<string>}
  57219. * @readOnly
  57220. */
  57221. this.dimensions = ['single'];
  57222. /**
  57223. * @private
  57224. * @type {module:echarts/coord/single/SingleAxis}.
  57225. */
  57226. this._axis = null;
  57227. /**
  57228. * @private
  57229. * @type {module:zrender/core/BoundingRect}
  57230. */
  57231. this._rect;
  57232. this._init(axisModel, ecModel, api);
  57233. /**
  57234. * @type {module:echarts/coord/single/AxisModel}
  57235. */
  57236. this.model = axisModel;
  57237. }
  57238. Single.prototype = {
  57239. type: 'singleAxis',
  57240. axisPointerEnabled: true,
  57241. constructor: Single,
  57242. /**
  57243. * Initialize single coordinate system.
  57244. *
  57245. * @param {module:echarts/coord/single/AxisModel} axisModel
  57246. * @param {module:echarts/model/Global} ecModel
  57247. * @param {module:echarts/ExtensionAPI} api
  57248. * @private
  57249. */
  57250. _init: function (axisModel, ecModel, api) {
  57251. var dim = this.dimension;
  57252. var axis = new SingleAxis(
  57253. dim,
  57254. createScaleByModel(axisModel),
  57255. [0, 0],
  57256. axisModel.get('type'),
  57257. axisModel.get('position')
  57258. );
  57259. var isCategory = axis.type === 'category';
  57260. axis.onBand = isCategory && axisModel.get('boundaryGap');
  57261. axis.inverse = axisModel.get('inverse');
  57262. axis.orient = axisModel.get('orient');
  57263. axisModel.axis = axis;
  57264. axis.model = axisModel;
  57265. axis.coordinateSystem = this;
  57266. this._axis = axis;
  57267. },
  57268. /**
  57269. * Update axis scale after data processed
  57270. * @param {module:echarts/model/Global} ecModel
  57271. * @param {module:echarts/ExtensionAPI} api
  57272. */
  57273. update: function (ecModel, api) {
  57274. ecModel.eachSeries(function (seriesModel) {
  57275. if (seriesModel.coordinateSystem === this) {
  57276. var data = seriesModel.getData();
  57277. each$1(data.mapDimension(this.dimension, true), function (dim) {
  57278. this._axis.scale.unionExtentFromData(data, dim);
  57279. }, this);
  57280. niceScaleExtent(this._axis.scale, this._axis.model);
  57281. }
  57282. }, this);
  57283. },
  57284. /**
  57285. * Resize the single coordinate system.
  57286. *
  57287. * @param {module:echarts/coord/single/AxisModel} axisModel
  57288. * @param {module:echarts/ExtensionAPI} api
  57289. */
  57290. resize: function (axisModel, api) {
  57291. this._rect = getLayoutRect(
  57292. {
  57293. left: axisModel.get('left'),
  57294. top: axisModel.get('top'),
  57295. right: axisModel.get('right'),
  57296. bottom: axisModel.get('bottom'),
  57297. width: axisModel.get('width'),
  57298. height: axisModel.get('height')
  57299. },
  57300. {
  57301. width: api.getWidth(),
  57302. height: api.getHeight()
  57303. }
  57304. );
  57305. this._adjustAxis();
  57306. },
  57307. /**
  57308. * @return {module:zrender/core/BoundingRect}
  57309. */
  57310. getRect: function () {
  57311. return this._rect;
  57312. },
  57313. /**
  57314. * @private
  57315. */
  57316. _adjustAxis: function () {
  57317. var rect = this._rect;
  57318. var axis = this._axis;
  57319. var isHorizontal = axis.isHorizontal();
  57320. var extent = isHorizontal ? [0, rect.width] : [0, rect.height];
  57321. var idx = axis.reverse ? 1 : 0;
  57322. axis.setExtent(extent[idx], extent[1 - idx]);
  57323. this._updateAxisTransform(axis, isHorizontal ? rect.x : rect.y);
  57324. },
  57325. /**
  57326. * @param {module:echarts/coord/single/SingleAxis} axis
  57327. * @param {number} coordBase
  57328. */
  57329. _updateAxisTransform: function (axis, coordBase) {
  57330. var axisExtent = axis.getExtent();
  57331. var extentSum = axisExtent[0] + axisExtent[1];
  57332. var isHorizontal = axis.isHorizontal();
  57333. axis.toGlobalCoord = isHorizontal
  57334. ? function (coord) {
  57335. return coord + coordBase;
  57336. }
  57337. : function (coord) {
  57338. return extentSum - coord + coordBase;
  57339. };
  57340. axis.toLocalCoord = isHorizontal
  57341. ? function (coord) {
  57342. return coord - coordBase;
  57343. }
  57344. : function (coord) {
  57345. return extentSum - coord + coordBase;
  57346. };
  57347. },
  57348. /**
  57349. * Get axis.
  57350. *
  57351. * @return {module:echarts/coord/single/SingleAxis}
  57352. */
  57353. getAxis: function () {
  57354. return this._axis;
  57355. },
  57356. /**
  57357. * Get axis, add it just for draw tooltip.
  57358. *
  57359. * @return {[type]} [description]
  57360. */
  57361. getBaseAxis: function () {
  57362. return this._axis;
  57363. },
  57364. /**
  57365. * @return {Array.<module:echarts/coord/Axis>}
  57366. */
  57367. getAxes: function () {
  57368. return [this._axis];
  57369. },
  57370. /**
  57371. * @return {Object} {baseAxes: [], otherAxes: []}
  57372. */
  57373. getTooltipAxes: function () {
  57374. return {baseAxes: [this.getAxis()]};
  57375. },
  57376. /**
  57377. * If contain point.
  57378. *
  57379. * @param {Array.<number>} point
  57380. * @return {boolean}
  57381. */
  57382. containPoint: function (point) {
  57383. var rect = this.getRect();
  57384. var axis = this.getAxis();
  57385. var orient = axis.orient;
  57386. if (orient === 'horizontal') {
  57387. return axis.contain(axis.toLocalCoord(point[0]))
  57388. && (point[1] >= rect.y && point[1] <= (rect.y + rect.height));
  57389. }
  57390. else {
  57391. return axis.contain(axis.toLocalCoord(point[1]))
  57392. && (point[0] >= rect.y && point[0] <= (rect.y + rect.height));
  57393. }
  57394. },
  57395. /**
  57396. * @param {Array.<number>} point
  57397. * @return {Array.<number>}
  57398. */
  57399. pointToData: function (point) {
  57400. var axis = this.getAxis();
  57401. return [axis.coordToData(axis.toLocalCoord(
  57402. point[axis.orient === 'horizontal' ? 0 : 1]
  57403. ))];
  57404. },
  57405. /**
  57406. * Convert the series data to concrete point.
  57407. *
  57408. * @param {number|Array.<number>} val
  57409. * @return {Array.<number>}
  57410. */
  57411. dataToPoint: function (val) {
  57412. var axis = this.getAxis();
  57413. var rect = this.getRect();
  57414. var pt = [];
  57415. var idx = axis.orient === 'horizontal' ? 0 : 1;
  57416. if (val instanceof Array) {
  57417. val = val[0];
  57418. }
  57419. pt[idx] = axis.toGlobalCoord(axis.dataToCoord(+val));
  57420. pt[1 - idx] = idx === 0 ? (rect.y + rect.height / 2) : (rect.x + rect.width / 2);
  57421. return pt;
  57422. }
  57423. };
  57424. /*
  57425. * Licensed to the Apache Software Foundation (ASF) under one
  57426. * or more contributor license agreements. See the NOTICE file
  57427. * distributed with this work for additional information
  57428. * regarding copyright ownership. The ASF licenses this file
  57429. * to you under the Apache License, Version 2.0 (the
  57430. * "License"); you may not use this file except in compliance
  57431. * with the License. You may obtain a copy of the License at
  57432. *
  57433. * http://www.apache.org/licenses/LICENSE-2.0
  57434. *
  57435. * Unless required by applicable law or agreed to in writing,
  57436. * software distributed under the License is distributed on an
  57437. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57438. * KIND, either express or implied. See the License for the
  57439. * specific language governing permissions and limitations
  57440. * under the License.
  57441. */
  57442. /**
  57443. * Single coordinate system creator.
  57444. */
  57445. /**
  57446. * Create single coordinate system and inject it into seriesModel.
  57447. *
  57448. * @param {module:echarts/model/Global} ecModel
  57449. * @param {module:echarts/ExtensionAPI} api
  57450. * @return {Array.<module:echarts/coord/single/Single>}
  57451. */
  57452. function create$3(ecModel, api) {
  57453. var singles = [];
  57454. ecModel.eachComponent('singleAxis', function (axisModel, idx) {
  57455. var single = new Single(axisModel, ecModel, api);
  57456. single.name = 'single_' + idx;
  57457. single.resize(axisModel, api);
  57458. axisModel.coordinateSystem = single;
  57459. singles.push(single);
  57460. });
  57461. ecModel.eachSeries(function (seriesModel) {
  57462. if (seriesModel.get('coordinateSystem') === 'singleAxis') {
  57463. var singleAxisModel = ecModel.queryComponents({
  57464. mainType: 'singleAxis',
  57465. index: seriesModel.get('singleAxisIndex'),
  57466. id: seriesModel.get('singleAxisId')
  57467. })[0];
  57468. seriesModel.coordinateSystem = singleAxisModel && singleAxisModel.coordinateSystem;
  57469. }
  57470. });
  57471. return singles;
  57472. }
  57473. CoordinateSystemManager.register('single', {
  57474. create: create$3,
  57475. dimensions: Single.prototype.dimensions
  57476. });
  57477. /*
  57478. * Licensed to the Apache Software Foundation (ASF) under one
  57479. * or more contributor license agreements. See the NOTICE file
  57480. * distributed with this work for additional information
  57481. * regarding copyright ownership. The ASF licenses this file
  57482. * to you under the Apache License, Version 2.0 (the
  57483. * "License"); you may not use this file except in compliance
  57484. * with the License. You may obtain a copy of the License at
  57485. *
  57486. * http://www.apache.org/licenses/LICENSE-2.0
  57487. *
  57488. * Unless required by applicable law or agreed to in writing,
  57489. * software distributed under the License is distributed on an
  57490. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57491. * KIND, either express or implied. See the License for the
  57492. * specific language governing permissions and limitations
  57493. * under the License.
  57494. */
  57495. /**
  57496. * @param {Object} opt {labelInside}
  57497. * @return {Object} {
  57498. * position, rotation, labelDirection, labelOffset,
  57499. * tickDirection, labelRotate, z2
  57500. * }
  57501. */
  57502. function layout$2(axisModel, opt) {
  57503. opt = opt || {};
  57504. var single = axisModel.coordinateSystem;
  57505. var axis = axisModel.axis;
  57506. var layout = {};
  57507. var axisPosition = axis.position;
  57508. var orient = axis.orient;
  57509. var rect = single.getRect();
  57510. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  57511. var positionMap = {
  57512. horizontal: {top: rectBound[2], bottom: rectBound[3]},
  57513. vertical: {left: rectBound[0], right: rectBound[1]}
  57514. };
  57515. layout.position = [
  57516. orient === 'vertical'
  57517. ? positionMap.vertical[axisPosition]
  57518. : rectBound[0],
  57519. orient === 'horizontal'
  57520. ? positionMap.horizontal[axisPosition]
  57521. : rectBound[3]
  57522. ];
  57523. var r = {horizontal: 0, vertical: 1};
  57524. layout.rotation = Math.PI / 2 * r[orient];
  57525. var directionMap = {top: -1, bottom: 1, right: 1, left: -1};
  57526. layout.labelDirection = layout.tickDirection
  57527. = layout.nameDirection
  57528. = directionMap[axisPosition];
  57529. if (axisModel.get('axisTick.inside')) {
  57530. layout.tickDirection = -layout.tickDirection;
  57531. }
  57532. if (retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  57533. layout.labelDirection = -layout.labelDirection;
  57534. }
  57535. var labelRotation = opt.rotate;
  57536. labelRotation == null && (labelRotation = axisModel.get('axisLabel.rotate'));
  57537. layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
  57538. layout.z2 = 1;
  57539. return layout;
  57540. }
  57541. /*
  57542. * Licensed to the Apache Software Foundation (ASF) under one
  57543. * or more contributor license agreements. See the NOTICE file
  57544. * distributed with this work for additional information
  57545. * regarding copyright ownership. The ASF licenses this file
  57546. * to you under the Apache License, Version 2.0 (the
  57547. * "License"); you may not use this file except in compliance
  57548. * with the License. You may obtain a copy of the License at
  57549. *
  57550. * http://www.apache.org/licenses/LICENSE-2.0
  57551. *
  57552. * Unless required by applicable law or agreed to in writing,
  57553. * software distributed under the License is distributed on an
  57554. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57555. * KIND, either express or implied. See the License for the
  57556. * specific language governing permissions and limitations
  57557. * under the License.
  57558. */
  57559. var axisBuilderAttrs$2 = [
  57560. 'axisLine', 'axisTickLabel', 'axisName'
  57561. ];
  57562. var selfBuilderAttr = 'splitLine';
  57563. var SingleAxisView = AxisView.extend({
  57564. type: 'singleAxis',
  57565. axisPointerClass: 'SingleAxisPointer',
  57566. render: function (axisModel, ecModel, api, payload) {
  57567. var group = this.group;
  57568. group.removeAll();
  57569. var layout = layout$2(axisModel);
  57570. var axisBuilder = new AxisBuilder(axisModel, layout);
  57571. each$1(axisBuilderAttrs$2, axisBuilder.add, axisBuilder);
  57572. group.add(axisBuilder.getGroup());
  57573. if (axisModel.get(selfBuilderAttr + '.show')) {
  57574. this['_' + selfBuilderAttr](axisModel);
  57575. }
  57576. SingleAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  57577. },
  57578. _splitLine: function (axisModel) {
  57579. var axis = axisModel.axis;
  57580. if (axis.scale.isBlank()) {
  57581. return;
  57582. }
  57583. var splitLineModel = axisModel.getModel('splitLine');
  57584. var lineStyleModel = splitLineModel.getModel('lineStyle');
  57585. var lineWidth = lineStyleModel.get('width');
  57586. var lineColors = lineStyleModel.get('color');
  57587. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  57588. var gridRect = axisModel.coordinateSystem.getRect();
  57589. var isHorizontal = axis.isHorizontal();
  57590. var splitLines = [];
  57591. var lineCount = 0;
  57592. var ticksCoords = axis.getTicksCoords({
  57593. tickModel: splitLineModel
  57594. });
  57595. var p1 = [];
  57596. var p2 = [];
  57597. for (var i = 0; i < ticksCoords.length; ++i) {
  57598. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  57599. if (isHorizontal) {
  57600. p1[0] = tickCoord;
  57601. p1[1] = gridRect.y;
  57602. p2[0] = tickCoord;
  57603. p2[1] = gridRect.y + gridRect.height;
  57604. }
  57605. else {
  57606. p1[0] = gridRect.x;
  57607. p1[1] = tickCoord;
  57608. p2[0] = gridRect.x + gridRect.width;
  57609. p2[1] = tickCoord;
  57610. }
  57611. var colorIndex = (lineCount++) % lineColors.length;
  57612. splitLines[colorIndex] = splitLines[colorIndex] || [];
  57613. splitLines[colorIndex].push(new Line(
  57614. subPixelOptimizeLine({
  57615. shape: {
  57616. x1: p1[0],
  57617. y1: p1[1],
  57618. x2: p2[0],
  57619. y2: p2[1]
  57620. },
  57621. style: {
  57622. lineWidth: lineWidth
  57623. },
  57624. silent: true
  57625. })));
  57626. }
  57627. for (var i = 0; i < splitLines.length; ++i) {
  57628. this.group.add(mergePath(splitLines[i], {
  57629. style: {
  57630. stroke: lineColors[i % lineColors.length],
  57631. lineDash: lineStyleModel.getLineDash(lineWidth),
  57632. lineWidth: lineWidth
  57633. },
  57634. silent: true
  57635. }));
  57636. }
  57637. }
  57638. });
  57639. /*
  57640. * Licensed to the Apache Software Foundation (ASF) under one
  57641. * or more contributor license agreements. See the NOTICE file
  57642. * distributed with this work for additional information
  57643. * regarding copyright ownership. The ASF licenses this file
  57644. * to you under the Apache License, Version 2.0 (the
  57645. * "License"); you may not use this file except in compliance
  57646. * with the License. You may obtain a copy of the License at
  57647. *
  57648. * http://www.apache.org/licenses/LICENSE-2.0
  57649. *
  57650. * Unless required by applicable law or agreed to in writing,
  57651. * software distributed under the License is distributed on an
  57652. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57653. * KIND, either express or implied. See the License for the
  57654. * specific language governing permissions and limitations
  57655. * under the License.
  57656. */
  57657. var AxisModel$4 = ComponentModel.extend({
  57658. type: 'singleAxis',
  57659. layoutMode: 'box',
  57660. /**
  57661. * @type {module:echarts/coord/single/SingleAxis}
  57662. */
  57663. axis: null,
  57664. /**
  57665. * @type {module:echarts/coord/single/Single}
  57666. */
  57667. coordinateSystem: null,
  57668. /**
  57669. * @override
  57670. */
  57671. getCoordSysModel: function () {
  57672. return this;
  57673. }
  57674. });
  57675. var defaultOption$2 = {
  57676. left: '5%',
  57677. top: '5%',
  57678. right: '5%',
  57679. bottom: '5%',
  57680. type: 'value',
  57681. position: 'bottom',
  57682. orient: 'horizontal',
  57683. axisLine: {
  57684. show: true,
  57685. lineStyle: {
  57686. width: 2,
  57687. type: 'solid'
  57688. }
  57689. },
  57690. // Single coordinate system and single axis is the,
  57691. // which is used as the parent tooltip model.
  57692. // same model, so we set default tooltip show as true.
  57693. tooltip: {
  57694. show: true
  57695. },
  57696. axisTick: {
  57697. show: true,
  57698. length: 6,
  57699. lineStyle: {
  57700. width: 2
  57701. }
  57702. },
  57703. axisLabel: {
  57704. show: true,
  57705. interval: 'auto'
  57706. },
  57707. splitLine: {
  57708. show: true,
  57709. lineStyle: {
  57710. type: 'dashed',
  57711. opacity: 0.2
  57712. }
  57713. }
  57714. };
  57715. function getAxisType$2(axisName, option) {
  57716. return option.type || (option.data ? 'category' : 'value');
  57717. }
  57718. merge(AxisModel$4.prototype, axisModelCommonMixin);
  57719. axisModelCreator('single', AxisModel$4, getAxisType$2, defaultOption$2);
  57720. /*
  57721. * Licensed to the Apache Software Foundation (ASF) under one
  57722. * or more contributor license agreements. See the NOTICE file
  57723. * distributed with this work for additional information
  57724. * regarding copyright ownership. The ASF licenses this file
  57725. * to you under the Apache License, Version 2.0 (the
  57726. * "License"); you may not use this file except in compliance
  57727. * with the License. You may obtain a copy of the License at
  57728. *
  57729. * http://www.apache.org/licenses/LICENSE-2.0
  57730. *
  57731. * Unless required by applicable law or agreed to in writing,
  57732. * software distributed under the License is distributed on an
  57733. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57734. * KIND, either express or implied. See the License for the
  57735. * specific language governing permissions and limitations
  57736. * under the License.
  57737. */
  57738. /**
  57739. * @param {Object} finder contains {seriesIndex, dataIndex, dataIndexInside}
  57740. * @param {module:echarts/model/Global} ecModel
  57741. * @return {Object} {point: [x, y], el: ...} point Will not be null.
  57742. */
  57743. var findPointFromSeries = function (finder, ecModel) {
  57744. var point = [];
  57745. var seriesIndex = finder.seriesIndex;
  57746. var seriesModel;
  57747. if (seriesIndex == null || !(
  57748. seriesModel = ecModel.getSeriesByIndex(seriesIndex)
  57749. )) {
  57750. return {point: []};
  57751. }
  57752. var data = seriesModel.getData();
  57753. var dataIndex = queryDataIndex(data, finder);
  57754. if (dataIndex == null || dataIndex < 0 || isArray(dataIndex)) {
  57755. return {point: []};
  57756. }
  57757. var el = data.getItemGraphicEl(dataIndex);
  57758. var coordSys = seriesModel.coordinateSystem;
  57759. if (seriesModel.getTooltipPosition) {
  57760. point = seriesModel.getTooltipPosition(dataIndex) || [];
  57761. }
  57762. else if (coordSys && coordSys.dataToPoint) {
  57763. point = coordSys.dataToPoint(
  57764. data.getValues(
  57765. map(coordSys.dimensions, function (dim) {
  57766. return data.mapDimension(dim);
  57767. }), dataIndex, true
  57768. )
  57769. ) || [];
  57770. }
  57771. else if (el) {
  57772. // Use graphic bounding rect
  57773. var rect = el.getBoundingRect().clone();
  57774. rect.applyTransform(el.transform);
  57775. point = [
  57776. rect.x + rect.width / 2,
  57777. rect.y + rect.height / 2
  57778. ];
  57779. }
  57780. return {point: point, el: el};
  57781. };
  57782. /*
  57783. * Licensed to the Apache Software Foundation (ASF) under one
  57784. * or more contributor license agreements. See the NOTICE file
  57785. * distributed with this work for additional information
  57786. * regarding copyright ownership. The ASF licenses this file
  57787. * to you under the Apache License, Version 2.0 (the
  57788. * "License"); you may not use this file except in compliance
  57789. * with the License. You may obtain a copy of the License at
  57790. *
  57791. * http://www.apache.org/licenses/LICENSE-2.0
  57792. *
  57793. * Unless required by applicable law or agreed to in writing,
  57794. * software distributed under the License is distributed on an
  57795. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57796. * KIND, either express or implied. See the License for the
  57797. * specific language governing permissions and limitations
  57798. * under the License.
  57799. */
  57800. var each$14 = each$1;
  57801. var curry$3 = curry;
  57802. var inner$9 = makeInner();
  57803. /**
  57804. * Basic logic: check all axis, if they do not demand show/highlight,
  57805. * then hide/downplay them.
  57806. *
  57807. * @param {Object} coordSysAxesInfo
  57808. * @param {Object} payload
  57809. * @param {string} [payload.currTrigger] 'click' | 'mousemove' | 'leave'
  57810. * @param {Array.<number>} [payload.x] x and y, which are mandatory, specify a point to
  57811. * trigger axisPointer and tooltip.
  57812. * @param {Array.<number>} [payload.y] x and y, which are mandatory, specify a point to
  57813. * trigger axisPointer and tooltip.
  57814. * @param {Object} [payload.seriesIndex] finder, optional, restrict target axes.
  57815. * @param {Object} [payload.dataIndex] finder, restrict target axes.
  57816. * @param {Object} [payload.axesInfo] finder, restrict target axes.
  57817. * [{
  57818. * axisDim: 'x'|'y'|'angle'|...,
  57819. * axisIndex: ...,
  57820. * value: ...
  57821. * }, ...]
  57822. * @param {Function} [payload.dispatchAction]
  57823. * @param {Object} [payload.tooltipOption]
  57824. * @param {Object|Array.<number>|Function} [payload.position] Tooltip position,
  57825. * which can be specified in dispatchAction
  57826. * @param {module:echarts/model/Global} ecModel
  57827. * @param {module:echarts/ExtensionAPI} api
  57828. * @return {Object} content of event obj for echarts.connect.
  57829. */
  57830. var axisTrigger = function (payload, ecModel, api) {
  57831. var currTrigger = payload.currTrigger;
  57832. var point = [payload.x, payload.y];
  57833. var finder = payload;
  57834. var dispatchAction = payload.dispatchAction || bind(api.dispatchAction, api);
  57835. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  57836. // Pending
  57837. // See #6121. But we are not able to reproduce it yet.
  57838. if (!coordSysAxesInfo) {
  57839. return;
  57840. }
  57841. if (illegalPoint(point)) {
  57842. // Used in the default behavior of `connection`: use the sample seriesIndex
  57843. // and dataIndex. And also used in the tooltipView trigger.
  57844. point = findPointFromSeries({
  57845. seriesIndex: finder.seriesIndex,
  57846. // Do not use dataIndexInside from other ec instance.
  57847. // FIXME: auto detect it?
  57848. dataIndex: finder.dataIndex
  57849. }, ecModel).point;
  57850. }
  57851. var isIllegalPoint = illegalPoint(point);
  57852. // Axis and value can be specified when calling dispatchAction({type: 'updateAxisPointer'}).
  57853. // Notice: In this case, it is difficult to get the `point` (which is necessary to show
  57854. // tooltip, so if point is not given, we just use the point found by sample seriesIndex
  57855. // and dataIndex.
  57856. var inputAxesInfo = finder.axesInfo;
  57857. var axesInfo = coordSysAxesInfo.axesInfo;
  57858. var shouldHide = currTrigger === 'leave' || illegalPoint(point);
  57859. var outputFinder = {};
  57860. var showValueMap = {};
  57861. var dataByCoordSys = {list: [], map: {}};
  57862. var updaters = {
  57863. showPointer: curry$3(showPointer, showValueMap),
  57864. showTooltip: curry$3(showTooltip, dataByCoordSys)
  57865. };
  57866. // Process for triggered axes.
  57867. each$14(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
  57868. // If a point given, it must be contained by the coordinate system.
  57869. var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
  57870. each$14(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo, key) {
  57871. var axis = axisInfo.axis;
  57872. var inputAxisInfo = findInputAxisInfo(inputAxesInfo, axisInfo);
  57873. // If no inputAxesInfo, no axis is restricted.
  57874. if (!shouldHide && coordSysContainsPoint && (!inputAxesInfo || inputAxisInfo)) {
  57875. var val = inputAxisInfo && inputAxisInfo.value;
  57876. if (val == null && !isIllegalPoint) {
  57877. val = axis.pointToData(point);
  57878. }
  57879. val != null && processOnAxis(axisInfo, val, updaters, false, outputFinder);
  57880. }
  57881. });
  57882. });
  57883. // Process for linked axes.
  57884. var linkTriggers = {};
  57885. each$14(axesInfo, function (tarAxisInfo, tarKey) {
  57886. var linkGroup = tarAxisInfo.linkGroup;
  57887. // If axis has been triggered in the previous stage, it should not be triggered by link.
  57888. if (linkGroup && !showValueMap[tarKey]) {
  57889. each$14(linkGroup.axesInfo, function (srcAxisInfo, srcKey) {
  57890. var srcValItem = showValueMap[srcKey];
  57891. // If srcValItem exist, source axis is triggered, so link to target axis.
  57892. if (srcAxisInfo !== tarAxisInfo && srcValItem) {
  57893. var val = srcValItem.value;
  57894. linkGroup.mapper && (val = tarAxisInfo.axis.scale.parse(linkGroup.mapper(
  57895. val, makeMapperParam(srcAxisInfo), makeMapperParam(tarAxisInfo)
  57896. )));
  57897. linkTriggers[tarAxisInfo.key] = val;
  57898. }
  57899. });
  57900. }
  57901. });
  57902. each$14(linkTriggers, function (val, tarKey) {
  57903. processOnAxis(axesInfo[tarKey], val, updaters, true, outputFinder);
  57904. });
  57905. updateModelActually(showValueMap, axesInfo, outputFinder);
  57906. dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction);
  57907. dispatchHighDownActually(axesInfo, dispatchAction, api);
  57908. return outputFinder;
  57909. };
  57910. function processOnAxis(axisInfo, newValue, updaters, dontSnap, outputFinder) {
  57911. var axis = axisInfo.axis;
  57912. if (axis.scale.isBlank() || !axis.containData(newValue)) {
  57913. return;
  57914. }
  57915. if (!axisInfo.involveSeries) {
  57916. updaters.showPointer(axisInfo, newValue);
  57917. return;
  57918. }
  57919. // Heavy calculation. So put it after axis.containData checking.
  57920. var payloadInfo = buildPayloadsBySeries(newValue, axisInfo);
  57921. var payloadBatch = payloadInfo.payloadBatch;
  57922. var snapToValue = payloadInfo.snapToValue;
  57923. // Fill content of event obj for echarts.connect.
  57924. // By defualt use the first involved series data as a sample to connect.
  57925. if (payloadBatch[0] && outputFinder.seriesIndex == null) {
  57926. extend(outputFinder, payloadBatch[0]);
  57927. }
  57928. // If no linkSource input, this process is for collecting link
  57929. // target, where snap should not be accepted.
  57930. if (!dontSnap && axisInfo.snap) {
  57931. if (axis.containData(snapToValue) && snapToValue != null) {
  57932. newValue = snapToValue;
  57933. }
  57934. }
  57935. updaters.showPointer(axisInfo, newValue, payloadBatch, outputFinder);
  57936. // Tooltip should always be snapToValue, otherwise there will be
  57937. // incorrect "axis value ~ series value" mapping displayed in tooltip.
  57938. updaters.showTooltip(axisInfo, payloadInfo, snapToValue);
  57939. }
  57940. function buildPayloadsBySeries(value, axisInfo) {
  57941. var axis = axisInfo.axis;
  57942. var dim = axis.dim;
  57943. var snapToValue = value;
  57944. var payloadBatch = [];
  57945. var minDist = Number.MAX_VALUE;
  57946. var minDiff = -1;
  57947. each$14(axisInfo.seriesModels, function (series, idx) {
  57948. var dataDim = series.getData().mapDimension(dim, true);
  57949. var seriesNestestValue;
  57950. var dataIndices;
  57951. if (series.getAxisTooltipData) {
  57952. var result = series.getAxisTooltipData(dataDim, value, axis);
  57953. dataIndices = result.dataIndices;
  57954. seriesNestestValue = result.nestestValue;
  57955. }
  57956. else {
  57957. dataIndices = series.getData().indicesOfNearest(
  57958. dataDim[0],
  57959. value,
  57960. // Add a threshold to avoid find the wrong dataIndex
  57961. // when data length is not same.
  57962. // false,
  57963. axis.type === 'category' ? 0.5 : null
  57964. );
  57965. if (!dataIndices.length) {
  57966. return;
  57967. }
  57968. seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
  57969. }
  57970. if (seriesNestestValue == null || !isFinite(seriesNestestValue)) {
  57971. return;
  57972. }
  57973. var diff = value - seriesNestestValue;
  57974. var dist = Math.abs(diff);
  57975. // Consider category case
  57976. if (dist <= minDist) {
  57977. if (dist < minDist || (diff >= 0 && minDiff < 0)) {
  57978. minDist = dist;
  57979. minDiff = diff;
  57980. snapToValue = seriesNestestValue;
  57981. payloadBatch.length = 0;
  57982. }
  57983. each$14(dataIndices, function (dataIndex) {
  57984. payloadBatch.push({
  57985. seriesIndex: series.seriesIndex,
  57986. dataIndexInside: dataIndex,
  57987. dataIndex: series.getData().getRawIndex(dataIndex)
  57988. });
  57989. });
  57990. }
  57991. });
  57992. return {
  57993. payloadBatch: payloadBatch,
  57994. snapToValue: snapToValue
  57995. };
  57996. }
  57997. function showPointer(showValueMap, axisInfo, value, payloadBatch) {
  57998. showValueMap[axisInfo.key] = {value: value, payloadBatch: payloadBatch};
  57999. }
  58000. function showTooltip(dataByCoordSys, axisInfo, payloadInfo, value) {
  58001. var payloadBatch = payloadInfo.payloadBatch;
  58002. var axis = axisInfo.axis;
  58003. var axisModel = axis.model;
  58004. var axisPointerModel = axisInfo.axisPointerModel;
  58005. // If no data, do not create anything in dataByCoordSys,
  58006. // whose length will be used to judge whether dispatch action.
  58007. if (!axisInfo.triggerTooltip || !payloadBatch.length) {
  58008. return;
  58009. }
  58010. var coordSysModel = axisInfo.coordSys.model;
  58011. var coordSysKey = makeKey(coordSysModel);
  58012. var coordSysItem = dataByCoordSys.map[coordSysKey];
  58013. if (!coordSysItem) {
  58014. coordSysItem = dataByCoordSys.map[coordSysKey] = {
  58015. coordSysId: coordSysModel.id,
  58016. coordSysIndex: coordSysModel.componentIndex,
  58017. coordSysType: coordSysModel.type,
  58018. coordSysMainType: coordSysModel.mainType,
  58019. dataByAxis: []
  58020. };
  58021. dataByCoordSys.list.push(coordSysItem);
  58022. }
  58023. coordSysItem.dataByAxis.push({
  58024. axisDim: axis.dim,
  58025. axisIndex: axisModel.componentIndex,
  58026. axisType: axisModel.type,
  58027. axisId: axisModel.id,
  58028. value: value,
  58029. // Caustion: viewHelper.getValueLabel is actually on "view stage", which
  58030. // depends that all models have been updated. So it should not be performed
  58031. // here. Considering axisPointerModel used here is volatile, which is hard
  58032. // to be retrieve in TooltipView, we prepare parameters here.
  58033. valueLabelOpt: {
  58034. precision: axisPointerModel.get('label.precision'),
  58035. formatter: axisPointerModel.get('label.formatter')
  58036. },
  58037. seriesDataIndices: payloadBatch.slice()
  58038. });
  58039. }
  58040. function updateModelActually(showValueMap, axesInfo, outputFinder) {
  58041. var outputAxesInfo = outputFinder.axesInfo = [];
  58042. // Basic logic: If no 'show' required, 'hide' this axisPointer.
  58043. each$14(axesInfo, function (axisInfo, key) {
  58044. var option = axisInfo.axisPointerModel.option;
  58045. var valItem = showValueMap[key];
  58046. if (valItem) {
  58047. !axisInfo.useHandle && (option.status = 'show');
  58048. option.value = valItem.value;
  58049. // For label formatter param and highlight.
  58050. option.seriesDataIndices = (valItem.payloadBatch || []).slice();
  58051. }
  58052. // When always show (e.g., handle used), remain
  58053. // original value and status.
  58054. else {
  58055. // If hide, value still need to be set, consider
  58056. // click legend to toggle axis blank.
  58057. !axisInfo.useHandle && (option.status = 'hide');
  58058. }
  58059. // If status is 'hide', should be no info in payload.
  58060. option.status === 'show' && outputAxesInfo.push({
  58061. axisDim: axisInfo.axis.dim,
  58062. axisIndex: axisInfo.axis.model.componentIndex,
  58063. value: option.value
  58064. });
  58065. });
  58066. }
  58067. function dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction) {
  58068. // Basic logic: If no showTip required, hideTip will be dispatched.
  58069. if (illegalPoint(point) || !dataByCoordSys.list.length) {
  58070. dispatchAction({type: 'hideTip'});
  58071. return;
  58072. }
  58073. // In most case only one axis (or event one series is used). It is
  58074. // convinient to fetch payload.seriesIndex and payload.dataIndex
  58075. // dirtectly. So put the first seriesIndex and dataIndex of the first
  58076. // axis on the payload.
  58077. var sampleItem = ((dataByCoordSys.list[0].dataByAxis[0] || {}).seriesDataIndices || [])[0] || {};
  58078. dispatchAction({
  58079. type: 'showTip',
  58080. escapeConnect: true,
  58081. x: point[0],
  58082. y: point[1],
  58083. tooltipOption: payload.tooltipOption,
  58084. position: payload.position,
  58085. dataIndexInside: sampleItem.dataIndexInside,
  58086. dataIndex: sampleItem.dataIndex,
  58087. seriesIndex: sampleItem.seriesIndex,
  58088. dataByCoordSys: dataByCoordSys.list
  58089. });
  58090. }
  58091. function dispatchHighDownActually(axesInfo, dispatchAction, api) {
  58092. // FIXME
  58093. // highlight status modification shoule be a stage of main process?
  58094. // (Consider confilct (e.g., legend and axisPointer) and setOption)
  58095. var zr = api.getZr();
  58096. var highDownKey = 'axisPointerLastHighlights';
  58097. var lastHighlights = inner$9(zr)[highDownKey] || {};
  58098. var newHighlights = inner$9(zr)[highDownKey] = {};
  58099. // Update highlight/downplay status according to axisPointer model.
  58100. // Build hash map and remove duplicate incidentally.
  58101. each$14(axesInfo, function (axisInfo, key) {
  58102. var option = axisInfo.axisPointerModel.option;
  58103. option.status === 'show' && each$14(option.seriesDataIndices, function (batchItem) {
  58104. var key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
  58105. newHighlights[key] = batchItem;
  58106. });
  58107. });
  58108. // Diff.
  58109. var toHighlight = [];
  58110. var toDownplay = [];
  58111. each$1(lastHighlights, function (batchItem, key) {
  58112. !newHighlights[key] && toDownplay.push(batchItem);
  58113. });
  58114. each$1(newHighlights, function (batchItem, key) {
  58115. !lastHighlights[key] && toHighlight.push(batchItem);
  58116. });
  58117. toDownplay.length && api.dispatchAction({
  58118. type: 'downplay', escapeConnect: true, batch: toDownplay
  58119. });
  58120. toHighlight.length && api.dispatchAction({
  58121. type: 'highlight', escapeConnect: true, batch: toHighlight
  58122. });
  58123. }
  58124. function findInputAxisInfo(inputAxesInfo, axisInfo) {
  58125. for (var i = 0; i < (inputAxesInfo || []).length; i++) {
  58126. var inputAxisInfo = inputAxesInfo[i];
  58127. if (axisInfo.axis.dim === inputAxisInfo.axisDim
  58128. && axisInfo.axis.model.componentIndex === inputAxisInfo.axisIndex
  58129. ) {
  58130. return inputAxisInfo;
  58131. }
  58132. }
  58133. }
  58134. function makeMapperParam(axisInfo) {
  58135. var axisModel = axisInfo.axis.model;
  58136. var item = {};
  58137. var dim = item.axisDim = axisInfo.axis.dim;
  58138. item.axisIndex = item[dim + 'AxisIndex'] = axisModel.componentIndex;
  58139. item.axisName = item[dim + 'AxisName'] = axisModel.name;
  58140. item.axisId = item[dim + 'AxisId'] = axisModel.id;
  58141. return item;
  58142. }
  58143. function illegalPoint(point) {
  58144. return !point || point[0] == null || isNaN(point[0]) || point[1] == null || isNaN(point[1]);
  58145. }
  58146. /*
  58147. * Licensed to the Apache Software Foundation (ASF) under one
  58148. * or more contributor license agreements. See the NOTICE file
  58149. * distributed with this work for additional information
  58150. * regarding copyright ownership. The ASF licenses this file
  58151. * to you under the Apache License, Version 2.0 (the
  58152. * "License"); you may not use this file except in compliance
  58153. * with the License. You may obtain a copy of the License at
  58154. *
  58155. * http://www.apache.org/licenses/LICENSE-2.0
  58156. *
  58157. * Unless required by applicable law or agreed to in writing,
  58158. * software distributed under the License is distributed on an
  58159. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58160. * KIND, either express or implied. See the License for the
  58161. * specific language governing permissions and limitations
  58162. * under the License.
  58163. */
  58164. var AxisPointerModel = extendComponentModel({
  58165. type: 'axisPointer',
  58166. coordSysAxesInfo: null,
  58167. defaultOption: {
  58168. // 'auto' means that show when triggered by tooltip or handle.
  58169. show: 'auto',
  58170. // 'click' | 'mousemove' | 'none'
  58171. triggerOn: null, // set default in AxisPonterView.js
  58172. zlevel: 0,
  58173. z: 50,
  58174. type: 'line', // 'line' 'shadow' 'cross' 'none'.
  58175. // axispointer triggered by tootip determine snap automatically,
  58176. // see `modelHelper`.
  58177. snap: false,
  58178. triggerTooltip: true,
  58179. value: null,
  58180. status: null, // Init value depends on whether handle is used.
  58181. // [group0, group1, ...]
  58182. // Each group can be: {
  58183. // mapper: function () {},
  58184. // singleTooltip: 'multiple', // 'multiple' or 'single'
  58185. // xAxisId: ...,
  58186. // yAxisName: ...,
  58187. // angleAxisIndex: ...
  58188. // }
  58189. // mapper: can be ignored.
  58190. // input: {axisInfo, value}
  58191. // output: {axisInfo, value}
  58192. link: [],
  58193. // Do not set 'auto' here, otherwise global animation: false
  58194. // will not effect at this axispointer.
  58195. animation: null,
  58196. animationDurationUpdate: 200,
  58197. lineStyle: {
  58198. color: '#aaa',
  58199. width: 1,
  58200. type: 'solid'
  58201. },
  58202. shadowStyle: {
  58203. color: 'rgba(150,150,150,0.3)'
  58204. },
  58205. label: {
  58206. show: true,
  58207. formatter: null, // string | Function
  58208. precision: 'auto', // Or a number like 0, 1, 2 ...
  58209. margin: 3,
  58210. color: '#fff',
  58211. padding: [5, 7, 5, 7],
  58212. backgroundColor: 'auto', // default: axis line color
  58213. borderColor: null,
  58214. borderWidth: 0,
  58215. shadowBlur: 3,
  58216. shadowColor: '#aaa'
  58217. // Considering applicability, common style should
  58218. // better not have shadowOffset.
  58219. // shadowOffsetX: 0,
  58220. // shadowOffsetY: 2
  58221. },
  58222. handle: {
  58223. show: false,
  58224. /* eslint-disable */
  58225. icon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
  58226. /* eslint-enable */
  58227. size: 45,
  58228. // handle margin is from symbol center to axis, which is stable when circular move.
  58229. margin: 50,
  58230. // color: '#1b8bbd'
  58231. // color: '#2f4554'
  58232. color: '#333',
  58233. shadowBlur: 3,
  58234. shadowColor: '#aaa',
  58235. shadowOffsetX: 0,
  58236. shadowOffsetY: 2,
  58237. // For mobile performance
  58238. throttle: 40
  58239. }
  58240. }
  58241. });
  58242. /*
  58243. * Licensed to the Apache Software Foundation (ASF) under one
  58244. * or more contributor license agreements. See the NOTICE file
  58245. * distributed with this work for additional information
  58246. * regarding copyright ownership. The ASF licenses this file
  58247. * to you under the Apache License, Version 2.0 (the
  58248. * "License"); you may not use this file except in compliance
  58249. * with the License. You may obtain a copy of the License at
  58250. *
  58251. * http://www.apache.org/licenses/LICENSE-2.0
  58252. *
  58253. * Unless required by applicable law or agreed to in writing,
  58254. * software distributed under the License is distributed on an
  58255. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58256. * KIND, either express or implied. See the License for the
  58257. * specific language governing permissions and limitations
  58258. * under the License.
  58259. */
  58260. var inner$10 = makeInner();
  58261. var each$15 = each$1;
  58262. /**
  58263. * @param {string} key
  58264. * @param {module:echarts/ExtensionAPI} api
  58265. * @param {Function} handler
  58266. * param: {string} currTrigger
  58267. * param: {Array.<number>} point
  58268. */
  58269. function register(key, api, handler) {
  58270. if (env$1.node) {
  58271. return;
  58272. }
  58273. var zr = api.getZr();
  58274. inner$10(zr).records || (inner$10(zr).records = {});
  58275. initGlobalListeners(zr, api);
  58276. var record = inner$10(zr).records[key] || (inner$10(zr).records[key] = {});
  58277. record.handler = handler;
  58278. }
  58279. function initGlobalListeners(zr, api) {
  58280. if (inner$10(zr).initialized) {
  58281. return;
  58282. }
  58283. inner$10(zr).initialized = true;
  58284. useHandler('click', curry(doEnter, 'click'));
  58285. useHandler('mousemove', curry(doEnter, 'mousemove'));
  58286. // useHandler('mouseout', onLeave);
  58287. useHandler('globalout', onLeave);
  58288. function useHandler(eventType, cb) {
  58289. zr.on(eventType, function (e) {
  58290. var dis = makeDispatchAction(api);
  58291. each$15(inner$10(zr).records, function (record) {
  58292. record && cb(record, e, dis.dispatchAction);
  58293. });
  58294. dispatchTooltipFinally(dis.pendings, api);
  58295. });
  58296. }
  58297. }
  58298. function dispatchTooltipFinally(pendings, api) {
  58299. var showLen = pendings.showTip.length;
  58300. var hideLen = pendings.hideTip.length;
  58301. var actuallyPayload;
  58302. if (showLen) {
  58303. actuallyPayload = pendings.showTip[showLen - 1];
  58304. }
  58305. else if (hideLen) {
  58306. actuallyPayload = pendings.hideTip[hideLen - 1];
  58307. }
  58308. if (actuallyPayload) {
  58309. actuallyPayload.dispatchAction = null;
  58310. api.dispatchAction(actuallyPayload);
  58311. }
  58312. }
  58313. function onLeave(record, e, dispatchAction) {
  58314. record.handler('leave', null, dispatchAction);
  58315. }
  58316. function doEnter(currTrigger, record, e, dispatchAction) {
  58317. record.handler(currTrigger, e, dispatchAction);
  58318. }
  58319. function makeDispatchAction(api) {
  58320. var pendings = {
  58321. showTip: [],
  58322. hideTip: []
  58323. };
  58324. // FIXME
  58325. // better approach?
  58326. // 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
  58327. // which may be conflict, (axisPointer call showTip but tooltip call hideTip);
  58328. // So we have to add "final stage" to merge those dispatched actions.
  58329. var dispatchAction = function (payload) {
  58330. var pendingList = pendings[payload.type];
  58331. if (pendingList) {
  58332. pendingList.push(payload);
  58333. }
  58334. else {
  58335. payload.dispatchAction = dispatchAction;
  58336. api.dispatchAction(payload);
  58337. }
  58338. };
  58339. return {
  58340. dispatchAction: dispatchAction,
  58341. pendings: pendings
  58342. };
  58343. }
  58344. /**
  58345. * @param {string} key
  58346. * @param {module:echarts/ExtensionAPI} api
  58347. */
  58348. function unregister(key, api) {
  58349. if (env$1.node) {
  58350. return;
  58351. }
  58352. var zr = api.getZr();
  58353. var record = (inner$10(zr).records || {})[key];
  58354. if (record) {
  58355. inner$10(zr).records[key] = null;
  58356. }
  58357. }
  58358. /*
  58359. * Licensed to the Apache Software Foundation (ASF) under one
  58360. * or more contributor license agreements. See the NOTICE file
  58361. * distributed with this work for additional information
  58362. * regarding copyright ownership. The ASF licenses this file
  58363. * to you under the Apache License, Version 2.0 (the
  58364. * "License"); you may not use this file except in compliance
  58365. * with the License. You may obtain a copy of the License at
  58366. *
  58367. * http://www.apache.org/licenses/LICENSE-2.0
  58368. *
  58369. * Unless required by applicable law or agreed to in writing,
  58370. * software distributed under the License is distributed on an
  58371. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58372. * KIND, either express or implied. See the License for the
  58373. * specific language governing permissions and limitations
  58374. * under the License.
  58375. */
  58376. var AxisPointerView = extendComponentView({
  58377. type: 'axisPointer',
  58378. render: function (globalAxisPointerModel, ecModel, api) {
  58379. var globalTooltipModel = ecModel.getComponent('tooltip');
  58380. var triggerOn = globalAxisPointerModel.get('triggerOn')
  58381. || (globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click');
  58382. // Register global listener in AxisPointerView to enable
  58383. // AxisPointerView to be independent to Tooltip.
  58384. register(
  58385. 'axisPointer',
  58386. api,
  58387. function (currTrigger, e, dispatchAction) {
  58388. // If 'none', it is not controlled by mouse totally.
  58389. if (triggerOn !== 'none'
  58390. && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)
  58391. ) {
  58392. dispatchAction({
  58393. type: 'updateAxisPointer',
  58394. currTrigger: currTrigger,
  58395. x: e && e.offsetX,
  58396. y: e && e.offsetY
  58397. });
  58398. }
  58399. }
  58400. );
  58401. },
  58402. /**
  58403. * @override
  58404. */
  58405. remove: function (ecModel, api) {
  58406. unregister(api.getZr(), 'axisPointer');
  58407. AxisPointerView.superApply(this._model, 'remove', arguments);
  58408. },
  58409. /**
  58410. * @override
  58411. */
  58412. dispose: function (ecModel, api) {
  58413. unregister('axisPointer', api);
  58414. AxisPointerView.superApply(this._model, 'dispose', arguments);
  58415. }
  58416. });
  58417. /*
  58418. * Licensed to the Apache Software Foundation (ASF) under one
  58419. * or more contributor license agreements. See the NOTICE file
  58420. * distributed with this work for additional information
  58421. * regarding copyright ownership. The ASF licenses this file
  58422. * to you under the Apache License, Version 2.0 (the
  58423. * "License"); you may not use this file except in compliance
  58424. * with the License. You may obtain a copy of the License at
  58425. *
  58426. * http://www.apache.org/licenses/LICENSE-2.0
  58427. *
  58428. * Unless required by applicable law or agreed to in writing,
  58429. * software distributed under the License is distributed on an
  58430. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58431. * KIND, either express or implied. See the License for the
  58432. * specific language governing permissions and limitations
  58433. * under the License.
  58434. */
  58435. var inner$11 = makeInner();
  58436. var clone$4 = clone;
  58437. var bind$2 = bind;
  58438. /**
  58439. * Base axis pointer class in 2D.
  58440. * Implemenents {module:echarts/component/axis/IAxisPointer}.
  58441. */
  58442. function BaseAxisPointer() {
  58443. }
  58444. BaseAxisPointer.prototype = {
  58445. /**
  58446. * @private
  58447. */
  58448. _group: null,
  58449. /**
  58450. * @private
  58451. */
  58452. _lastGraphicKey: null,
  58453. /**
  58454. * @private
  58455. */
  58456. _handle: null,
  58457. /**
  58458. * @private
  58459. */
  58460. _dragging: false,
  58461. /**
  58462. * @private
  58463. */
  58464. _lastValue: null,
  58465. /**
  58466. * @private
  58467. */
  58468. _lastStatus: null,
  58469. /**
  58470. * @private
  58471. */
  58472. _payloadInfo: null,
  58473. /**
  58474. * In px, arbitrary value. Do not set too small,
  58475. * no animation is ok for most cases.
  58476. * @protected
  58477. */
  58478. animationThreshold: 15,
  58479. /**
  58480. * @implement
  58481. */
  58482. render: function (axisModel, axisPointerModel, api, forceRender) {
  58483. var value = axisPointerModel.get('value');
  58484. var status = axisPointerModel.get('status');
  58485. // Bind them to `this`, not in closure, otherwise they will not
  58486. // be replaced when user calling setOption in not merge mode.
  58487. this._axisModel = axisModel;
  58488. this._axisPointerModel = axisPointerModel;
  58489. this._api = api;
  58490. // Optimize: `render` will be called repeatly during mouse move.
  58491. // So it is power consuming if performing `render` each time,
  58492. // especially on mobile device.
  58493. if (!forceRender
  58494. && this._lastValue === value
  58495. && this._lastStatus === status
  58496. ) {
  58497. return;
  58498. }
  58499. this._lastValue = value;
  58500. this._lastStatus = status;
  58501. var group = this._group;
  58502. var handle = this._handle;
  58503. if (!status || status === 'hide') {
  58504. // Do not clear here, for animation better.
  58505. group && group.hide();
  58506. handle && handle.hide();
  58507. return;
  58508. }
  58509. group && group.show();
  58510. handle && handle.show();
  58511. // Otherwise status is 'show'
  58512. var elOption = {};
  58513. this.makeElOption(elOption, value, axisModel, axisPointerModel, api);
  58514. // Enable change axis pointer type.
  58515. var graphicKey = elOption.graphicKey;
  58516. if (graphicKey !== this._lastGraphicKey) {
  58517. this.clear(api);
  58518. }
  58519. this._lastGraphicKey = graphicKey;
  58520. var moveAnimation = this._moveAnimation
  58521. = this.determineAnimation(axisModel, axisPointerModel);
  58522. if (!group) {
  58523. group = this._group = new Group();
  58524. this.createPointerEl(group, elOption, axisModel, axisPointerModel);
  58525. this.createLabelEl(group, elOption, axisModel, axisPointerModel);
  58526. api.getZr().add(group);
  58527. }
  58528. else {
  58529. var doUpdateProps = curry(updateProps$1, axisPointerModel, moveAnimation);
  58530. this.updatePointerEl(group, elOption, doUpdateProps, axisPointerModel);
  58531. this.updateLabelEl(group, elOption, doUpdateProps, axisPointerModel);
  58532. }
  58533. updateMandatoryProps(group, axisPointerModel, true);
  58534. this._renderHandle(value);
  58535. },
  58536. /**
  58537. * @implement
  58538. */
  58539. remove: function (api) {
  58540. this.clear(api);
  58541. },
  58542. /**
  58543. * @implement
  58544. */
  58545. dispose: function (api) {
  58546. this.clear(api);
  58547. },
  58548. /**
  58549. * @protected
  58550. */
  58551. determineAnimation: function (axisModel, axisPointerModel) {
  58552. var animation = axisPointerModel.get('animation');
  58553. var axis = axisModel.axis;
  58554. var isCategoryAxis = axis.type === 'category';
  58555. var useSnap = axisPointerModel.get('snap');
  58556. // Value axis without snap always do not snap.
  58557. if (!useSnap && !isCategoryAxis) {
  58558. return false;
  58559. }
  58560. if (animation === 'auto' || animation == null) {
  58561. var animationThreshold = this.animationThreshold;
  58562. if (isCategoryAxis && axis.getBandWidth() > animationThreshold) {
  58563. return true;
  58564. }
  58565. // It is important to auto animation when snap used. Consider if there is
  58566. // a dataZoom, animation will be disabled when too many points exist, while
  58567. // it will be enabled for better visual effect when little points exist.
  58568. if (useSnap) {
  58569. var seriesDataCount = getAxisInfo(axisModel).seriesDataCount;
  58570. var axisExtent = axis.getExtent();
  58571. // Approximate band width
  58572. return Math.abs(axisExtent[0] - axisExtent[1]) / seriesDataCount > animationThreshold;
  58573. }
  58574. return false;
  58575. }
  58576. return animation === true;
  58577. },
  58578. /**
  58579. * add {pointer, label, graphicKey} to elOption
  58580. * @protected
  58581. */
  58582. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  58583. // Shoule be implemenented by sub-class.
  58584. },
  58585. /**
  58586. * @protected
  58587. */
  58588. createPointerEl: function (group, elOption, axisModel, axisPointerModel) {
  58589. var pointerOption = elOption.pointer;
  58590. if (pointerOption) {
  58591. var pointerEl = inner$11(group).pointerEl = new graphic[pointerOption.type](
  58592. clone$4(elOption.pointer)
  58593. );
  58594. group.add(pointerEl);
  58595. }
  58596. },
  58597. /**
  58598. * @protected
  58599. */
  58600. createLabelEl: function (group, elOption, axisModel, axisPointerModel) {
  58601. if (elOption.label) {
  58602. var labelEl = inner$11(group).labelEl = new Rect(
  58603. clone$4(elOption.label)
  58604. );
  58605. group.add(labelEl);
  58606. updateLabelShowHide(labelEl, axisPointerModel);
  58607. }
  58608. },
  58609. /**
  58610. * @protected
  58611. */
  58612. updatePointerEl: function (group, elOption, updateProps$$1) {
  58613. var pointerEl = inner$11(group).pointerEl;
  58614. if (pointerEl) {
  58615. pointerEl.setStyle(elOption.pointer.style);
  58616. updateProps$$1(pointerEl, {shape: elOption.pointer.shape});
  58617. }
  58618. },
  58619. /**
  58620. * @protected
  58621. */
  58622. updateLabelEl: function (group, elOption, updateProps$$1, axisPointerModel) {
  58623. var labelEl = inner$11(group).labelEl;
  58624. if (labelEl) {
  58625. labelEl.setStyle(elOption.label.style);
  58626. updateProps$$1(labelEl, {
  58627. // Consider text length change in vertical axis, animation should
  58628. // be used on shape, otherwise the effect will be weird.
  58629. shape: elOption.label.shape,
  58630. position: elOption.label.position
  58631. });
  58632. updateLabelShowHide(labelEl, axisPointerModel);
  58633. }
  58634. },
  58635. /**
  58636. * @private
  58637. */
  58638. _renderHandle: function (value) {
  58639. if (this._dragging || !this.updateHandleTransform) {
  58640. return;
  58641. }
  58642. var axisPointerModel = this._axisPointerModel;
  58643. var zr = this._api.getZr();
  58644. var handle = this._handle;
  58645. var handleModel = axisPointerModel.getModel('handle');
  58646. var status = axisPointerModel.get('status');
  58647. if (!handleModel.get('show') || !status || status === 'hide') {
  58648. handle && zr.remove(handle);
  58649. this._handle = null;
  58650. return;
  58651. }
  58652. var isInit;
  58653. if (!this._handle) {
  58654. isInit = true;
  58655. handle = this._handle = createIcon(
  58656. handleModel.get('icon'),
  58657. {
  58658. cursor: 'move',
  58659. draggable: true,
  58660. onmousemove: function (e) {
  58661. // Fot mobile devicem, prevent screen slider on the button.
  58662. stop(e.event);
  58663. },
  58664. onmousedown: bind$2(this._onHandleDragMove, this, 0, 0),
  58665. drift: bind$2(this._onHandleDragMove, this),
  58666. ondragend: bind$2(this._onHandleDragEnd, this)
  58667. }
  58668. );
  58669. zr.add(handle);
  58670. }
  58671. updateMandatoryProps(handle, axisPointerModel, false);
  58672. // update style
  58673. var includeStyles = [
  58674. 'color', 'borderColor', 'borderWidth', 'opacity',
  58675. 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'
  58676. ];
  58677. handle.setStyle(handleModel.getItemStyle(null, includeStyles));
  58678. // update position
  58679. var handleSize = handleModel.get('size');
  58680. if (!isArray(handleSize)) {
  58681. handleSize = [handleSize, handleSize];
  58682. }
  58683. handle.attr('scale', [handleSize[0] / 2, handleSize[1] / 2]);
  58684. createOrUpdate(
  58685. this,
  58686. '_doDispatchAxisPointer',
  58687. handleModel.get('throttle') || 0,
  58688. 'fixRate'
  58689. );
  58690. this._moveHandleToValue(value, isInit);
  58691. },
  58692. /**
  58693. * @private
  58694. */
  58695. _moveHandleToValue: function (value, isInit) {
  58696. updateProps$1(
  58697. this._axisPointerModel,
  58698. !isInit && this._moveAnimation,
  58699. this._handle,
  58700. getHandleTransProps(this.getHandleTransform(
  58701. value, this._axisModel, this._axisPointerModel
  58702. ))
  58703. );
  58704. },
  58705. /**
  58706. * @private
  58707. */
  58708. _onHandleDragMove: function (dx, dy) {
  58709. var handle = this._handle;
  58710. if (!handle) {
  58711. return;
  58712. }
  58713. this._dragging = true;
  58714. // Persistent for throttle.
  58715. var trans = this.updateHandleTransform(
  58716. getHandleTransProps(handle),
  58717. [dx, dy],
  58718. this._axisModel,
  58719. this._axisPointerModel
  58720. );
  58721. this._payloadInfo = trans;
  58722. handle.stopAnimation();
  58723. handle.attr(getHandleTransProps(trans));
  58724. inner$11(handle).lastProp = null;
  58725. this._doDispatchAxisPointer();
  58726. },
  58727. /**
  58728. * Throttled method.
  58729. * @private
  58730. */
  58731. _doDispatchAxisPointer: function () {
  58732. var handle = this._handle;
  58733. if (!handle) {
  58734. return;
  58735. }
  58736. var payloadInfo = this._payloadInfo;
  58737. var axisModel = this._axisModel;
  58738. this._api.dispatchAction({
  58739. type: 'updateAxisPointer',
  58740. x: payloadInfo.cursorPoint[0],
  58741. y: payloadInfo.cursorPoint[1],
  58742. tooltipOption: payloadInfo.tooltipOption,
  58743. axesInfo: [{
  58744. axisDim: axisModel.axis.dim,
  58745. axisIndex: axisModel.componentIndex
  58746. }]
  58747. });
  58748. },
  58749. /**
  58750. * @private
  58751. */
  58752. _onHandleDragEnd: function (moveAnimation) {
  58753. this._dragging = false;
  58754. var handle = this._handle;
  58755. if (!handle) {
  58756. return;
  58757. }
  58758. var value = this._axisPointerModel.get('value');
  58759. // Consider snap or categroy axis, handle may be not consistent with
  58760. // axisPointer. So move handle to align the exact value position when
  58761. // drag ended.
  58762. this._moveHandleToValue(value);
  58763. // For the effect: tooltip will be shown when finger holding on handle
  58764. // button, and will be hidden after finger left handle button.
  58765. this._api.dispatchAction({
  58766. type: 'hideTip'
  58767. });
  58768. },
  58769. /**
  58770. * Should be implemenented by sub-class if support `handle`.
  58771. * @protected
  58772. * @param {number} value
  58773. * @param {module:echarts/model/Model} axisModel
  58774. * @param {module:echarts/model/Model} axisPointerModel
  58775. * @return {Object} {position: [x, y], rotation: 0}
  58776. */
  58777. getHandleTransform: null,
  58778. /**
  58779. * * Should be implemenented by sub-class if support `handle`.
  58780. * @protected
  58781. * @param {Object} transform {position, rotation}
  58782. * @param {Array.<number>} delta [dx, dy]
  58783. * @param {module:echarts/model/Model} axisModel
  58784. * @param {module:echarts/model/Model} axisPointerModel
  58785. * @return {Object} {position: [x, y], rotation: 0, cursorPoint: [x, y]}
  58786. */
  58787. updateHandleTransform: null,
  58788. /**
  58789. * @private
  58790. */
  58791. clear: function (api) {
  58792. this._lastValue = null;
  58793. this._lastStatus = null;
  58794. var zr = api.getZr();
  58795. var group = this._group;
  58796. var handle = this._handle;
  58797. if (zr && group) {
  58798. this._lastGraphicKey = null;
  58799. group && zr.remove(group);
  58800. handle && zr.remove(handle);
  58801. this._group = null;
  58802. this._handle = null;
  58803. this._payloadInfo = null;
  58804. }
  58805. },
  58806. /**
  58807. * @protected
  58808. */
  58809. doClear: function () {
  58810. // Implemented by sub-class if necessary.
  58811. },
  58812. /**
  58813. * @protected
  58814. * @param {Array.<number>} xy
  58815. * @param {Array.<number>} wh
  58816. * @param {number} [xDimIndex=0] or 1
  58817. */
  58818. buildLabel: function (xy, wh, xDimIndex) {
  58819. xDimIndex = xDimIndex || 0;
  58820. return {
  58821. x: xy[xDimIndex],
  58822. y: xy[1 - xDimIndex],
  58823. width: wh[xDimIndex],
  58824. height: wh[1 - xDimIndex]
  58825. };
  58826. }
  58827. };
  58828. BaseAxisPointer.prototype.constructor = BaseAxisPointer;
  58829. function updateProps$1(animationModel, moveAnimation, el, props) {
  58830. // Animation optimize.
  58831. if (!propsEqual(inner$11(el).lastProp, props)) {
  58832. inner$11(el).lastProp = props;
  58833. moveAnimation
  58834. ? updateProps(el, props, animationModel)
  58835. : (el.stopAnimation(), el.attr(props));
  58836. }
  58837. }
  58838. function propsEqual(lastProps, newProps) {
  58839. if (isObject$1(lastProps) && isObject$1(newProps)) {
  58840. var equals = true;
  58841. each$1(newProps, function (item, key) {
  58842. equals = equals && propsEqual(lastProps[key], item);
  58843. });
  58844. return !!equals;
  58845. }
  58846. else {
  58847. return lastProps === newProps;
  58848. }
  58849. }
  58850. function updateLabelShowHide(labelEl, axisPointerModel) {
  58851. labelEl[axisPointerModel.get('label.show') ? 'show' : 'hide']();
  58852. }
  58853. function getHandleTransProps(trans) {
  58854. return {
  58855. position: trans.position.slice(),
  58856. rotation: trans.rotation || 0
  58857. };
  58858. }
  58859. function updateMandatoryProps(group, axisPointerModel, silent) {
  58860. var z = axisPointerModel.get('z');
  58861. var zlevel = axisPointerModel.get('zlevel');
  58862. group && group.traverse(function (el) {
  58863. if (el.type !== 'group') {
  58864. z != null && (el.z = z);
  58865. zlevel != null && (el.zlevel = zlevel);
  58866. el.silent = silent;
  58867. }
  58868. });
  58869. }
  58870. enableClassExtend(BaseAxisPointer);
  58871. /*
  58872. * Licensed to the Apache Software Foundation (ASF) under one
  58873. * or more contributor license agreements. See the NOTICE file
  58874. * distributed with this work for additional information
  58875. * regarding copyright ownership. The ASF licenses this file
  58876. * to you under the Apache License, Version 2.0 (the
  58877. * "License"); you may not use this file except in compliance
  58878. * with the License. You may obtain a copy of the License at
  58879. *
  58880. * http://www.apache.org/licenses/LICENSE-2.0
  58881. *
  58882. * Unless required by applicable law or agreed to in writing,
  58883. * software distributed under the License is distributed on an
  58884. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58885. * KIND, either express or implied. See the License for the
  58886. * specific language governing permissions and limitations
  58887. * under the License.
  58888. */
  58889. /**
  58890. * @param {module:echarts/model/Model} axisPointerModel
  58891. */
  58892. function buildElStyle(axisPointerModel) {
  58893. var axisPointerType = axisPointerModel.get('type');
  58894. var styleModel = axisPointerModel.getModel(axisPointerType + 'Style');
  58895. var style;
  58896. if (axisPointerType === 'line') {
  58897. style = styleModel.getLineStyle();
  58898. style.fill = null;
  58899. }
  58900. else if (axisPointerType === 'shadow') {
  58901. style = styleModel.getAreaStyle();
  58902. style.stroke = null;
  58903. }
  58904. return style;
  58905. }
  58906. /**
  58907. * @param {Function} labelPos {align, verticalAlign, position}
  58908. */
  58909. function buildLabelElOption(
  58910. elOption, axisModel, axisPointerModel, api, labelPos
  58911. ) {
  58912. var value = axisPointerModel.get('value');
  58913. var text = getValueLabel(
  58914. value, axisModel.axis, axisModel.ecModel,
  58915. axisPointerModel.get('seriesDataIndices'),
  58916. {
  58917. precision: axisPointerModel.get('label.precision'),
  58918. formatter: axisPointerModel.get('label.formatter')
  58919. }
  58920. );
  58921. var labelModel = axisPointerModel.getModel('label');
  58922. var paddings = normalizeCssArray$1(labelModel.get('padding') || 0);
  58923. var font = labelModel.getFont();
  58924. var textRect = getBoundingRect(text, font);
  58925. var position = labelPos.position;
  58926. var width = textRect.width + paddings[1] + paddings[3];
  58927. var height = textRect.height + paddings[0] + paddings[2];
  58928. // Adjust by align.
  58929. var align = labelPos.align;
  58930. align === 'right' && (position[0] -= width);
  58931. align === 'center' && (position[0] -= width / 2);
  58932. var verticalAlign = labelPos.verticalAlign;
  58933. verticalAlign === 'bottom' && (position[1] -= height);
  58934. verticalAlign === 'middle' && (position[1] -= height / 2);
  58935. // Not overflow ec container
  58936. confineInContainer(position, width, height, api);
  58937. var bgColor = labelModel.get('backgroundColor');
  58938. if (!bgColor || bgColor === 'auto') {
  58939. bgColor = axisModel.get('axisLine.lineStyle.color');
  58940. }
  58941. elOption.label = {
  58942. shape: {x: 0, y: 0, width: width, height: height, r: labelModel.get('borderRadius')},
  58943. position: position.slice(),
  58944. // TODO: rich
  58945. style: {
  58946. text: text,
  58947. textFont: font,
  58948. textFill: labelModel.getTextColor(),
  58949. textPosition: 'inside',
  58950. fill: bgColor,
  58951. stroke: labelModel.get('borderColor') || 'transparent',
  58952. lineWidth: labelModel.get('borderWidth') || 0,
  58953. shadowBlur: labelModel.get('shadowBlur'),
  58954. shadowColor: labelModel.get('shadowColor'),
  58955. shadowOffsetX: labelModel.get('shadowOffsetX'),
  58956. shadowOffsetY: labelModel.get('shadowOffsetY')
  58957. },
  58958. // Lable should be over axisPointer.
  58959. z2: 10
  58960. };
  58961. }
  58962. // Do not overflow ec container
  58963. function confineInContainer(position, width, height, api) {
  58964. var viewWidth = api.getWidth();
  58965. var viewHeight = api.getHeight();
  58966. position[0] = Math.min(position[0] + width, viewWidth) - width;
  58967. position[1] = Math.min(position[1] + height, viewHeight) - height;
  58968. position[0] = Math.max(position[0], 0);
  58969. position[1] = Math.max(position[1], 0);
  58970. }
  58971. /**
  58972. * @param {number} value
  58973. * @param {module:echarts/coord/Axis} axis
  58974. * @param {module:echarts/model/Global} ecModel
  58975. * @param {Object} opt
  58976. * @param {Array.<Object>} seriesDataIndices
  58977. * @param {number|string} opt.precision 'auto' or a number
  58978. * @param {string|Function} opt.formatter label formatter
  58979. */
  58980. function getValueLabel(value, axis, ecModel, seriesDataIndices, opt) {
  58981. value = axis.scale.parse(value);
  58982. var text = axis.scale.getLabel(
  58983. // If `precision` is set, width can be fixed (like '12.00500'), which
  58984. // helps to debounce when when moving label.
  58985. value, {precision: opt.precision}
  58986. );
  58987. var formatter = opt.formatter;
  58988. if (formatter) {
  58989. var params = {
  58990. value: getAxisRawValue(axis, value),
  58991. seriesData: []
  58992. };
  58993. each$1(seriesDataIndices, function (idxItem) {
  58994. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  58995. var dataIndex = idxItem.dataIndexInside;
  58996. var dataParams = series && series.getDataParams(dataIndex);
  58997. dataParams && params.seriesData.push(dataParams);
  58998. });
  58999. if (isString(formatter)) {
  59000. text = formatter.replace('{value}', text);
  59001. }
  59002. else if (isFunction$1(formatter)) {
  59003. text = formatter(params);
  59004. }
  59005. }
  59006. return text;
  59007. }
  59008. /**
  59009. * @param {module:echarts/coord/Axis} axis
  59010. * @param {number} value
  59011. * @param {Object} layoutInfo {
  59012. * rotation, position, labelOffset, labelDirection, labelMargin
  59013. * }
  59014. */
  59015. function getTransformedPosition(axis, value, layoutInfo) {
  59016. var transform = create$1();
  59017. rotate(transform, transform, layoutInfo.rotation);
  59018. translate(transform, transform, layoutInfo.position);
  59019. return applyTransform$1([
  59020. axis.dataToCoord(value),
  59021. (layoutInfo.labelOffset || 0)
  59022. + (layoutInfo.labelDirection || 1) * (layoutInfo.labelMargin || 0)
  59023. ], transform);
  59024. }
  59025. function buildCartesianSingleLabelElOption(
  59026. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  59027. ) {
  59028. var textLayout = AxisBuilder.innerTextLayout(
  59029. layoutInfo.rotation, 0, layoutInfo.labelDirection
  59030. );
  59031. layoutInfo.labelMargin = axisPointerModel.get('label.margin');
  59032. buildLabelElOption(elOption, axisModel, axisPointerModel, api, {
  59033. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  59034. align: textLayout.textAlign,
  59035. verticalAlign: textLayout.textVerticalAlign
  59036. });
  59037. }
  59038. /**
  59039. * @param {Array.<number>} p1
  59040. * @param {Array.<number>} p2
  59041. * @param {number} [xDimIndex=0] or 1
  59042. */
  59043. function makeLineShape(p1, p2, xDimIndex) {
  59044. xDimIndex = xDimIndex || 0;
  59045. return {
  59046. x1: p1[xDimIndex],
  59047. y1: p1[1 - xDimIndex],
  59048. x2: p2[xDimIndex],
  59049. y2: p2[1 - xDimIndex]
  59050. };
  59051. }
  59052. /**
  59053. * @param {Array.<number>} xy
  59054. * @param {Array.<number>} wh
  59055. * @param {number} [xDimIndex=0] or 1
  59056. */
  59057. function makeRectShape(xy, wh, xDimIndex) {
  59058. xDimIndex = xDimIndex || 0;
  59059. return {
  59060. x: xy[xDimIndex],
  59061. y: xy[1 - xDimIndex],
  59062. width: wh[xDimIndex],
  59063. height: wh[1 - xDimIndex]
  59064. };
  59065. }
  59066. function makeSectorShape(cx, cy, r0, r, startAngle, endAngle) {
  59067. return {
  59068. cx: cx,
  59069. cy: cy,
  59070. r0: r0,
  59071. r: r,
  59072. startAngle: startAngle,
  59073. endAngle: endAngle,
  59074. clockwise: true
  59075. };
  59076. }
  59077. /*
  59078. * Licensed to the Apache Software Foundation (ASF) under one
  59079. * or more contributor license agreements. See the NOTICE file
  59080. * distributed with this work for additional information
  59081. * regarding copyright ownership. The ASF licenses this file
  59082. * to you under the Apache License, Version 2.0 (the
  59083. * "License"); you may not use this file except in compliance
  59084. * with the License. You may obtain a copy of the License at
  59085. *
  59086. * http://www.apache.org/licenses/LICENSE-2.0
  59087. *
  59088. * Unless required by applicable law or agreed to in writing,
  59089. * software distributed under the License is distributed on an
  59090. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59091. * KIND, either express or implied. See the License for the
  59092. * specific language governing permissions and limitations
  59093. * under the License.
  59094. */
  59095. var CartesianAxisPointer = BaseAxisPointer.extend({
  59096. /**
  59097. * @override
  59098. */
  59099. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  59100. var axis = axisModel.axis;
  59101. var grid = axis.grid;
  59102. var axisPointerType = axisPointerModel.get('type');
  59103. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  59104. var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
  59105. if (axisPointerType && axisPointerType !== 'none') {
  59106. var elStyle = buildElStyle(axisPointerModel);
  59107. var pointerOption = pointerShapeBuilder[axisPointerType](
  59108. axis, pixelValue, otherExtent, elStyle
  59109. );
  59110. pointerOption.style = elStyle;
  59111. elOption.graphicKey = pointerOption.type;
  59112. elOption.pointer = pointerOption;
  59113. }
  59114. var layoutInfo = layout$1(grid.model, axisModel);
  59115. buildCartesianSingleLabelElOption(
  59116. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  59117. );
  59118. },
  59119. /**
  59120. * @override
  59121. */
  59122. getHandleTransform: function (value, axisModel, axisPointerModel) {
  59123. var layoutInfo = layout$1(axisModel.axis.grid.model, axisModel, {
  59124. labelInside: false
  59125. });
  59126. layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
  59127. return {
  59128. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  59129. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  59130. };
  59131. },
  59132. /**
  59133. * @override
  59134. */
  59135. updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
  59136. var axis = axisModel.axis;
  59137. var grid = axis.grid;
  59138. var axisExtent = axis.getGlobalExtent(true);
  59139. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  59140. var dimIndex = axis.dim === 'x' ? 0 : 1;
  59141. var currPosition = transform.position;
  59142. currPosition[dimIndex] += delta[dimIndex];
  59143. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  59144. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  59145. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  59146. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  59147. cursorPoint[dimIndex] = currPosition[dimIndex];
  59148. // Make tooltip do not overlap axisPointer and in the middle of the grid.
  59149. var tooltipOptions = [{verticalAlign: 'middle'}, {align: 'center'}];
  59150. return {
  59151. position: currPosition,
  59152. rotation: transform.rotation,
  59153. cursorPoint: cursorPoint,
  59154. tooltipOption: tooltipOptions[dimIndex]
  59155. };
  59156. }
  59157. });
  59158. function getCartesian(grid, axis) {
  59159. var opt = {};
  59160. opt[axis.dim + 'AxisIndex'] = axis.index;
  59161. return grid.getCartesian(opt);
  59162. }
  59163. var pointerShapeBuilder = {
  59164. line: function (axis, pixelValue, otherExtent, elStyle) {
  59165. var targetShape = makeLineShape(
  59166. [pixelValue, otherExtent[0]],
  59167. [pixelValue, otherExtent[1]],
  59168. getAxisDimIndex(axis)
  59169. );
  59170. subPixelOptimizeLine({
  59171. shape: targetShape,
  59172. style: elStyle
  59173. });
  59174. return {
  59175. type: 'Line',
  59176. shape: targetShape
  59177. };
  59178. },
  59179. shadow: function (axis, pixelValue, otherExtent, elStyle) {
  59180. var bandWidth = Math.max(1, axis.getBandWidth());
  59181. var span = otherExtent[1] - otherExtent[0];
  59182. return {
  59183. type: 'Rect',
  59184. shape: makeRectShape(
  59185. [pixelValue - bandWidth / 2, otherExtent[0]],
  59186. [bandWidth, span],
  59187. getAxisDimIndex(axis)
  59188. )
  59189. };
  59190. }
  59191. };
  59192. function getAxisDimIndex(axis) {
  59193. return axis.dim === 'x' ? 0 : 1;
  59194. }
  59195. AxisView.registerAxisPointerClass('CartesianAxisPointer', CartesianAxisPointer);
  59196. /*
  59197. * Licensed to the Apache Software Foundation (ASF) under one
  59198. * or more contributor license agreements. See the NOTICE file
  59199. * distributed with this work for additional information
  59200. * regarding copyright ownership. The ASF licenses this file
  59201. * to you under the Apache License, Version 2.0 (the
  59202. * "License"); you may not use this file except in compliance
  59203. * with the License. You may obtain a copy of the License at
  59204. *
  59205. * http://www.apache.org/licenses/LICENSE-2.0
  59206. *
  59207. * Unless required by applicable law or agreed to in writing,
  59208. * software distributed under the License is distributed on an
  59209. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59210. * KIND, either express or implied. See the License for the
  59211. * specific language governing permissions and limitations
  59212. * under the License.
  59213. */
  59214. // CartesianAxisPointer is not supposed to be required here. But consider
  59215. // echarts.simple.js and online build tooltip, which only require gridSimple,
  59216. // CartesianAxisPointer should be able to required somewhere.
  59217. registerPreprocessor(function (option) {
  59218. // Always has a global axisPointerModel for default setting.
  59219. if (option) {
  59220. (!option.axisPointer || option.axisPointer.length === 0)
  59221. && (option.axisPointer = {});
  59222. var link = option.axisPointer.link;
  59223. // Normalize to array to avoid object mergin. But if link
  59224. // is not set, remain null/undefined, otherwise it will
  59225. // override existent link setting.
  59226. if (link && !isArray(link)) {
  59227. option.axisPointer.link = [link];
  59228. }
  59229. }
  59230. });
  59231. // This process should proformed after coordinate systems created
  59232. // and series data processed. So put it on statistic processing stage.
  59233. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, function (ecModel, api) {
  59234. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  59235. // allAxesInfo should be updated when setOption performed.
  59236. ecModel.getComponent('axisPointer').coordSysAxesInfo
  59237. = collect(ecModel, api);
  59238. });
  59239. // Broadcast to all views.
  59240. registerAction({
  59241. type: 'updateAxisPointer',
  59242. event: 'updateAxisPointer',
  59243. update: ':updateAxisPointer'
  59244. }, axisTrigger);
  59245. /*
  59246. * Licensed to the Apache Software Foundation (ASF) under one
  59247. * or more contributor license agreements. See the NOTICE file
  59248. * distributed with this work for additional information
  59249. * regarding copyright ownership. The ASF licenses this file
  59250. * to you under the Apache License, Version 2.0 (the
  59251. * "License"); you may not use this file except in compliance
  59252. * with the License. You may obtain a copy of the License at
  59253. *
  59254. * http://www.apache.org/licenses/LICENSE-2.0
  59255. *
  59256. * Unless required by applicable law or agreed to in writing,
  59257. * software distributed under the License is distributed on an
  59258. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59259. * KIND, either express or implied. See the License for the
  59260. * specific language governing permissions and limitations
  59261. * under the License.
  59262. */
  59263. var XY = ['x', 'y'];
  59264. var WH = ['width', 'height'];
  59265. var SingleAxisPointer = BaseAxisPointer.extend({
  59266. /**
  59267. * @override
  59268. */
  59269. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  59270. var axis = axisModel.axis;
  59271. var coordSys = axis.coordinateSystem;
  59272. var otherExtent = getGlobalExtent(coordSys, 1 - getPointDimIndex(axis));
  59273. var pixelValue = coordSys.dataToPoint(value)[0];
  59274. var axisPointerType = axisPointerModel.get('type');
  59275. if (axisPointerType && axisPointerType !== 'none') {
  59276. var elStyle = buildElStyle(axisPointerModel);
  59277. var pointerOption = pointerShapeBuilder$1[axisPointerType](
  59278. axis, pixelValue, otherExtent, elStyle
  59279. );
  59280. pointerOption.style = elStyle;
  59281. elOption.graphicKey = pointerOption.type;
  59282. elOption.pointer = pointerOption;
  59283. }
  59284. var layoutInfo = layout$2(axisModel);
  59285. buildCartesianSingleLabelElOption(
  59286. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  59287. );
  59288. },
  59289. /**
  59290. * @override
  59291. */
  59292. getHandleTransform: function (value, axisModel, axisPointerModel) {
  59293. var layoutInfo = layout$2(axisModel, {labelInside: false});
  59294. layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
  59295. return {
  59296. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  59297. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  59298. };
  59299. },
  59300. /**
  59301. * @override
  59302. */
  59303. updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
  59304. var axis = axisModel.axis;
  59305. var coordSys = axis.coordinateSystem;
  59306. var dimIndex = getPointDimIndex(axis);
  59307. var axisExtent = getGlobalExtent(coordSys, dimIndex);
  59308. var currPosition = transform.position;
  59309. currPosition[dimIndex] += delta[dimIndex];
  59310. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  59311. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  59312. var otherExtent = getGlobalExtent(coordSys, 1 - dimIndex);
  59313. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  59314. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  59315. cursorPoint[dimIndex] = currPosition[dimIndex];
  59316. return {
  59317. position: currPosition,
  59318. rotation: transform.rotation,
  59319. cursorPoint: cursorPoint,
  59320. tooltipOption: {
  59321. verticalAlign: 'middle'
  59322. }
  59323. };
  59324. }
  59325. });
  59326. var pointerShapeBuilder$1 = {
  59327. line: function (axis, pixelValue, otherExtent, elStyle) {
  59328. var targetShape = makeLineShape(
  59329. [pixelValue, otherExtent[0]],
  59330. [pixelValue, otherExtent[1]],
  59331. getPointDimIndex(axis)
  59332. );
  59333. subPixelOptimizeLine({
  59334. shape: targetShape,
  59335. style: elStyle
  59336. });
  59337. return {
  59338. type: 'Line',
  59339. shape: targetShape
  59340. };
  59341. },
  59342. shadow: function (axis, pixelValue, otherExtent, elStyle) {
  59343. var bandWidth = axis.getBandWidth();
  59344. var span = otherExtent[1] - otherExtent[0];
  59345. return {
  59346. type: 'Rect',
  59347. shape: makeRectShape(
  59348. [pixelValue - bandWidth / 2, otherExtent[0]],
  59349. [bandWidth, span],
  59350. getPointDimIndex(axis)
  59351. )
  59352. };
  59353. }
  59354. };
  59355. function getPointDimIndex(axis) {
  59356. return axis.isHorizontal() ? 0 : 1;
  59357. }
  59358. function getGlobalExtent(coordSys, dimIndex) {
  59359. var rect = coordSys.getRect();
  59360. return [rect[XY[dimIndex]], rect[XY[dimIndex]] + rect[WH[dimIndex]]];
  59361. }
  59362. AxisView.registerAxisPointerClass('SingleAxisPointer', SingleAxisPointer);
  59363. /*
  59364. * Licensed to the Apache Software Foundation (ASF) under one
  59365. * or more contributor license agreements. See the NOTICE file
  59366. * distributed with this work for additional information
  59367. * regarding copyright ownership. The ASF licenses this file
  59368. * to you under the Apache License, Version 2.0 (the
  59369. * "License"); you may not use this file except in compliance
  59370. * with the License. You may obtain a copy of the License at
  59371. *
  59372. * http://www.apache.org/licenses/LICENSE-2.0
  59373. *
  59374. * Unless required by applicable law or agreed to in writing,
  59375. * software distributed under the License is distributed on an
  59376. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59377. * KIND, either express or implied. See the License for the
  59378. * specific language governing permissions and limitations
  59379. * under the License.
  59380. */
  59381. extendComponentView({
  59382. type: 'single'
  59383. });
  59384. /*
  59385. * Licensed to the Apache Software Foundation (ASF) under one
  59386. * or more contributor license agreements. See the NOTICE file
  59387. * distributed with this work for additional information
  59388. * regarding copyright ownership. The ASF licenses this file
  59389. * to you under the Apache License, Version 2.0 (the
  59390. * "License"); you may not use this file except in compliance
  59391. * with the License. You may obtain a copy of the License at
  59392. *
  59393. * http://www.apache.org/licenses/LICENSE-2.0
  59394. *
  59395. * Unless required by applicable law or agreed to in writing,
  59396. * software distributed under the License is distributed on an
  59397. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59398. * KIND, either express or implied. See the License for the
  59399. * specific language governing permissions and limitations
  59400. * under the License.
  59401. */
  59402. /**
  59403. * @file Define the themeRiver view's series model
  59404. * @author Deqing Li(annong035@gmail.com)
  59405. */
  59406. var DATA_NAME_INDEX = 2;
  59407. var ThemeRiverSeries = SeriesModel.extend({
  59408. type: 'series.themeRiver',
  59409. dependencies: ['singleAxis'],
  59410. /**
  59411. * @readOnly
  59412. * @type {module:zrender/core/util#HashMap}
  59413. */
  59414. nameMap: null,
  59415. /**
  59416. * @override
  59417. */
  59418. init: function (option) {
  59419. // eslint-disable-next-line
  59420. ThemeRiverSeries.superApply(this, 'init', arguments);
  59421. // Put this function here is for the sake of consistency of code style.
  59422. // Enable legend selection for each data item
  59423. // Use a function instead of direct access because data reference may changed
  59424. this.legendDataProvider = function () {
  59425. return this.getRawData();
  59426. };
  59427. },
  59428. /**
  59429. * If there is no value of a certain point in the time for some event,set it value to 0.
  59430. *
  59431. * @param {Array} data initial data in the option
  59432. * @return {Array}
  59433. */
  59434. fixData: function (data) {
  59435. var rawDataLength = data.length;
  59436. // grouped data by name
  59437. var groupResult = groupData(data, function (item) {
  59438. return item[2];
  59439. });
  59440. var layData = [];
  59441. groupResult.buckets.each(function (items, key) {
  59442. layData.push({name: key, dataList: items});
  59443. });
  59444. var layerNum = layData.length;
  59445. var largestLayer = -1;
  59446. var index = -1;
  59447. for (var i = 0; i < layerNum; ++i) {
  59448. var len = layData[i].dataList.length;
  59449. if (len > largestLayer) {
  59450. largestLayer = len;
  59451. index = i;
  59452. }
  59453. }
  59454. for (var k = 0; k < layerNum; ++k) {
  59455. if (k === index) {
  59456. continue;
  59457. }
  59458. var name = layData[k].name;
  59459. for (var j = 0; j < largestLayer; ++j) {
  59460. var timeValue = layData[index].dataList[j][0];
  59461. var length = layData[k].dataList.length;
  59462. var keyIndex = -1;
  59463. for (var l = 0; l < length; ++l) {
  59464. var value = layData[k].dataList[l][0];
  59465. if (value === timeValue) {
  59466. keyIndex = l;
  59467. break;
  59468. }
  59469. }
  59470. if (keyIndex === -1) {
  59471. data[rawDataLength] = [];
  59472. data[rawDataLength][0] = timeValue;
  59473. data[rawDataLength][1] = 0;
  59474. data[rawDataLength][2] = name;
  59475. rawDataLength++;
  59476. }
  59477. }
  59478. }
  59479. return data;
  59480. },
  59481. /**
  59482. * @override
  59483. * @param {Object} option the initial option that user gived
  59484. * @param {module:echarts/model/Model} ecModel the model object for themeRiver option
  59485. * @return {module:echarts/data/List}
  59486. */
  59487. getInitialData: function (option, ecModel) {
  59488. var singleAxisModel = ecModel.queryComponents({
  59489. mainType: 'singleAxis',
  59490. index: this.get('singleAxisIndex'),
  59491. id: this.get('singleAxisId')
  59492. })[0];
  59493. var axisType = singleAxisModel.get('type');
  59494. // filter the data item with the value of label is undefined
  59495. var filterData = filter(option.data, function (dataItem) {
  59496. return dataItem[2] !== undefined;
  59497. });
  59498. // ??? TODO design a stage to transfer data for themeRiver and lines?
  59499. var data = this.fixData(filterData || []);
  59500. var nameList = [];
  59501. var nameMap = this.nameMap = createHashMap();
  59502. var count = 0;
  59503. for (var i = 0; i < data.length; ++i) {
  59504. nameList.push(data[i][DATA_NAME_INDEX]);
  59505. if (!nameMap.get(data[i][DATA_NAME_INDEX])) {
  59506. nameMap.set(data[i][DATA_NAME_INDEX], count);
  59507. count++;
  59508. }
  59509. }
  59510. var dimensionsInfo = createDimensions(data, {
  59511. coordDimensions: ['single'],
  59512. dimensionsDefine: [
  59513. {
  59514. name: 'time',
  59515. type: getDimensionTypeByAxis(axisType)
  59516. },
  59517. {
  59518. name: 'value',
  59519. type: 'float'
  59520. },
  59521. {
  59522. name: 'name',
  59523. type: 'ordinal'
  59524. }
  59525. ],
  59526. encodeDefine: {
  59527. single: 0,
  59528. value: 1,
  59529. itemName: 2
  59530. }
  59531. });
  59532. var list = new List(dimensionsInfo, this);
  59533. list.initData(data);
  59534. return list;
  59535. },
  59536. /**
  59537. * The raw data is divided into multiple layers and each layer
  59538. * has same name.
  59539. *
  59540. * @return {Array.<Array.<number>>}
  59541. */
  59542. getLayerSeries: function () {
  59543. var data = this.getData();
  59544. var lenCount = data.count();
  59545. var indexArr = [];
  59546. for (var i = 0; i < lenCount; ++i) {
  59547. indexArr[i] = i;
  59548. }
  59549. var timeDim = data.mapDimension('single');
  59550. // data group by name
  59551. var groupResult = groupData(indexArr, function (index) {
  59552. return data.get('name', index);
  59553. });
  59554. var layerSeries = [];
  59555. groupResult.buckets.each(function (items, key) {
  59556. items.sort(function (index1, index2) {
  59557. return data.get(timeDim, index1) - data.get(timeDim, index2);
  59558. });
  59559. layerSeries.push({name: key, indices: items});
  59560. });
  59561. return layerSeries;
  59562. },
  59563. /**
  59564. * Get data indices for show tooltip content
  59565. *
  59566. * @param {Array.<string>|string} dim single coordinate dimension
  59567. * @param {number} value axis value
  59568. * @param {module:echarts/coord/single/SingleAxis} baseAxis single Axis used
  59569. * the themeRiver.
  59570. * @return {Object} {dataIndices, nestestValue}
  59571. */
  59572. getAxisTooltipData: function (dim, value, baseAxis) {
  59573. if (!isArray(dim)) {
  59574. dim = dim ? [dim] : [];
  59575. }
  59576. var data = this.getData();
  59577. var layerSeries = this.getLayerSeries();
  59578. var indices = [];
  59579. var layerNum = layerSeries.length;
  59580. var nestestValue;
  59581. for (var i = 0; i < layerNum; ++i) {
  59582. var minDist = Number.MAX_VALUE;
  59583. var nearestIdx = -1;
  59584. var pointNum = layerSeries[i].indices.length;
  59585. for (var j = 0; j < pointNum; ++j) {
  59586. var theValue = data.get(dim[0], layerSeries[i].indices[j]);
  59587. var dist = Math.abs(theValue - value);
  59588. if (dist <= minDist) {
  59589. nestestValue = theValue;
  59590. minDist = dist;
  59591. nearestIdx = layerSeries[i].indices[j];
  59592. }
  59593. }
  59594. indices.push(nearestIdx);
  59595. }
  59596. return {dataIndices: indices, nestestValue: nestestValue};
  59597. },
  59598. /**
  59599. * @override
  59600. * @param {number} dataIndex index of data
  59601. */
  59602. formatTooltip: function (dataIndex) {
  59603. var data = this.getData();
  59604. var htmlName = data.getName(dataIndex);
  59605. var htmlValue = data.get(data.mapDimension('value'), dataIndex);
  59606. if (isNaN(htmlValue) || htmlValue == null) {
  59607. htmlValue = '-';
  59608. }
  59609. return encodeHTML(htmlName + ' : ' + htmlValue);
  59610. },
  59611. defaultOption: {
  59612. zlevel: 0,
  59613. z: 2,
  59614. coordinateSystem: 'singleAxis',
  59615. // gap in axis's orthogonal orientation
  59616. boundaryGap: ['10%', '10%'],
  59617. // legendHoverLink: true,
  59618. singleAxisIndex: 0,
  59619. animationEasing: 'linear',
  59620. label: {
  59621. margin: 4,
  59622. show: true,
  59623. position: 'left',
  59624. color: '#000',
  59625. fontSize: 11
  59626. },
  59627. emphasis: {
  59628. label: {
  59629. show: true
  59630. }
  59631. }
  59632. }
  59633. });
  59634. /*
  59635. * Licensed to the Apache Software Foundation (ASF) under one
  59636. * or more contributor license agreements. See the NOTICE file
  59637. * distributed with this work for additional information
  59638. * regarding copyright ownership. The ASF licenses this file
  59639. * to you under the Apache License, Version 2.0 (the
  59640. * "License"); you may not use this file except in compliance
  59641. * with the License. You may obtain a copy of the License at
  59642. *
  59643. * http://www.apache.org/licenses/LICENSE-2.0
  59644. *
  59645. * Unless required by applicable law or agreed to in writing,
  59646. * software distributed under the License is distributed on an
  59647. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59648. * KIND, either express or implied. See the License for the
  59649. * specific language governing permissions and limitations
  59650. * under the License.
  59651. */
  59652. /**
  59653. * @file The file used to draw themeRiver view
  59654. * @author Deqing Li(annong035@gmail.com)
  59655. */
  59656. extendChartView({
  59657. type: 'themeRiver',
  59658. init: function () {
  59659. this._layers = [];
  59660. },
  59661. render: function (seriesModel, ecModel, api) {
  59662. var data = seriesModel.getData();
  59663. var group = this.group;
  59664. var layerSeries = seriesModel.getLayerSeries();
  59665. var layoutInfo = data.getLayout('layoutInfo');
  59666. var rect = layoutInfo.rect;
  59667. var boundaryGap = layoutInfo.boundaryGap;
  59668. group.attr('position', [0, rect.y + boundaryGap[0]]);
  59669. function keyGetter(item) {
  59670. return item.name;
  59671. }
  59672. var dataDiffer = new DataDiffer(
  59673. this._layersSeries || [], layerSeries,
  59674. keyGetter, keyGetter
  59675. );
  59676. var newLayersGroups = {};
  59677. dataDiffer
  59678. .add(bind(process, this, 'add'))
  59679. .update(bind(process, this, 'update'))
  59680. .remove(bind(process, this, 'remove'))
  59681. .execute();
  59682. function process(status, idx, oldIdx) {
  59683. var oldLayersGroups = this._layers;
  59684. if (status === 'remove') {
  59685. group.remove(oldLayersGroups[idx]);
  59686. return;
  59687. }
  59688. var points0 = [];
  59689. var points1 = [];
  59690. var color;
  59691. var indices = layerSeries[idx].indices;
  59692. for (var j = 0; j < indices.length; j++) {
  59693. var layout = data.getItemLayout(indices[j]);
  59694. var x = layout.x;
  59695. var y0 = layout.y0;
  59696. var y = layout.y;
  59697. points0.push([x, y0]);
  59698. points1.push([x, y0 + y]);
  59699. color = data.getItemVisual(indices[j], 'color');
  59700. }
  59701. var polygon;
  59702. var text;
  59703. var textLayout = data.getItemLayout(indices[0]);
  59704. var itemModel = data.getItemModel(indices[j - 1]);
  59705. var labelModel = itemModel.getModel('label');
  59706. var margin = labelModel.get('margin');
  59707. if (status === 'add') {
  59708. var layerGroup = newLayersGroups[idx] = new Group();
  59709. polygon = new Polygon$1({
  59710. shape: {
  59711. points: points0,
  59712. stackedOnPoints: points1,
  59713. smooth: 0.4,
  59714. stackedOnSmooth: 0.4,
  59715. smoothConstraint: false
  59716. },
  59717. z2: 0
  59718. });
  59719. text = new Text({
  59720. style: {
  59721. x: textLayout.x - margin,
  59722. y: textLayout.y0 + textLayout.y / 2
  59723. }
  59724. });
  59725. layerGroup.add(polygon);
  59726. layerGroup.add(text);
  59727. group.add(layerGroup);
  59728. polygon.setClipPath(createGridClipShape$3(polygon.getBoundingRect(), seriesModel, function () {
  59729. polygon.removeClipPath();
  59730. }));
  59731. }
  59732. else {
  59733. var layerGroup = oldLayersGroups[oldIdx];
  59734. polygon = layerGroup.childAt(0);
  59735. text = layerGroup.childAt(1);
  59736. group.add(layerGroup);
  59737. newLayersGroups[idx] = layerGroup;
  59738. updateProps(polygon, {
  59739. shape: {
  59740. points: points0,
  59741. stackedOnPoints: points1
  59742. }
  59743. }, seriesModel);
  59744. updateProps(text, {
  59745. style: {
  59746. x: textLayout.x - margin,
  59747. y: textLayout.y0 + textLayout.y / 2
  59748. }
  59749. }, seriesModel);
  59750. }
  59751. var hoverItemStyleModel = itemModel.getModel('emphasis.itemStyle');
  59752. var itemStyleModel = itemModel.getModel('itemStyle');
  59753. setTextStyle(text.style, labelModel, {
  59754. text: labelModel.get('show')
  59755. ? seriesModel.getFormattedLabel(indices[j - 1], 'normal')
  59756. || data.getName(indices[j - 1])
  59757. : null,
  59758. textVerticalAlign: 'middle'
  59759. });
  59760. polygon.setStyle(extend({
  59761. fill: color
  59762. }, itemStyleModel.getItemStyle(['color'])));
  59763. setHoverStyle(polygon, hoverItemStyleModel.getItemStyle());
  59764. }
  59765. this._layersSeries = layerSeries;
  59766. this._layers = newLayersGroups;
  59767. },
  59768. dispose: function () {}
  59769. });
  59770. // add animation to the view
  59771. function createGridClipShape$3(rect, seriesModel, cb) {
  59772. var rectEl = new Rect({
  59773. shape: {
  59774. x: rect.x - 10,
  59775. y: rect.y - 10,
  59776. width: 0,
  59777. height: rect.height + 20
  59778. }
  59779. });
  59780. initProps(rectEl, {
  59781. shape: {
  59782. width: rect.width + 20,
  59783. height: rect.height + 20
  59784. }
  59785. }, seriesModel, cb);
  59786. return rectEl;
  59787. }
  59788. /*
  59789. * Licensed to the Apache Software Foundation (ASF) under one
  59790. * or more contributor license agreements. See the NOTICE file
  59791. * distributed with this work for additional information
  59792. * regarding copyright ownership. The ASF licenses this file
  59793. * to you under the Apache License, Version 2.0 (the
  59794. * "License"); you may not use this file except in compliance
  59795. * with the License. You may obtain a copy of the License at
  59796. *
  59797. * http://www.apache.org/licenses/LICENSE-2.0
  59798. *
  59799. * Unless required by applicable law or agreed to in writing,
  59800. * software distributed under the License is distributed on an
  59801. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59802. * KIND, either express or implied. See the License for the
  59803. * specific language governing permissions and limitations
  59804. * under the License.
  59805. */
  59806. /**
  59807. * @file Using layout algorithm transform the raw data to layout information.
  59808. * @author Deqing Li(annong035@gmail.com)
  59809. */
  59810. var themeRiverLayout = function (ecModel, api) {
  59811. ecModel.eachSeriesByType('themeRiver', function (seriesModel) {
  59812. var data = seriesModel.getData();
  59813. var single = seriesModel.coordinateSystem;
  59814. var layoutInfo = {};
  59815. // use the axis boundingRect for view
  59816. var rect = single.getRect();
  59817. layoutInfo.rect = rect;
  59818. var boundaryGap = seriesModel.get('boundaryGap');
  59819. var axis = single.getAxis();
  59820. layoutInfo.boundaryGap = boundaryGap;
  59821. if (axis.orient === 'horizontal') {
  59822. boundaryGap[0] = parsePercent$1(boundaryGap[0], rect.height);
  59823. boundaryGap[1] = parsePercent$1(boundaryGap[1], rect.height);
  59824. var height = rect.height - boundaryGap[0] - boundaryGap[1];
  59825. themeRiverLayout$1(data, seriesModel, height);
  59826. }
  59827. else {
  59828. boundaryGap[0] = parsePercent$1(boundaryGap[0], rect.width);
  59829. boundaryGap[1] = parsePercent$1(boundaryGap[1], rect.width);
  59830. var width = rect.width - boundaryGap[0] - boundaryGap[1];
  59831. themeRiverLayout$1(data, seriesModel, width);
  59832. }
  59833. data.setLayout('layoutInfo', layoutInfo);
  59834. });
  59835. };
  59836. /**
  59837. * The layout information about themeriver
  59838. *
  59839. * @param {module:echarts/data/List} data data in the series
  59840. * @param {module:echarts/model/Series} seriesModel the model object of themeRiver series
  59841. * @param {number} height value used to compute every series height
  59842. */
  59843. function themeRiverLayout$1(data, seriesModel, height) {
  59844. if (!data.count()) {
  59845. return;
  59846. }
  59847. var coordSys = seriesModel.coordinateSystem;
  59848. // the data in each layer are organized into a series.
  59849. var layerSeries = seriesModel.getLayerSeries();
  59850. // the points in each layer.
  59851. var timeDim = data.mapDimension('single');
  59852. var valueDim = data.mapDimension('value');
  59853. var layerPoints = map(layerSeries, function (singleLayer) {
  59854. return map(singleLayer.indices, function (idx) {
  59855. var pt = coordSys.dataToPoint(data.get(timeDim, idx));
  59856. pt[1] = data.get(valueDim, idx);
  59857. return pt;
  59858. });
  59859. });
  59860. var base = computeBaseline(layerPoints);
  59861. var baseLine = base.y0;
  59862. var ky = height / base.max;
  59863. // set layout information for each item.
  59864. var n = layerSeries.length;
  59865. var m = layerSeries[0].indices.length;
  59866. var baseY0;
  59867. for (var j = 0; j < m; ++j) {
  59868. baseY0 = baseLine[j] * ky;
  59869. data.setItemLayout(layerSeries[0].indices[j], {
  59870. layerIndex: 0,
  59871. x: layerPoints[0][j][0],
  59872. y0: baseY0,
  59873. y: layerPoints[0][j][1] * ky
  59874. });
  59875. for (var i = 1; i < n; ++i) {
  59876. baseY0 += layerPoints[i - 1][j][1] * ky;
  59877. data.setItemLayout(layerSeries[i].indices[j], {
  59878. layerIndex: i,
  59879. x: layerPoints[i][j][0],
  59880. y0: baseY0,
  59881. y: layerPoints[i][j][1] * ky
  59882. });
  59883. }
  59884. }
  59885. }
  59886. /**
  59887. * Compute the baseLine of the rawdata
  59888. * Inspired by Lee Byron's paper Stacked Graphs - Geometry & Aesthetics
  59889. *
  59890. * @param {Array.<Array>} data the points in each layer
  59891. * @return {Object}
  59892. */
  59893. function computeBaseline(data) {
  59894. var layerNum = data.length;
  59895. var pointNum = data[0].length;
  59896. var sums = [];
  59897. var y0 = [];
  59898. var max = 0;
  59899. var temp;
  59900. var base = {};
  59901. for (var i = 0; i < pointNum; ++i) {
  59902. for (var j = 0, temp = 0; j < layerNum; ++j) {
  59903. temp += data[j][i][1];
  59904. }
  59905. if (temp > max) {
  59906. max = temp;
  59907. }
  59908. sums.push(temp);
  59909. }
  59910. for (var k = 0; k < pointNum; ++k) {
  59911. y0[k] = (max - sums[k]) / 2;
  59912. }
  59913. max = 0;
  59914. for (var l = 0; l < pointNum; ++l) {
  59915. var sum = sums[l] + y0[l];
  59916. if (sum > max) {
  59917. max = sum;
  59918. }
  59919. }
  59920. base.y0 = y0;
  59921. base.max = max;
  59922. return base;
  59923. }
  59924. /*
  59925. * Licensed to the Apache Software Foundation (ASF) under one
  59926. * or more contributor license agreements. See the NOTICE file
  59927. * distributed with this work for additional information
  59928. * regarding copyright ownership. The ASF licenses this file
  59929. * to you under the Apache License, Version 2.0 (the
  59930. * "License"); you may not use this file except in compliance
  59931. * with the License. You may obtain a copy of the License at
  59932. *
  59933. * http://www.apache.org/licenses/LICENSE-2.0
  59934. *
  59935. * Unless required by applicable law or agreed to in writing,
  59936. * software distributed under the License is distributed on an
  59937. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59938. * KIND, either express or implied. See the License for the
  59939. * specific language governing permissions and limitations
  59940. * under the License.
  59941. */
  59942. /**
  59943. * @file Visual encoding for themeRiver view
  59944. * @author Deqing Li(annong035@gmail.com)
  59945. */
  59946. var themeRiverVisual = function (ecModel) {
  59947. ecModel.eachSeriesByType('themeRiver', function (seriesModel) {
  59948. var data = seriesModel.getData();
  59949. var rawData = seriesModel.getRawData();
  59950. var colorList = seriesModel.get('color');
  59951. var idxMap = createHashMap();
  59952. data.each(function (idx) {
  59953. idxMap.set(data.getRawIndex(idx), idx);
  59954. });
  59955. rawData.each(function (rawIndex) {
  59956. var name = rawData.getName(rawIndex);
  59957. var color = colorList[(seriesModel.nameMap.get(name) - 1) % colorList.length];
  59958. rawData.setItemVisual(rawIndex, 'color', color);
  59959. var idx = idxMap.get(rawIndex);
  59960. if (idx != null) {
  59961. data.setItemVisual(idx, 'color', color);
  59962. }
  59963. });
  59964. });
  59965. };
  59966. /*
  59967. * Licensed to the Apache Software Foundation (ASF) under one
  59968. * or more contributor license agreements. See the NOTICE file
  59969. * distributed with this work for additional information
  59970. * regarding copyright ownership. The ASF licenses this file
  59971. * to you under the Apache License, Version 2.0 (the
  59972. * "License"); you may not use this file except in compliance
  59973. * with the License. You may obtain a copy of the License at
  59974. *
  59975. * http://www.apache.org/licenses/LICENSE-2.0
  59976. *
  59977. * Unless required by applicable law or agreed to in writing,
  59978. * software distributed under the License is distributed on an
  59979. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59980. * KIND, either express or implied. See the License for the
  59981. * specific language governing permissions and limitations
  59982. * under the License.
  59983. */
  59984. registerLayout(themeRiverLayout);
  59985. registerVisual(themeRiverVisual);
  59986. registerProcessor(dataFilter('themeRiver'));
  59987. /*
  59988. * Licensed to the Apache Software Foundation (ASF) under one
  59989. * or more contributor license agreements. See the NOTICE file
  59990. * distributed with this work for additional information
  59991. * regarding copyright ownership. The ASF licenses this file
  59992. * to you under the Apache License, Version 2.0 (the
  59993. * "License"); you may not use this file except in compliance
  59994. * with the License. You may obtain a copy of the License at
  59995. *
  59996. * http://www.apache.org/licenses/LICENSE-2.0
  59997. *
  59998. * Unless required by applicable law or agreed to in writing,
  59999. * software distributed under the License is distributed on an
  60000. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60001. * KIND, either express or implied. See the License for the
  60002. * specific language governing permissions and limitations
  60003. * under the License.
  60004. */
  60005. SeriesModel.extend({
  60006. type: 'series.sunburst',
  60007. /**
  60008. * @type {module:echarts/data/Tree~Node}
  60009. */
  60010. _viewRoot: null,
  60011. getInitialData: function (option, ecModel) {
  60012. // Create a virtual root.
  60013. var root = { name: option.name, children: option.data };
  60014. completeTreeValue$1(root);
  60015. var levels = option.levels || [];
  60016. // levels = option.levels = setDefault(levels, ecModel);
  60017. var treeOption = {};
  60018. treeOption.levels = levels;
  60019. // Make sure always a new tree is created when setOption,
  60020. // in TreemapView, we check whether oldTree === newTree
  60021. // to choose mappings approach among old shapes and new shapes.
  60022. return Tree.createTree(root, this, treeOption).data;
  60023. },
  60024. optionUpdated: function () {
  60025. this.resetViewRoot();
  60026. },
  60027. /*
  60028. * @override
  60029. */
  60030. getDataParams: function (dataIndex) {
  60031. var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
  60032. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  60033. params.treePathInfo = wrapTreePathInfo(node, this);
  60034. return params;
  60035. },
  60036. defaultOption: {
  60037. zlevel: 0,
  60038. z: 2,
  60039. // 默认全局居中
  60040. center: ['50%', '50%'],
  60041. radius: [0, '75%'],
  60042. // 默认顺时针
  60043. clockwise: true,
  60044. startAngle: 90,
  60045. // 最小角度改为0
  60046. minAngle: 0,
  60047. percentPrecision: 2,
  60048. // If still show when all data zero.
  60049. stillShowZeroSum: true,
  60050. // Policy of highlighting pieces when hover on one
  60051. // Valid values: 'none' (for not downplay others), 'descendant',
  60052. // 'ancestor', 'self'
  60053. highlightPolicy: 'descendant',
  60054. // 'rootToNode', 'link', or false
  60055. nodeClick: 'rootToNode',
  60056. renderLabelForZeroData: false,
  60057. label: {
  60058. // could be: 'radial', 'tangential', or 'none'
  60059. rotate: 'radial',
  60060. show: true,
  60061. opacity: 1,
  60062. // 'left' is for inner side of inside, and 'right' is for outter
  60063. // side for inside
  60064. align: 'center',
  60065. position: 'inside',
  60066. distance: 5,
  60067. silent: true,
  60068. emphasis: {}
  60069. },
  60070. itemStyle: {
  60071. borderWidth: 1,
  60072. borderColor: 'white',
  60073. borderType: 'solid',
  60074. shadowBlur: 0,
  60075. shadowColor: 'rgba(0, 0, 0, 0.2)',
  60076. shadowOffsetX: 0,
  60077. shadowOffsetY: 0,
  60078. opacity: 1,
  60079. emphasis: {},
  60080. highlight: {
  60081. opacity: 1
  60082. },
  60083. downplay: {
  60084. opacity: 0.9
  60085. }
  60086. },
  60087. // Animation type canbe expansion, scale
  60088. animationType: 'expansion',
  60089. animationDuration: 1000,
  60090. animationDurationUpdate: 500,
  60091. animationEasing: 'cubicOut',
  60092. data: [],
  60093. levels: [],
  60094. /**
  60095. * Sort order.
  60096. *
  60097. * Valid values: 'desc', 'asc', null, or callback function.
  60098. * 'desc' and 'asc' for descend and ascendant order;
  60099. * null for not sorting;
  60100. * example of callback function:
  60101. * function(nodeA, nodeB) {
  60102. * return nodeA.getValue() - nodeB.getValue();
  60103. * }
  60104. */
  60105. sort: 'desc'
  60106. },
  60107. getViewRoot: function () {
  60108. return this._viewRoot;
  60109. },
  60110. /**
  60111. * @param {module:echarts/data/Tree~Node} [viewRoot]
  60112. */
  60113. resetViewRoot: function (viewRoot) {
  60114. viewRoot
  60115. ? (this._viewRoot = viewRoot)
  60116. : (viewRoot = this._viewRoot);
  60117. var root = this.getRawData().tree.root;
  60118. if (!viewRoot
  60119. || (viewRoot !== root && !root.contains(viewRoot))
  60120. ) {
  60121. this._viewRoot = root;
  60122. }
  60123. }
  60124. });
  60125. /**
  60126. * @param {Object} dataNode
  60127. */
  60128. function completeTreeValue$1(dataNode) {
  60129. // Postorder travel tree.
  60130. // If value of none-leaf node is not set,
  60131. // calculate it by suming up the value of all children.
  60132. var sum = 0;
  60133. each$1(dataNode.children, function (child) {
  60134. completeTreeValue$1(child);
  60135. var childValue = child.value;
  60136. isArray(childValue) && (childValue = childValue[0]);
  60137. sum += childValue;
  60138. });
  60139. var thisValue = dataNode.value;
  60140. if (isArray(thisValue)) {
  60141. thisValue = thisValue[0];
  60142. }
  60143. if (thisValue == null || isNaN(thisValue)) {
  60144. thisValue = sum;
  60145. }
  60146. // Value should not less than 0.
  60147. if (thisValue < 0) {
  60148. thisValue = 0;
  60149. }
  60150. isArray(dataNode.value)
  60151. ? (dataNode.value[0] = thisValue)
  60152. : (dataNode.value = thisValue);
  60153. }
  60154. /*
  60155. * Licensed to the Apache Software Foundation (ASF) under one
  60156. * or more contributor license agreements. See the NOTICE file
  60157. * distributed with this work for additional information
  60158. * regarding copyright ownership. The ASF licenses this file
  60159. * to you under the Apache License, Version 2.0 (the
  60160. * "License"); you may not use this file except in compliance
  60161. * with the License. You may obtain a copy of the License at
  60162. *
  60163. * http://www.apache.org/licenses/LICENSE-2.0
  60164. *
  60165. * Unless required by applicable law or agreed to in writing,
  60166. * software distributed under the License is distributed on an
  60167. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60168. * KIND, either express or implied. See the License for the
  60169. * specific language governing permissions and limitations
  60170. * under the License.
  60171. */
  60172. var NodeHighlightPolicy = {
  60173. NONE: 'none', // not downplay others
  60174. DESCENDANT: 'descendant',
  60175. ANCESTOR: 'ancestor',
  60176. SELF: 'self'
  60177. };
  60178. var DEFAULT_SECTOR_Z = 2;
  60179. var DEFAULT_TEXT_Z = 4;
  60180. /**
  60181. * Sunburstce of Sunburst including Sector, Label, LabelLine
  60182. * @constructor
  60183. * @extends {module:zrender/graphic/Group}
  60184. */
  60185. function SunburstPiece(node, seriesModel, ecModel) {
  60186. Group.call(this);
  60187. var sector = new Sector({
  60188. z2: DEFAULT_SECTOR_Z
  60189. });
  60190. sector.seriesIndex = seriesModel.seriesIndex;
  60191. var text = new Text({
  60192. z2: DEFAULT_TEXT_Z,
  60193. silent: node.getModel('label').get('silent')
  60194. });
  60195. this.add(sector);
  60196. this.add(text);
  60197. this.updateData(true, node, 'normal', seriesModel, ecModel);
  60198. // Hover to change label and labelLine
  60199. function onEmphasis() {
  60200. text.ignore = text.hoverIgnore;
  60201. }
  60202. function onNormal() {
  60203. text.ignore = text.normalIgnore;
  60204. }
  60205. this.on('emphasis', onEmphasis)
  60206. .on('normal', onNormal)
  60207. .on('mouseover', onEmphasis)
  60208. .on('mouseout', onNormal);
  60209. }
  60210. var SunburstPieceProto = SunburstPiece.prototype;
  60211. SunburstPieceProto.updateData = function (
  60212. firstCreate,
  60213. node,
  60214. state,
  60215. seriesModel,
  60216. ecModel
  60217. ) {
  60218. this.node = node;
  60219. node.piece = this;
  60220. seriesModel = seriesModel || this._seriesModel;
  60221. ecModel = ecModel || this._ecModel;
  60222. var sector = this.childAt(0);
  60223. sector.dataIndex = node.dataIndex;
  60224. var itemModel = node.getModel();
  60225. var layout = node.getLayout();
  60226. // if (!layout) {
  60227. // console.log(node.getLayout());
  60228. // }
  60229. var sectorShape = extend({}, layout);
  60230. sectorShape.label = null;
  60231. var visualColor = getNodeColor(node, seriesModel, ecModel);
  60232. fillDefaultColor(node, seriesModel, visualColor);
  60233. var normalStyle = itemModel.getModel('itemStyle').getItemStyle();
  60234. var style;
  60235. if (state === 'normal') {
  60236. style = normalStyle;
  60237. }
  60238. else {
  60239. var stateStyle = itemModel.getModel(state + '.itemStyle')
  60240. .getItemStyle();
  60241. style = merge(stateStyle, normalStyle);
  60242. }
  60243. style = defaults(
  60244. {
  60245. lineJoin: 'bevel',
  60246. fill: style.fill || visualColor
  60247. },
  60248. style
  60249. );
  60250. if (firstCreate) {
  60251. sector.setShape(sectorShape);
  60252. sector.shape.r = layout.r0;
  60253. updateProps(
  60254. sector,
  60255. {
  60256. shape: {
  60257. r: layout.r
  60258. }
  60259. },
  60260. seriesModel,
  60261. node.dataIndex
  60262. );
  60263. sector.useStyle(style);
  60264. }
  60265. else if (typeof style.fill === 'object' && style.fill.type
  60266. || typeof sector.style.fill === 'object' && sector.style.fill.type
  60267. ) {
  60268. // Disable animation for gradient since no interpolation method
  60269. // is supported for gradient
  60270. updateProps(sector, {
  60271. shape: sectorShape
  60272. }, seriesModel);
  60273. sector.useStyle(style);
  60274. }
  60275. else {
  60276. updateProps(sector, {
  60277. shape: sectorShape,
  60278. style: style
  60279. }, seriesModel);
  60280. }
  60281. this._updateLabel(seriesModel, visualColor, state);
  60282. var cursorStyle = itemModel.getShallow('cursor');
  60283. cursorStyle && sector.attr('cursor', cursorStyle);
  60284. if (firstCreate) {
  60285. var highlightPolicy = seriesModel.getShallow('highlightPolicy');
  60286. this._initEvents(sector, node, seriesModel, highlightPolicy);
  60287. }
  60288. this._seriesModel = seriesModel || this._seriesModel;
  60289. this._ecModel = ecModel || this._ecModel;
  60290. };
  60291. SunburstPieceProto.onEmphasis = function (highlightPolicy) {
  60292. var that = this;
  60293. this.node.hostTree.root.eachNode(function (n) {
  60294. if (n.piece) {
  60295. if (that.node === n) {
  60296. n.piece.updateData(false, n, 'emphasis');
  60297. }
  60298. else if (isNodeHighlighted(n, that.node, highlightPolicy)) {
  60299. n.piece.childAt(0).trigger('highlight');
  60300. }
  60301. else if (highlightPolicy !== NodeHighlightPolicy.NONE) {
  60302. n.piece.childAt(0).trigger('downplay');
  60303. }
  60304. }
  60305. });
  60306. };
  60307. SunburstPieceProto.onNormal = function () {
  60308. this.node.hostTree.root.eachNode(function (n) {
  60309. if (n.piece) {
  60310. n.piece.updateData(false, n, 'normal');
  60311. }
  60312. });
  60313. };
  60314. SunburstPieceProto.onHighlight = function () {
  60315. this.updateData(false, this.node, 'highlight');
  60316. };
  60317. SunburstPieceProto.onDownplay = function () {
  60318. this.updateData(false, this.node, 'downplay');
  60319. };
  60320. SunburstPieceProto._updateLabel = function (seriesModel, visualColor, state) {
  60321. var itemModel = this.node.getModel();
  60322. var normalModel = itemModel.getModel('label');
  60323. var labelModel = state === 'normal' || state === 'emphasis'
  60324. ? normalModel
  60325. : itemModel.getModel(state + '.label');
  60326. var labelHoverModel = itemModel.getModel('emphasis.label');
  60327. var text = retrieve(
  60328. seriesModel.getFormattedLabel(
  60329. this.node.dataIndex, 'normal', null, null, 'label'
  60330. ),
  60331. this.node.name
  60332. );
  60333. if (getLabelAttr('show') === false) {
  60334. text = '';
  60335. }
  60336. var layout = this.node.getLayout();
  60337. var labelMinAngle = labelModel.get('minAngle');
  60338. if (labelMinAngle == null) {
  60339. labelMinAngle = normalModel.get('minAngle');
  60340. }
  60341. labelMinAngle = labelMinAngle / 180 * Math.PI;
  60342. var angle = layout.endAngle - layout.startAngle;
  60343. if (labelMinAngle != null && Math.abs(angle) < labelMinAngle) {
  60344. // Not displaying text when angle is too small
  60345. text = '';
  60346. }
  60347. var label = this.childAt(1);
  60348. setLabelStyle(
  60349. label.style, label.hoverStyle || {}, normalModel, labelHoverModel,
  60350. {
  60351. defaultText: labelModel.getShallow('show') ? text : null,
  60352. autoColor: visualColor,
  60353. useInsideStyle: true
  60354. }
  60355. );
  60356. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  60357. var dx = Math.cos(midAngle);
  60358. var dy = Math.sin(midAngle);
  60359. var r;
  60360. var labelPosition = getLabelAttr('position');
  60361. var labelPadding = getLabelAttr('distance') || 0;
  60362. var textAlign = getLabelAttr('align');
  60363. if (labelPosition === 'outside') {
  60364. r = layout.r + labelPadding;
  60365. textAlign = midAngle > Math.PI / 2 ? 'right' : 'left';
  60366. }
  60367. else {
  60368. if (!textAlign || textAlign === 'center') {
  60369. r = (layout.r + layout.r0) / 2;
  60370. textAlign = 'center';
  60371. }
  60372. else if (textAlign === 'left') {
  60373. r = layout.r0 + labelPadding;
  60374. if (midAngle > Math.PI / 2) {
  60375. textAlign = 'right';
  60376. }
  60377. }
  60378. else if (textAlign === 'right') {
  60379. r = layout.r - labelPadding;
  60380. if (midAngle > Math.PI / 2) {
  60381. textAlign = 'left';
  60382. }
  60383. }
  60384. }
  60385. label.attr('style', {
  60386. text: text,
  60387. textAlign: textAlign,
  60388. textVerticalAlign: getLabelAttr('verticalAlign') || 'middle',
  60389. opacity: getLabelAttr('opacity')
  60390. });
  60391. var textX = r * dx + layout.cx;
  60392. var textY = r * dy + layout.cy;
  60393. label.attr('position', [textX, textY]);
  60394. var rotateType = getLabelAttr('rotate');
  60395. var rotate = 0;
  60396. if (rotateType === 'radial') {
  60397. rotate = -midAngle;
  60398. if (rotate < -Math.PI / 2) {
  60399. rotate += Math.PI;
  60400. }
  60401. }
  60402. else if (rotateType === 'tangential') {
  60403. rotate = Math.PI / 2 - midAngle;
  60404. if (rotate > Math.PI / 2) {
  60405. rotate -= Math.PI;
  60406. }
  60407. else if (rotate < -Math.PI / 2) {
  60408. rotate += Math.PI;
  60409. }
  60410. } else if (typeof rotateType === 'number') {
  60411. rotate = rotateType * Math.PI / 180;
  60412. }
  60413. label.attr('rotation', rotate);
  60414. function getLabelAttr(name) {
  60415. var stateAttr = labelModel.get(name);
  60416. if (stateAttr == null) {
  60417. return normalModel.get(name);
  60418. }
  60419. else {
  60420. return stateAttr;
  60421. }
  60422. }
  60423. };
  60424. SunburstPieceProto._initEvents = function (
  60425. sector,
  60426. node,
  60427. seriesModel,
  60428. highlightPolicy
  60429. ) {
  60430. sector.off('mouseover').off('mouseout').off('emphasis').off('normal');
  60431. var that = this;
  60432. var onEmphasis = function () {
  60433. that.onEmphasis(highlightPolicy);
  60434. };
  60435. var onNormal = function () {
  60436. that.onNormal();
  60437. };
  60438. var onDownplay = function () {
  60439. that.onDownplay();
  60440. };
  60441. var onHighlight = function () {
  60442. that.onHighlight();
  60443. };
  60444. if (seriesModel.isAnimationEnabled()) {
  60445. sector
  60446. .on('mouseover', onEmphasis)
  60447. .on('mouseout', onNormal)
  60448. .on('emphasis', onEmphasis)
  60449. .on('normal', onNormal)
  60450. .on('downplay', onDownplay)
  60451. .on('highlight', onHighlight);
  60452. }
  60453. };
  60454. inherits(SunburstPiece, Group);
  60455. /**
  60456. * Get node color
  60457. *
  60458. * @param {TreeNode} node the node to get color
  60459. * @param {module:echarts/model/Series} seriesModel series
  60460. * @param {module:echarts/model/Global} ecModel echarts defaults
  60461. */
  60462. function getNodeColor(node, seriesModel, ecModel) {
  60463. // Color from visualMap
  60464. var visualColor = node.getVisual('color');
  60465. var visualMetaList = node.getVisual('visualMeta');
  60466. if (!visualMetaList || visualMetaList.length === 0) {
  60467. // Use first-generation color if has no visualMap
  60468. visualColor = null;
  60469. }
  60470. // Self color or level color
  60471. var color = node.getModel('itemStyle').get('color');
  60472. if (color) {
  60473. return color;
  60474. }
  60475. else if (visualColor) {
  60476. // Color mapping
  60477. return visualColor;
  60478. }
  60479. else if (node.depth === 0) {
  60480. // Virtual root node
  60481. return ecModel.option.color[0];
  60482. }
  60483. else {
  60484. // First-generation color
  60485. var length = ecModel.option.color.length;
  60486. color = ecModel.option.color[getRootId(node) % length];
  60487. }
  60488. return color;
  60489. }
  60490. /**
  60491. * Get index of root in sorted order
  60492. *
  60493. * @param {TreeNode} node current node
  60494. * @return {number} index in root
  60495. */
  60496. function getRootId(node) {
  60497. var ancestor = node;
  60498. while (ancestor.depth > 1) {
  60499. ancestor = ancestor.parentNode;
  60500. }
  60501. var virtualRoot = node.getAncestors()[0];
  60502. return indexOf(virtualRoot.children, ancestor);
  60503. }
  60504. function isNodeHighlighted(node, activeNode, policy) {
  60505. if (policy === NodeHighlightPolicy.NONE) {
  60506. return false;
  60507. }
  60508. else if (policy === NodeHighlightPolicy.SELF) {
  60509. return node === activeNode;
  60510. }
  60511. else if (policy === NodeHighlightPolicy.ANCESTOR) {
  60512. return node === activeNode || node.isAncestorOf(activeNode);
  60513. }
  60514. else {
  60515. return node === activeNode || node.isDescendantOf(activeNode);
  60516. }
  60517. }
  60518. // Fix tooltip callback function params.color incorrect when pick a default color
  60519. function fillDefaultColor(node, seriesModel, color) {
  60520. var data = seriesModel.getData();
  60521. data.setItemVisual(node.dataIndex, 'color', color);
  60522. }
  60523. /*
  60524. * Licensed to the Apache Software Foundation (ASF) under one
  60525. * or more contributor license agreements. See the NOTICE file
  60526. * distributed with this work for additional information
  60527. * regarding copyright ownership. The ASF licenses this file
  60528. * to you under the Apache License, Version 2.0 (the
  60529. * "License"); you may not use this file except in compliance
  60530. * with the License. You may obtain a copy of the License at
  60531. *
  60532. * http://www.apache.org/licenses/LICENSE-2.0
  60533. *
  60534. * Unless required by applicable law or agreed to in writing,
  60535. * software distributed under the License is distributed on an
  60536. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60537. * KIND, either express or implied. See the License for the
  60538. * specific language governing permissions and limitations
  60539. * under the License.
  60540. */
  60541. var ROOT_TO_NODE_ACTION = 'sunburstRootToNode';
  60542. var SunburstView = Chart.extend({
  60543. type: 'sunburst',
  60544. init: function () {
  60545. },
  60546. render: function (seriesModel, ecModel, api, payload) {
  60547. var that = this;
  60548. this.seriesModel = seriesModel;
  60549. this.api = api;
  60550. this.ecModel = ecModel;
  60551. var data = seriesModel.getData();
  60552. var virtualRoot = data.tree.root;
  60553. var newRoot = seriesModel.getViewRoot();
  60554. var group = this.group;
  60555. var renderLabelForZeroData = seriesModel.get('renderLabelForZeroData');
  60556. var newChildren = [];
  60557. newRoot.eachNode(function (node) {
  60558. newChildren.push(node);
  60559. });
  60560. var oldChildren = this._oldChildren || [];
  60561. dualTravel(newChildren, oldChildren);
  60562. renderRollUp(virtualRoot, newRoot);
  60563. if (payload && payload.highlight && payload.highlight.piece) {
  60564. var highlightPolicy = seriesModel.getShallow('highlightPolicy');
  60565. payload.highlight.piece.onEmphasis(highlightPolicy);
  60566. }
  60567. else if (payload && payload.unhighlight) {
  60568. var piece = this.virtualPiece;
  60569. if (!piece && virtualRoot.children.length) {
  60570. piece = virtualRoot.children[0].piece;
  60571. }
  60572. if (piece) {
  60573. piece.onNormal();
  60574. }
  60575. }
  60576. this._initEvents();
  60577. this._oldChildren = newChildren;
  60578. function dualTravel(newChildren, oldChildren) {
  60579. if (newChildren.length === 0 && oldChildren.length === 0) {
  60580. return;
  60581. }
  60582. new DataDiffer(oldChildren, newChildren, getKey, getKey)
  60583. .add(processNode)
  60584. .update(processNode)
  60585. .remove(curry(processNode, null))
  60586. .execute();
  60587. function getKey(node) {
  60588. return node.getId();
  60589. }
  60590. function processNode(newId, oldId) {
  60591. var newNode = newId == null ? null : newChildren[newId];
  60592. var oldNode = oldId == null ? null : oldChildren[oldId];
  60593. doRenderNode(newNode, oldNode);
  60594. }
  60595. }
  60596. function doRenderNode(newNode, oldNode) {
  60597. if (!renderLabelForZeroData && newNode && !newNode.getValue()) {
  60598. // Not render data with value 0
  60599. newNode = null;
  60600. }
  60601. if (newNode !== virtualRoot && oldNode !== virtualRoot) {
  60602. if (oldNode && oldNode.piece) {
  60603. if (newNode) {
  60604. // Update
  60605. oldNode.piece.updateData(
  60606. false, newNode, 'normal', seriesModel, ecModel);
  60607. // For tooltip
  60608. data.setItemGraphicEl(newNode.dataIndex, oldNode.piece);
  60609. }
  60610. else {
  60611. // Remove
  60612. removeNode(oldNode);
  60613. }
  60614. }
  60615. else if (newNode) {
  60616. // Add
  60617. var piece = new SunburstPiece(
  60618. newNode,
  60619. seriesModel,
  60620. ecModel
  60621. );
  60622. group.add(piece);
  60623. // For tooltip
  60624. data.setItemGraphicEl(newNode.dataIndex, piece);
  60625. }
  60626. }
  60627. }
  60628. function removeNode(node) {
  60629. if (!node) {
  60630. return;
  60631. }
  60632. if (node.piece) {
  60633. group.remove(node.piece);
  60634. node.piece = null;
  60635. }
  60636. }
  60637. function renderRollUp(virtualRoot, viewRoot) {
  60638. if (viewRoot.depth > 0) {
  60639. // Render
  60640. if (that.virtualPiece) {
  60641. // Update
  60642. that.virtualPiece.updateData(
  60643. false, virtualRoot, 'normal', seriesModel, ecModel);
  60644. }
  60645. else {
  60646. // Add
  60647. that.virtualPiece = new SunburstPiece(
  60648. virtualRoot,
  60649. seriesModel,
  60650. ecModel
  60651. );
  60652. group.add(that.virtualPiece);
  60653. }
  60654. if (viewRoot.piece._onclickEvent) {
  60655. viewRoot.piece.off('click', viewRoot.piece._onclickEvent);
  60656. }
  60657. var event = function (e) {
  60658. that._rootToNode(viewRoot.parentNode);
  60659. };
  60660. viewRoot.piece._onclickEvent = event;
  60661. that.virtualPiece.on('click', event);
  60662. }
  60663. else if (that.virtualPiece) {
  60664. // Remove
  60665. group.remove(that.virtualPiece);
  60666. that.virtualPiece = null;
  60667. }
  60668. }
  60669. },
  60670. dispose: function () {
  60671. },
  60672. /**
  60673. * @private
  60674. */
  60675. _initEvents: function () {
  60676. var that = this;
  60677. var event = function (e) {
  60678. var targetFound = false;
  60679. var viewRoot = that.seriesModel.getViewRoot();
  60680. viewRoot.eachNode(function (node) {
  60681. if (!targetFound
  60682. && node.piece && node.piece.childAt(0) === e.target
  60683. ) {
  60684. var nodeClick = node.getModel().get('nodeClick');
  60685. if (nodeClick === 'rootToNode') {
  60686. that._rootToNode(node);
  60687. }
  60688. else if (nodeClick === 'link') {
  60689. var itemModel = node.getModel();
  60690. var link = itemModel.get('link');
  60691. if (link) {
  60692. var linkTarget = itemModel.get('target', true)
  60693. || '_blank';
  60694. window.open(link, linkTarget);
  60695. }
  60696. }
  60697. targetFound = true;
  60698. }
  60699. });
  60700. };
  60701. if (this.group._onclickEvent) {
  60702. this.group.off('click', this.group._onclickEvent);
  60703. }
  60704. this.group.on('click', event);
  60705. this.group._onclickEvent = event;
  60706. },
  60707. /**
  60708. * @private
  60709. */
  60710. _rootToNode: function (node) {
  60711. if (node !== this.seriesModel.getViewRoot()) {
  60712. this.api.dispatchAction({
  60713. type: ROOT_TO_NODE_ACTION,
  60714. from: this.uid,
  60715. seriesId: this.seriesModel.id,
  60716. targetNode: node
  60717. });
  60718. }
  60719. },
  60720. /**
  60721. * @implement
  60722. */
  60723. containPoint: function (point, seriesModel) {
  60724. var treeRoot = seriesModel.getData();
  60725. var itemLayout = treeRoot.getItemLayout(0);
  60726. if (itemLayout) {
  60727. var dx = point[0] - itemLayout.cx;
  60728. var dy = point[1] - itemLayout.cy;
  60729. var radius = Math.sqrt(dx * dx + dy * dy);
  60730. return radius <= itemLayout.r && radius >= itemLayout.r0;
  60731. }
  60732. }
  60733. });
  60734. /*
  60735. * Licensed to the Apache Software Foundation (ASF) under one
  60736. * or more contributor license agreements. See the NOTICE file
  60737. * distributed with this work for additional information
  60738. * regarding copyright ownership. The ASF licenses this file
  60739. * to you under the Apache License, Version 2.0 (the
  60740. * "License"); you may not use this file except in compliance
  60741. * with the License. You may obtain a copy of the License at
  60742. *
  60743. * http://www.apache.org/licenses/LICENSE-2.0
  60744. *
  60745. * Unless required by applicable law or agreed to in writing,
  60746. * software distributed under the License is distributed on an
  60747. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60748. * KIND, either express or implied. See the License for the
  60749. * specific language governing permissions and limitations
  60750. * under the License.
  60751. */
  60752. /**
  60753. * @file Sunburst action
  60754. */
  60755. var ROOT_TO_NODE_ACTION$1 = 'sunburstRootToNode';
  60756. registerAction(
  60757. {type: ROOT_TO_NODE_ACTION$1, update: 'updateView'},
  60758. function (payload, ecModel) {
  60759. ecModel.eachComponent(
  60760. {mainType: 'series', subType: 'sunburst', query: payload},
  60761. handleRootToNode
  60762. );
  60763. function handleRootToNode(model, index) {
  60764. var targetInfo = retrieveTargetInfo(payload, [ROOT_TO_NODE_ACTION$1], model);
  60765. if (targetInfo) {
  60766. var originViewRoot = model.getViewRoot();
  60767. if (originViewRoot) {
  60768. payload.direction = aboveViewRoot(originViewRoot, targetInfo.node)
  60769. ? 'rollUp' : 'drillDown';
  60770. }
  60771. model.resetViewRoot(targetInfo.node);
  60772. }
  60773. }
  60774. }
  60775. );
  60776. var HIGHLIGHT_ACTION = 'sunburstHighlight';
  60777. registerAction(
  60778. {type: HIGHLIGHT_ACTION, update: 'updateView'},
  60779. function (payload, ecModel) {
  60780. ecModel.eachComponent(
  60781. {mainType: 'series', subType: 'sunburst', query: payload},
  60782. handleHighlight
  60783. );
  60784. function handleHighlight(model, index) {
  60785. var targetInfo = retrieveTargetInfo(payload, [HIGHLIGHT_ACTION], model);
  60786. if (targetInfo) {
  60787. payload.highlight = targetInfo.node;
  60788. }
  60789. }
  60790. }
  60791. );
  60792. var UNHIGHLIGHT_ACTION = 'sunburstUnhighlight';
  60793. registerAction(
  60794. {type: UNHIGHLIGHT_ACTION, update: 'updateView'},
  60795. function (payload, ecModel) {
  60796. ecModel.eachComponent(
  60797. {mainType: 'series', subType: 'sunburst', query: payload},
  60798. handleUnhighlight
  60799. );
  60800. function handleUnhighlight(model, index) {
  60801. payload.unhighlight = true;
  60802. }
  60803. }
  60804. );
  60805. /*
  60806. * Licensed to the Apache Software Foundation (ASF) under one
  60807. * or more contributor license agreements. See the NOTICE file
  60808. * distributed with this work for additional information
  60809. * regarding copyright ownership. The ASF licenses this file
  60810. * to you under the Apache License, Version 2.0 (the
  60811. * "License"); you may not use this file except in compliance
  60812. * with the License. You may obtain a copy of the License at
  60813. *
  60814. * http://www.apache.org/licenses/LICENSE-2.0
  60815. *
  60816. * Unless required by applicable law or agreed to in writing,
  60817. * software distributed under the License is distributed on an
  60818. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60819. * KIND, either express or implied. See the License for the
  60820. * specific language governing permissions and limitations
  60821. * under the License.
  60822. */
  60823. var RADIAN$1 = Math.PI / 180;
  60824. var sunburstLayout = function (seriesType, ecModel, api, payload) {
  60825. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  60826. var center = seriesModel.get('center');
  60827. var radius = seriesModel.get('radius');
  60828. if (!isArray(radius)) {
  60829. radius = [0, radius];
  60830. }
  60831. if (!isArray(center)) {
  60832. center = [center, center];
  60833. }
  60834. var width = api.getWidth();
  60835. var height = api.getHeight();
  60836. var size = Math.min(width, height);
  60837. var cx = parsePercent$1(center[0], width);
  60838. var cy = parsePercent$1(center[1], height);
  60839. var r0 = parsePercent$1(radius[0], size / 2);
  60840. var r = parsePercent$1(radius[1], size / 2);
  60841. var startAngle = -seriesModel.get('startAngle') * RADIAN$1;
  60842. var minAngle = seriesModel.get('minAngle') * RADIAN$1;
  60843. var virtualRoot = seriesModel.getData().tree.root;
  60844. var treeRoot = seriesModel.getViewRoot();
  60845. var rootDepth = treeRoot.depth;
  60846. var sort = seriesModel.get('sort');
  60847. if (sort != null) {
  60848. initChildren$1(treeRoot, sort);
  60849. }
  60850. var validDataCount = 0;
  60851. each$1(treeRoot.children, function (child) {
  60852. !isNaN(child.getValue()) && validDataCount++;
  60853. });
  60854. var sum = treeRoot.getValue();
  60855. // Sum may be 0
  60856. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  60857. var renderRollupNode = treeRoot.depth > 0;
  60858. var levels = treeRoot.height - (renderRollupNode ? -1 : 1);
  60859. var rPerLevel = (r - r0) / (levels || 1);
  60860. var clockwise = seriesModel.get('clockwise');
  60861. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  60862. // In the case some sector angle is smaller than minAngle
  60863. var dir = clockwise ? 1 : -1;
  60864. /**
  60865. * Render a tree
  60866. * @return increased angle
  60867. */
  60868. var renderNode = function (node, startAngle) {
  60869. if (!node) {
  60870. return;
  60871. }
  60872. var endAngle = startAngle;
  60873. // Render self
  60874. if (node !== virtualRoot) {
  60875. // Tree node is virtual, so it doesn't need to be drawn
  60876. var value = node.getValue();
  60877. var angle = (sum === 0 && stillShowZeroSum)
  60878. ? unitRadian : (value * unitRadian);
  60879. if (angle < minAngle) {
  60880. angle = minAngle;
  60881. }
  60882. else {
  60883. }
  60884. endAngle = startAngle + dir * angle;
  60885. var depth = node.depth - rootDepth
  60886. - (renderRollupNode ? -1 : 1);
  60887. var rStart = r0 + rPerLevel * depth;
  60888. var rEnd = r0 + rPerLevel * (depth + 1);
  60889. var itemModel = node.getModel();
  60890. if (itemModel.get('r0') != null) {
  60891. rStart = parsePercent$1(itemModel.get('r0'), size / 2);
  60892. }
  60893. if (itemModel.get('r') != null) {
  60894. rEnd = parsePercent$1(itemModel.get('r'), size / 2);
  60895. }
  60896. node.setLayout({
  60897. angle: angle,
  60898. startAngle: startAngle,
  60899. endAngle: endAngle,
  60900. clockwise: clockwise,
  60901. cx: cx,
  60902. cy: cy,
  60903. r0: rStart,
  60904. r: rEnd
  60905. });
  60906. }
  60907. // Render children
  60908. if (node.children && node.children.length) {
  60909. // currentAngle = startAngle;
  60910. var siblingAngle = 0;
  60911. each$1(node.children, function (node) {
  60912. siblingAngle += renderNode(node, startAngle + siblingAngle);
  60913. });
  60914. }
  60915. return endAngle - startAngle;
  60916. };
  60917. // Virtual root node for roll up
  60918. if (renderRollupNode) {
  60919. var rStart = r0;
  60920. var rEnd = r0 + rPerLevel;
  60921. var angle = Math.PI * 2;
  60922. virtualRoot.setLayout({
  60923. angle: angle,
  60924. startAngle: startAngle,
  60925. endAngle: startAngle + angle,
  60926. clockwise: clockwise,
  60927. cx: cx,
  60928. cy: cy,
  60929. r0: rStart,
  60930. r: rEnd
  60931. });
  60932. }
  60933. renderNode(treeRoot, startAngle);
  60934. });
  60935. };
  60936. /**
  60937. * Init node children by order and update visual
  60938. *
  60939. * @param {TreeNode} node root node
  60940. * @param {boolean} isAsc if is in ascendant order
  60941. */
  60942. function initChildren$1(node, isAsc) {
  60943. var children = node.children || [];
  60944. node.children = sort$2(children, isAsc);
  60945. // Init children recursively
  60946. if (children.length) {
  60947. each$1(node.children, function (child) {
  60948. initChildren$1(child, isAsc);
  60949. });
  60950. }
  60951. }
  60952. /**
  60953. * Sort children nodes
  60954. *
  60955. * @param {TreeNode[]} children children of node to be sorted
  60956. * @param {string | function | null} sort sort method
  60957. * See SunburstSeries.js for details.
  60958. */
  60959. function sort$2(children, sortOrder) {
  60960. if (typeof sortOrder === 'function') {
  60961. return children.sort(sortOrder);
  60962. }
  60963. else {
  60964. var isAsc = sortOrder === 'asc';
  60965. return children.sort(function (a, b) {
  60966. var diff = (a.getValue() - b.getValue()) * (isAsc ? 1 : -1);
  60967. return diff === 0
  60968. ? (a.dataIndex - b.dataIndex) * (isAsc ? -1 : 1)
  60969. : diff;
  60970. });
  60971. }
  60972. }
  60973. /*
  60974. * Licensed to the Apache Software Foundation (ASF) under one
  60975. * or more contributor license agreements. See the NOTICE file
  60976. * distributed with this work for additional information
  60977. * regarding copyright ownership. The ASF licenses this file
  60978. * to you under the Apache License, Version 2.0 (the
  60979. * "License"); you may not use this file except in compliance
  60980. * with the License. You may obtain a copy of the License at
  60981. *
  60982. * http://www.apache.org/licenses/LICENSE-2.0
  60983. *
  60984. * Unless required by applicable law or agreed to in writing,
  60985. * software distributed under the License is distributed on an
  60986. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60987. * KIND, either express or implied. See the License for the
  60988. * specific language governing permissions and limitations
  60989. * under the License.
  60990. */
  60991. registerVisual(curry(dataColor, 'sunburst'));
  60992. registerLayout(curry(sunburstLayout, 'sunburst'));
  60993. registerProcessor(curry(dataFilter, 'sunburst'));
  60994. /*
  60995. * Licensed to the Apache Software Foundation (ASF) under one
  60996. * or more contributor license agreements. See the NOTICE file
  60997. * distributed with this work for additional information
  60998. * regarding copyright ownership. The ASF licenses this file
  60999. * to you under the Apache License, Version 2.0 (the
  61000. * "License"); you may not use this file except in compliance
  61001. * with the License. You may obtain a copy of the License at
  61002. *
  61003. * http://www.apache.org/licenses/LICENSE-2.0
  61004. *
  61005. * Unless required by applicable law or agreed to in writing,
  61006. * software distributed under the License is distributed on an
  61007. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61008. * KIND, either express or implied. See the License for the
  61009. * specific language governing permissions and limitations
  61010. * under the License.
  61011. */
  61012. function dataToCoordSize(dataSize, dataItem) {
  61013. // dataItem is necessary in log axis.
  61014. dataItem = dataItem || [0, 0];
  61015. return map(['x', 'y'], function (dim, dimIdx) {
  61016. var axis = this.getAxis(dim);
  61017. var val = dataItem[dimIdx];
  61018. var halfSize = dataSize[dimIdx] / 2;
  61019. return axis.type === 'category'
  61020. ? axis.getBandWidth()
  61021. : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  61022. }, this);
  61023. }
  61024. var prepareCartesian2d = function (coordSys) {
  61025. var rect = coordSys.grid.getRect();
  61026. return {
  61027. coordSys: {
  61028. // The name exposed to user is always 'cartesian2d' but not 'grid'.
  61029. type: 'cartesian2d',
  61030. x: rect.x,
  61031. y: rect.y,
  61032. width: rect.width,
  61033. height: rect.height
  61034. },
  61035. api: {
  61036. coord: function (data) {
  61037. // do not provide "out" param
  61038. return coordSys.dataToPoint(data);
  61039. },
  61040. size: bind(dataToCoordSize, coordSys)
  61041. }
  61042. };
  61043. };
  61044. /*
  61045. * Licensed to the Apache Software Foundation (ASF) under one
  61046. * or more contributor license agreements. See the NOTICE file
  61047. * distributed with this work for additional information
  61048. * regarding copyright ownership. The ASF licenses this file
  61049. * to you under the Apache License, Version 2.0 (the
  61050. * "License"); you may not use this file except in compliance
  61051. * with the License. You may obtain a copy of the License at
  61052. *
  61053. * http://www.apache.org/licenses/LICENSE-2.0
  61054. *
  61055. * Unless required by applicable law or agreed to in writing,
  61056. * software distributed under the License is distributed on an
  61057. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61058. * KIND, either express or implied. See the License for the
  61059. * specific language governing permissions and limitations
  61060. * under the License.
  61061. */
  61062. function dataToCoordSize$1(dataSize, dataItem) {
  61063. dataItem = dataItem || [0, 0];
  61064. return map([0, 1], function (dimIdx) {
  61065. var val = dataItem[dimIdx];
  61066. var halfSize = dataSize[dimIdx] / 2;
  61067. var p1 = [];
  61068. var p2 = [];
  61069. p1[dimIdx] = val - halfSize;
  61070. p2[dimIdx] = val + halfSize;
  61071. p1[1 - dimIdx] = p2[1 - dimIdx] = dataItem[1 - dimIdx];
  61072. return Math.abs(this.dataToPoint(p1)[dimIdx] - this.dataToPoint(p2)[dimIdx]);
  61073. }, this);
  61074. }
  61075. var prepareGeo = function (coordSys) {
  61076. var rect = coordSys.getBoundingRect();
  61077. return {
  61078. coordSys: {
  61079. type: 'geo',
  61080. x: rect.x,
  61081. y: rect.y,
  61082. width: rect.width,
  61083. height: rect.height,
  61084. zoom: coordSys.getZoom()
  61085. },
  61086. api: {
  61087. coord: function (data) {
  61088. // do not provide "out" and noRoam param,
  61089. // Compatible with this usage:
  61090. // echarts.util.map(item.points, api.coord)
  61091. return coordSys.dataToPoint(data);
  61092. },
  61093. size: bind(dataToCoordSize$1, coordSys)
  61094. }
  61095. };
  61096. };
  61097. /*
  61098. * Licensed to the Apache Software Foundation (ASF) under one
  61099. * or more contributor license agreements. See the NOTICE file
  61100. * distributed with this work for additional information
  61101. * regarding copyright ownership. The ASF licenses this file
  61102. * to you under the Apache License, Version 2.0 (the
  61103. * "License"); you may not use this file except in compliance
  61104. * with the License. You may obtain a copy of the License at
  61105. *
  61106. * http://www.apache.org/licenses/LICENSE-2.0
  61107. *
  61108. * Unless required by applicable law or agreed to in writing,
  61109. * software distributed under the License is distributed on an
  61110. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61111. * KIND, either express or implied. See the License for the
  61112. * specific language governing permissions and limitations
  61113. * under the License.
  61114. */
  61115. function dataToCoordSize$2(dataSize, dataItem) {
  61116. // dataItem is necessary in log axis.
  61117. var axis = this.getAxis();
  61118. var val = dataItem instanceof Array ? dataItem[0] : dataItem;
  61119. var halfSize = (dataSize instanceof Array ? dataSize[0] : dataSize) / 2;
  61120. return axis.type === 'category'
  61121. ? axis.getBandWidth()
  61122. : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  61123. }
  61124. var prepareSingleAxis = function (coordSys) {
  61125. var rect = coordSys.getRect();
  61126. return {
  61127. coordSys: {
  61128. type: 'singleAxis',
  61129. x: rect.x,
  61130. y: rect.y,
  61131. width: rect.width,
  61132. height: rect.height
  61133. },
  61134. api: {
  61135. coord: function (val) {
  61136. // do not provide "out" param
  61137. return coordSys.dataToPoint(val);
  61138. },
  61139. size: bind(dataToCoordSize$2, coordSys)
  61140. }
  61141. };
  61142. };
  61143. /*
  61144. * Licensed to the Apache Software Foundation (ASF) under one
  61145. * or more contributor license agreements. See the NOTICE file
  61146. * distributed with this work for additional information
  61147. * regarding copyright ownership. The ASF licenses this file
  61148. * to you under the Apache License, Version 2.0 (the
  61149. * "License"); you may not use this file except in compliance
  61150. * with the License. You may obtain a copy of the License at
  61151. *
  61152. * http://www.apache.org/licenses/LICENSE-2.0
  61153. *
  61154. * Unless required by applicable law or agreed to in writing,
  61155. * software distributed under the License is distributed on an
  61156. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61157. * KIND, either express or implied. See the License for the
  61158. * specific language governing permissions and limitations
  61159. * under the License.
  61160. */
  61161. function dataToCoordSize$3(dataSize, dataItem) {
  61162. // dataItem is necessary in log axis.
  61163. return map(['Radius', 'Angle'], function (dim, dimIdx) {
  61164. var axis = this['get' + dim + 'Axis']();
  61165. var val = dataItem[dimIdx];
  61166. var halfSize = dataSize[dimIdx] / 2;
  61167. var method = 'dataTo' + dim;
  61168. var result = axis.type === 'category'
  61169. ? axis.getBandWidth()
  61170. : Math.abs(axis[method](val - halfSize) - axis[method](val + halfSize));
  61171. if (dim === 'Angle') {
  61172. result = result * Math.PI / 180;
  61173. }
  61174. return result;
  61175. }, this);
  61176. }
  61177. var preparePolar = function (coordSys) {
  61178. var radiusAxis = coordSys.getRadiusAxis();
  61179. var angleAxis = coordSys.getAngleAxis();
  61180. var radius = radiusAxis.getExtent();
  61181. radius[0] > radius[1] && radius.reverse();
  61182. return {
  61183. coordSys: {
  61184. type: 'polar',
  61185. cx: coordSys.cx,
  61186. cy: coordSys.cy,
  61187. r: radius[1],
  61188. r0: radius[0]
  61189. },
  61190. api: {
  61191. coord: bind(function (data) {
  61192. var radius = radiusAxis.dataToRadius(data[0]);
  61193. var angle = angleAxis.dataToAngle(data[1]);
  61194. var coord = coordSys.coordToPoint([radius, angle]);
  61195. coord.push(radius, angle * Math.PI / 180);
  61196. return coord;
  61197. }),
  61198. size: bind(dataToCoordSize$3, coordSys)
  61199. }
  61200. };
  61201. };
  61202. /*
  61203. * Licensed to the Apache Software Foundation (ASF) under one
  61204. * or more contributor license agreements. See the NOTICE file
  61205. * distributed with this work for additional information
  61206. * regarding copyright ownership. The ASF licenses this file
  61207. * to you under the Apache License, Version 2.0 (the
  61208. * "License"); you may not use this file except in compliance
  61209. * with the License. You may obtain a copy of the License at
  61210. *
  61211. * http://www.apache.org/licenses/LICENSE-2.0
  61212. *
  61213. * Unless required by applicable law or agreed to in writing,
  61214. * software distributed under the License is distributed on an
  61215. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61216. * KIND, either express or implied. See the License for the
  61217. * specific language governing permissions and limitations
  61218. * under the License.
  61219. */
  61220. var prepareCalendar = function (coordSys) {
  61221. var rect = coordSys.getRect();
  61222. var rangeInfo = coordSys.getRangeInfo();
  61223. return {
  61224. coordSys: {
  61225. type: 'calendar',
  61226. x: rect.x,
  61227. y: rect.y,
  61228. width: rect.width,
  61229. height: rect.height,
  61230. cellWidth: coordSys.getCellWidth(),
  61231. cellHeight: coordSys.getCellHeight(),
  61232. rangeInfo: {
  61233. start: rangeInfo.start,
  61234. end: rangeInfo.end,
  61235. weeks: rangeInfo.weeks,
  61236. dayCount: rangeInfo.allDay
  61237. }
  61238. },
  61239. api: {
  61240. coord: function (data, clamp) {
  61241. return coordSys.dataToPoint(data, clamp);
  61242. }
  61243. }
  61244. };
  61245. };
  61246. /*
  61247. * Licensed to the Apache Software Foundation (ASF) under one
  61248. * or more contributor license agreements. See the NOTICE file
  61249. * distributed with this work for additional information
  61250. * regarding copyright ownership. The ASF licenses this file
  61251. * to you under the Apache License, Version 2.0 (the
  61252. * "License"); you may not use this file except in compliance
  61253. * with the License. You may obtain a copy of the License at
  61254. *
  61255. * http://www.apache.org/licenses/LICENSE-2.0
  61256. *
  61257. * Unless required by applicable law or agreed to in writing,
  61258. * software distributed under the License is distributed on an
  61259. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61260. * KIND, either express or implied. See the License for the
  61261. * specific language governing permissions and limitations
  61262. * under the License.
  61263. */
  61264. var ITEM_STYLE_NORMAL_PATH = ['itemStyle'];
  61265. var ITEM_STYLE_EMPHASIS_PATH = ['emphasis', 'itemStyle'];
  61266. var LABEL_NORMAL = ['label'];
  61267. var LABEL_EMPHASIS = ['emphasis', 'label'];
  61268. // Use prefix to avoid index to be the same as el.name,
  61269. // which will cause weird udpate animation.
  61270. var GROUP_DIFF_PREFIX = 'e\0\0';
  61271. /**
  61272. * To reduce total package size of each coordinate systems, the modules `prepareCustom`
  61273. * of each coordinate systems are not required by each coordinate systems directly, but
  61274. * required by the module `custom`.
  61275. *
  61276. * prepareInfoForCustomSeries {Function}: optional
  61277. * @return {Object} {coordSys: {...}, api: {
  61278. * coord: function (data, clamp) {}, // return point in global.
  61279. * size: function (dataSize, dataItem) {} // return size of each axis in coordSys.
  61280. * }}
  61281. */
  61282. var prepareCustoms = {
  61283. cartesian2d: prepareCartesian2d,
  61284. geo: prepareGeo,
  61285. singleAxis: prepareSingleAxis,
  61286. polar: preparePolar,
  61287. calendar: prepareCalendar
  61288. };
  61289. // ------
  61290. // Model
  61291. // ------
  61292. SeriesModel.extend({
  61293. type: 'series.custom',
  61294. dependencies: ['grid', 'polar', 'geo', 'singleAxis', 'calendar'],
  61295. defaultOption: {
  61296. coordinateSystem: 'cartesian2d', // Can be set as 'none'
  61297. zlevel: 0,
  61298. z: 2,
  61299. legendHoverLink: true,
  61300. useTransform: true
  61301. // Cartesian coordinate system
  61302. // xAxisIndex: 0,
  61303. // yAxisIndex: 0,
  61304. // Polar coordinate system
  61305. // polarIndex: 0,
  61306. // Geo coordinate system
  61307. // geoIndex: 0,
  61308. // label: {}
  61309. // itemStyle: {}
  61310. },
  61311. /**
  61312. * @override
  61313. */
  61314. getInitialData: function (option, ecModel) {
  61315. return createListFromArray(this.getSource(), this);
  61316. },
  61317. /**
  61318. * @override
  61319. */
  61320. getDataParams: function (dataIndex, dataType, el) {
  61321. var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
  61322. el && (params.info = el.info);
  61323. return params;
  61324. }
  61325. });
  61326. // -----
  61327. // View
  61328. // -----
  61329. Chart.extend({
  61330. type: 'custom',
  61331. /**
  61332. * @private
  61333. * @type {module:echarts/data/List}
  61334. */
  61335. _data: null,
  61336. /**
  61337. * @override
  61338. */
  61339. render: function (customSeries, ecModel, api, payload) {
  61340. var oldData = this._data;
  61341. var data = customSeries.getData();
  61342. var group = this.group;
  61343. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  61344. // By default, merge mode is applied. In most cases, custom series is
  61345. // used in the scenario that data amount is not large but graphic elements
  61346. // is complicated, where merge mode is probably necessary for optimization.
  61347. // For example, reuse graphic elements and only update the transform when
  61348. // roam or data zoom according to `actionType`.
  61349. data.diff(oldData)
  61350. .add(function (newIdx) {
  61351. createOrUpdate$1(
  61352. null, newIdx, renderItem(newIdx, payload), customSeries, group, data
  61353. );
  61354. })
  61355. .update(function (newIdx, oldIdx) {
  61356. var el = oldData.getItemGraphicEl(oldIdx);
  61357. createOrUpdate$1(
  61358. el, newIdx, renderItem(newIdx, payload), customSeries, group, data
  61359. );
  61360. })
  61361. .remove(function (oldIdx) {
  61362. var el = oldData.getItemGraphicEl(oldIdx);
  61363. el && group.remove(el);
  61364. })
  61365. .execute();
  61366. this._data = data;
  61367. },
  61368. incrementalPrepareRender: function (customSeries, ecModel, api) {
  61369. this.group.removeAll();
  61370. this._data = null;
  61371. },
  61372. incrementalRender: function (params, customSeries, ecModel, api, payload) {
  61373. var data = customSeries.getData();
  61374. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  61375. function setIncrementalAndHoverLayer(el) {
  61376. if (!el.isGroup) {
  61377. el.incremental = true;
  61378. el.useHoverLayer = true;
  61379. }
  61380. }
  61381. for (var idx = params.start; idx < params.end; idx++) {
  61382. var el = createOrUpdate$1(null, idx, renderItem(idx, payload), customSeries, this.group, data);
  61383. el.traverse(setIncrementalAndHoverLayer);
  61384. }
  61385. },
  61386. /**
  61387. * @override
  61388. */
  61389. dispose: noop,
  61390. /**
  61391. * @override
  61392. */
  61393. filterForExposedEvent: function (eventType, query, targetEl, packedEvent) {
  61394. var elementName = query.element;
  61395. if (elementName == null || targetEl.name === elementName) {
  61396. return true;
  61397. }
  61398. // Enable to give a name on a group made by `renderItem`, and listen
  61399. // events that triggerd by its descendents.
  61400. while ((targetEl = targetEl.parent) && targetEl !== this.group) {
  61401. if (targetEl.name === elementName) {
  61402. return true;
  61403. }
  61404. }
  61405. return false;
  61406. }
  61407. });
  61408. function createEl(elOption) {
  61409. var graphicType = elOption.type;
  61410. var el;
  61411. if (graphicType === 'path') {
  61412. var shape = elOption.shape;
  61413. // Using pathRect brings convenience to users sacle svg path.
  61414. var pathRect = (shape.width != null && shape.height != null)
  61415. ? {
  61416. x: shape.x || 0,
  61417. y: shape.y || 0,
  61418. width: shape.width,
  61419. height: shape.height
  61420. }
  61421. : null;
  61422. var pathData = getPathData(shape);
  61423. // Path is also used for icon, so layout 'center' by default.
  61424. el = makePath(pathData, null, pathRect, shape.layout || 'center');
  61425. el.__customPathData = pathData;
  61426. }
  61427. else if (graphicType === 'image') {
  61428. el = new ZImage({});
  61429. el.__customImagePath = elOption.style.image;
  61430. }
  61431. else if (graphicType === 'text') {
  61432. el = new Text({});
  61433. el.__customText = elOption.style.text;
  61434. }
  61435. else {
  61436. var Clz = graphic[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];
  61437. if (__DEV__) {
  61438. assert$1(Clz, 'graphic type "' + graphicType + '" can not be found.');
  61439. }
  61440. el = new Clz();
  61441. }
  61442. el.__customGraphicType = graphicType;
  61443. el.name = elOption.name;
  61444. return el;
  61445. }
  61446. function updateEl(el, dataIndex, elOption, animatableModel, data, isInit, isRoot) {
  61447. var transitionProps = {};
  61448. var elOptionStyle = elOption.style || {};
  61449. elOption.shape && (transitionProps.shape = clone(elOption.shape));
  61450. elOption.position && (transitionProps.position = elOption.position.slice());
  61451. elOption.scale && (transitionProps.scale = elOption.scale.slice());
  61452. elOption.origin && (transitionProps.origin = elOption.origin.slice());
  61453. elOption.rotation && (transitionProps.rotation = elOption.rotation);
  61454. if (el.type === 'image' && elOption.style) {
  61455. var targetStyle = transitionProps.style = {};
  61456. each$1(['x', 'y', 'width', 'height'], function (prop) {
  61457. prepareStyleTransition(prop, targetStyle, elOptionStyle, el.style, isInit);
  61458. });
  61459. }
  61460. if (el.type === 'text' && elOption.style) {
  61461. var targetStyle = transitionProps.style = {};
  61462. each$1(['x', 'y'], function (prop) {
  61463. prepareStyleTransition(prop, targetStyle, elOptionStyle, el.style, isInit);
  61464. });
  61465. // Compatible with previous: both support
  61466. // textFill and fill, textStroke and stroke in 'text' element.
  61467. !elOptionStyle.hasOwnProperty('textFill') && elOptionStyle.fill && (
  61468. elOptionStyle.textFill = elOptionStyle.fill
  61469. );
  61470. !elOptionStyle.hasOwnProperty('textStroke') && elOptionStyle.stroke && (
  61471. elOptionStyle.textStroke = elOptionStyle.stroke
  61472. );
  61473. }
  61474. if (el.type !== 'group') {
  61475. el.useStyle(elOptionStyle);
  61476. // Init animation.
  61477. if (isInit) {
  61478. el.style.opacity = 0;
  61479. var targetOpacity = elOptionStyle.opacity;
  61480. targetOpacity == null && (targetOpacity = 1);
  61481. initProps(el, {style: {opacity: targetOpacity}}, animatableModel, dataIndex);
  61482. }
  61483. }
  61484. if (isInit) {
  61485. el.attr(transitionProps);
  61486. }
  61487. else {
  61488. updateProps(el, transitionProps, animatableModel, dataIndex);
  61489. }
  61490. // Merge by default.
  61491. // z2 must not be null/undefined, otherwise sort error may occur.
  61492. elOption.hasOwnProperty('z2') && el.attr('z2', elOption.z2 || 0);
  61493. elOption.hasOwnProperty('silent') && el.attr('silent', elOption.silent);
  61494. elOption.hasOwnProperty('invisible') && el.attr('invisible', elOption.invisible);
  61495. elOption.hasOwnProperty('ignore') && el.attr('ignore', elOption.ignore);
  61496. // `elOption.info` enables user to mount some info on
  61497. // elements and use them in event handlers.
  61498. // Update them only when user specified, otherwise, remain.
  61499. elOption.hasOwnProperty('info') && el.attr('info', elOption.info);
  61500. // If `elOption.styleEmphasis` is `false`, remove hover style. The
  61501. // logic is ensured by `graphicUtil.setElementHoverStyle`.
  61502. var styleEmphasis = elOption.styleEmphasis;
  61503. var disableStyleEmphasis = styleEmphasis === false;
  61504. if (!(
  61505. // Try to escapse setting hover style for performance.
  61506. (el.__cusHasEmphStl && styleEmphasis == null)
  61507. || (!el.__cusHasEmphStl && disableStyleEmphasis)
  61508. )) {
  61509. // Should not use graphicUtil.setHoverStyle, since the styleEmphasis
  61510. // should not be share by group and its descendants.
  61511. setElementHoverStyle(el, styleEmphasis);
  61512. el.__cusHasEmphStl = !disableStyleEmphasis;
  61513. }
  61514. isRoot && setAsHoverStyleTrigger(el, !disableStyleEmphasis);
  61515. }
  61516. function prepareStyleTransition(prop, targetStyle, elOptionStyle, oldElStyle, isInit) {
  61517. if (elOptionStyle[prop] != null && !isInit) {
  61518. targetStyle[prop] = elOptionStyle[prop];
  61519. elOptionStyle[prop] = oldElStyle[prop];
  61520. }
  61521. }
  61522. function makeRenderItem(customSeries, data, ecModel, api) {
  61523. var renderItem = customSeries.get('renderItem');
  61524. var coordSys = customSeries.coordinateSystem;
  61525. var prepareResult = {};
  61526. if (coordSys) {
  61527. if (__DEV__) {
  61528. assert$1(renderItem, 'series.render is required.');
  61529. assert$1(
  61530. coordSys.prepareCustoms || prepareCustoms[coordSys.type],
  61531. 'This coordSys does not support custom series.'
  61532. );
  61533. }
  61534. prepareResult = coordSys.prepareCustoms
  61535. ? coordSys.prepareCustoms()
  61536. : prepareCustoms[coordSys.type](coordSys);
  61537. }
  61538. var userAPI = defaults({
  61539. getWidth: api.getWidth,
  61540. getHeight: api.getHeight,
  61541. getZr: api.getZr,
  61542. getDevicePixelRatio: api.getDevicePixelRatio,
  61543. value: value,
  61544. style: style,
  61545. styleEmphasis: styleEmphasis,
  61546. visual: visual,
  61547. barLayout: barLayout,
  61548. currentSeriesIndices: currentSeriesIndices,
  61549. font: font
  61550. }, prepareResult.api || {});
  61551. var userParams = {
  61552. // The life cycle of context: current round of rendering.
  61553. // The global life cycle is probably not necessary, because
  61554. // user can store global status by themselves.
  61555. context: {},
  61556. seriesId: customSeries.id,
  61557. seriesName: customSeries.name,
  61558. seriesIndex: customSeries.seriesIndex,
  61559. coordSys: prepareResult.coordSys,
  61560. dataInsideLength: data.count(),
  61561. encode: wrapEncodeDef(customSeries.getData())
  61562. };
  61563. // Do not support call `api` asynchronously without dataIndexInside input.
  61564. var currDataIndexInside;
  61565. var currDirty = true;
  61566. var currItemModel;
  61567. var currLabelNormalModel;
  61568. var currLabelEmphasisModel;
  61569. var currVisualColor;
  61570. return function (dataIndexInside, payload) {
  61571. currDataIndexInside = dataIndexInside;
  61572. currDirty = true;
  61573. return renderItem && renderItem(
  61574. defaults({
  61575. dataIndexInside: dataIndexInside,
  61576. dataIndex: data.getRawIndex(dataIndexInside),
  61577. // Can be used for optimization when zoom or roam.
  61578. actionType: payload ? payload.type : null
  61579. }, userParams),
  61580. userAPI
  61581. );
  61582. };
  61583. // Do not update cache until api called.
  61584. function updateCache(dataIndexInside) {
  61585. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  61586. if (currDirty) {
  61587. currItemModel = data.getItemModel(dataIndexInside);
  61588. currLabelNormalModel = currItemModel.getModel(LABEL_NORMAL);
  61589. currLabelEmphasisModel = currItemModel.getModel(LABEL_EMPHASIS);
  61590. currVisualColor = data.getItemVisual(dataIndexInside, 'color');
  61591. currDirty = false;
  61592. }
  61593. }
  61594. /**
  61595. * @public
  61596. * @param {number|string} dim
  61597. * @param {number} [dataIndexInside=currDataIndexInside]
  61598. * @return {number|string} value
  61599. */
  61600. function value(dim, dataIndexInside) {
  61601. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  61602. return data.get(data.getDimension(dim || 0), dataIndexInside);
  61603. }
  61604. /**
  61605. * By default, `visual` is applied to style (to support visualMap).
  61606. * `visual.color` is applied at `fill`. If user want apply visual.color on `stroke`,
  61607. * it can be implemented as:
  61608. * `api.style({stroke: api.visual('color'), fill: null})`;
  61609. * @public
  61610. * @param {Object} [extra]
  61611. * @param {number} [dataIndexInside=currDataIndexInside]
  61612. */
  61613. function style(extra, dataIndexInside) {
  61614. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  61615. updateCache(dataIndexInside);
  61616. var itemStyle = currItemModel.getModel(ITEM_STYLE_NORMAL_PATH).getItemStyle();
  61617. currVisualColor != null && (itemStyle.fill = currVisualColor);
  61618. var opacity = data.getItemVisual(dataIndexInside, 'opacity');
  61619. opacity != null && (itemStyle.opacity = opacity);
  61620. setTextStyle(itemStyle, currLabelNormalModel, null, {
  61621. autoColor: currVisualColor,
  61622. isRectText: true
  61623. });
  61624. itemStyle.text = currLabelNormalModel.getShallow('show')
  61625. ? retrieve2(
  61626. customSeries.getFormattedLabel(dataIndexInside, 'normal'),
  61627. getDefaultLabel(data, dataIndexInside)
  61628. )
  61629. : null;
  61630. extra && extend(itemStyle, extra);
  61631. return itemStyle;
  61632. }
  61633. /**
  61634. * @public
  61635. * @param {Object} [extra]
  61636. * @param {number} [dataIndexInside=currDataIndexInside]
  61637. */
  61638. function styleEmphasis(extra, dataIndexInside) {
  61639. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  61640. updateCache(dataIndexInside);
  61641. var itemStyle = currItemModel.getModel(ITEM_STYLE_EMPHASIS_PATH).getItemStyle();
  61642. setTextStyle(itemStyle, currLabelEmphasisModel, null, {
  61643. isRectText: true
  61644. }, true);
  61645. itemStyle.text = currLabelEmphasisModel.getShallow('show')
  61646. ? retrieve3(
  61647. customSeries.getFormattedLabel(dataIndexInside, 'emphasis'),
  61648. customSeries.getFormattedLabel(dataIndexInside, 'normal'),
  61649. getDefaultLabel(data, dataIndexInside)
  61650. )
  61651. : null;
  61652. extra && extend(itemStyle, extra);
  61653. return itemStyle;
  61654. }
  61655. /**
  61656. * @public
  61657. * @param {string} visualType
  61658. * @param {number} [dataIndexInside=currDataIndexInside]
  61659. */
  61660. function visual(visualType, dataIndexInside) {
  61661. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  61662. return data.getItemVisual(dataIndexInside, visualType);
  61663. }
  61664. /**
  61665. * @public
  61666. * @param {number} opt.count Positive interger.
  61667. * @param {number} [opt.barWidth]
  61668. * @param {number} [opt.barMaxWidth]
  61669. * @param {number} [opt.barGap]
  61670. * @param {number} [opt.barCategoryGap]
  61671. * @return {Object} {width, offset, offsetCenter} is not support, return undefined.
  61672. */
  61673. function barLayout(opt) {
  61674. if (coordSys.getBaseAxis) {
  61675. var baseAxis = coordSys.getBaseAxis();
  61676. return getLayoutOnAxis(defaults({axis: baseAxis}, opt), api);
  61677. }
  61678. }
  61679. /**
  61680. * @public
  61681. * @return {Array.<number>}
  61682. */
  61683. function currentSeriesIndices() {
  61684. return ecModel.getCurrentSeriesIndices();
  61685. }
  61686. /**
  61687. * @public
  61688. * @param {Object} opt
  61689. * @param {string} [opt.fontStyle]
  61690. * @param {number} [opt.fontWeight]
  61691. * @param {number} [opt.fontSize]
  61692. * @param {string} [opt.fontFamily]
  61693. * @return {string} font string
  61694. */
  61695. function font(opt) {
  61696. return getFont(opt, ecModel);
  61697. }
  61698. }
  61699. function wrapEncodeDef(data) {
  61700. var encodeDef = {};
  61701. each$1(data.dimensions, function (dimName, dataDimIndex) {
  61702. var dimInfo = data.getDimensionInfo(dimName);
  61703. if (!dimInfo.isExtraCoord) {
  61704. var coordDim = dimInfo.coordDim;
  61705. var dataDims = encodeDef[coordDim] = encodeDef[coordDim] || [];
  61706. dataDims[dimInfo.coordDimIndex] = dataDimIndex;
  61707. }
  61708. });
  61709. return encodeDef;
  61710. }
  61711. function createOrUpdate$1(el, dataIndex, elOption, animatableModel, group, data) {
  61712. el = doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data, true);
  61713. el && data.setItemGraphicEl(dataIndex, el);
  61714. return el;
  61715. }
  61716. function doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data, isRoot) {
  61717. // [Rule]
  61718. // By default, follow merge mode.
  61719. // (It probably brings benifit for performance in some cases of large data, where
  61720. // user program can be optimized to that only updated props needed to be re-calculated,
  61721. // or according to `actionType` some calculation can be skipped.)
  61722. // If `renderItem` returns `null`/`undefined`/`false`, remove the previous el if existing.
  61723. // (It seems that violate the "merge" principle, but most of users probably intuitively
  61724. // regard "return;" as "show nothing element whatever", so make a exception to meet the
  61725. // most cases.)
  61726. var simplyRemove = !elOption; // `null`/`undefined`/`false`
  61727. elOption = elOption || {};
  61728. var elOptionType = elOption.type;
  61729. var elOptionShape = elOption.shape;
  61730. var elOptionStyle = elOption.style;
  61731. if (el && (
  61732. simplyRemove
  61733. // || elOption.$merge === false
  61734. // If `elOptionType` is `null`, follow the merge principle.
  61735. || (elOptionType != null
  61736. && elOptionType !== el.__customGraphicType
  61737. )
  61738. || (elOptionType === 'path'
  61739. && hasOwnPathData(elOptionShape) && getPathData(elOptionShape) !== el.__customPathData
  61740. )
  61741. || (elOptionType === 'image'
  61742. && hasOwn(elOptionStyle, 'image') && elOptionStyle.image !== el.__customImagePath
  61743. )
  61744. // FIXME test and remove this restriction?
  61745. || (elOptionType === 'text'
  61746. && hasOwn(elOptionShape, 'text') && elOptionStyle.text !== el.__customText
  61747. )
  61748. )) {
  61749. group.remove(el);
  61750. el = null;
  61751. }
  61752. // `elOption.type` is undefined when `renderItem` returns nothing.
  61753. if (simplyRemove) {
  61754. return;
  61755. }
  61756. var isInit = !el;
  61757. !el && (el = createEl(elOption));
  61758. updateEl(el, dataIndex, elOption, animatableModel, data, isInit, isRoot);
  61759. if (elOptionType === 'group') {
  61760. mergeChildren(el, dataIndex, elOption, animatableModel, data);
  61761. }
  61762. // Always add whatever already added to ensure sequence.
  61763. group.add(el);
  61764. return el;
  61765. }
  61766. // Usage:
  61767. // (1) By default, `elOption.$mergeChildren` is `'byIndex'`, which indicates that
  61768. // the existing children will not be removed, and enables the feature that
  61769. // update some of the props of some of the children simply by construct
  61770. // the returned children of `renderItem` like:
  61771. // `var children = group.children = []; children[3] = {opacity: 0.5};`
  61772. // (2) If `elOption.$mergeChildren` is `'byName'`, add/update/remove children
  61773. // by child.name. But that might be lower performance.
  61774. // (3) If `elOption.$mergeChildren` is `false`, the existing children will be
  61775. // replaced totally.
  61776. // (4) If `!elOption.children`, following the "merge" principle, nothing will happen.
  61777. //
  61778. // For implementation simpleness, do not provide a direct way to remove sinlge
  61779. // child (otherwise the total indicies of the children array have to be modified).
  61780. // User can remove a single child by set its `ignore` as `true` or replace
  61781. // it by another element, where its `$merge` can be set as `true` if necessary.
  61782. function mergeChildren(el, dataIndex, elOption, animatableModel, data) {
  61783. var newChildren = elOption.children;
  61784. var newLen = newChildren ? newChildren.length : 0;
  61785. var mergeChildren = elOption.$mergeChildren;
  61786. // `diffChildrenByName` has been deprecated.
  61787. var byName = mergeChildren === 'byName' || elOption.diffChildrenByName;
  61788. var notMerge = mergeChildren === false;
  61789. // For better performance on roam update, only enter if necessary.
  61790. if (!newLen && !byName && !notMerge) {
  61791. return;
  61792. }
  61793. if (byName) {
  61794. diffGroupChildren({
  61795. oldChildren: el.children() || [],
  61796. newChildren: newChildren || [],
  61797. dataIndex: dataIndex,
  61798. animatableModel: animatableModel,
  61799. group: el,
  61800. data: data
  61801. });
  61802. return;
  61803. }
  61804. notMerge && el.removeAll();
  61805. // Mapping children of a group simply by index, which
  61806. // might be better performance.
  61807. var index = 0;
  61808. for (; index < newLen; index++) {
  61809. newChildren[index] && doCreateOrUpdate(
  61810. el.childAt(index),
  61811. dataIndex,
  61812. newChildren[index],
  61813. animatableModel,
  61814. el,
  61815. data
  61816. );
  61817. }
  61818. if (__DEV__) {
  61819. assert$1(
  61820. !notMerge || el.childCount() === index,
  61821. 'MUST NOT contain empty item in children array when `group.$mergeChildren` is `false`.'
  61822. );
  61823. }
  61824. }
  61825. function diffGroupChildren(context) {
  61826. (new DataDiffer(
  61827. context.oldChildren,
  61828. context.newChildren,
  61829. getKey,
  61830. getKey,
  61831. context
  61832. ))
  61833. .add(processAddUpdate)
  61834. .update(processAddUpdate)
  61835. .remove(processRemove)
  61836. .execute();
  61837. }
  61838. function getKey(item, idx) {
  61839. var name = item && item.name;
  61840. return name != null ? name : GROUP_DIFF_PREFIX + idx;
  61841. }
  61842. function processAddUpdate(newIndex, oldIndex) {
  61843. var context = this.context;
  61844. var childOption = newIndex != null ? context.newChildren[newIndex] : null;
  61845. var child = oldIndex != null ? context.oldChildren[oldIndex] : null;
  61846. doCreateOrUpdate(
  61847. child,
  61848. context.dataIndex,
  61849. childOption,
  61850. context.animatableModel,
  61851. context.group,
  61852. context.data
  61853. );
  61854. }
  61855. function processRemove(oldIndex) {
  61856. var context = this.context;
  61857. var child = context.oldChildren[oldIndex];
  61858. child && context.group.remove(child);
  61859. }
  61860. function getPathData(shape) {
  61861. // "d" follows the SVG convention.
  61862. return shape && (shape.pathData || shape.d);
  61863. }
  61864. function hasOwnPathData(shape) {
  61865. return shape && (shape.hasOwnProperty('pathData') || shape.hasOwnProperty('d'));
  61866. }
  61867. function hasOwn(host, prop) {
  61868. return host && host.hasOwnProperty(prop);
  61869. }
  61870. /*
  61871. * Licensed to the Apache Software Foundation (ASF) under one
  61872. * or more contributor license agreements. See the NOTICE file
  61873. * distributed with this work for additional information
  61874. * regarding copyright ownership. The ASF licenses this file
  61875. * to you under the Apache License, Version 2.0 (the
  61876. * "License"); you may not use this file except in compliance
  61877. * with the License. You may obtain a copy of the License at
  61878. *
  61879. * http://www.apache.org/licenses/LICENSE-2.0
  61880. *
  61881. * Unless required by applicable law or agreed to in writing,
  61882. * software distributed under the License is distributed on an
  61883. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61884. * KIND, either express or implied. See the License for the
  61885. * specific language governing permissions and limitations
  61886. * under the License.
  61887. */
  61888. // -------------
  61889. // Preprocessor
  61890. // -------------
  61891. registerPreprocessor(function (option) {
  61892. var graphicOption = option.graphic;
  61893. // Convert
  61894. // {graphic: [{left: 10, type: 'circle'}, ...]}
  61895. // or
  61896. // {graphic: {left: 10, type: 'circle'}}
  61897. // to
  61898. // {graphic: [{elements: [{left: 10, type: 'circle'}, ...]}]}
  61899. if (isArray(graphicOption)) {
  61900. if (!graphicOption[0] || !graphicOption[0].elements) {
  61901. option.graphic = [{elements: graphicOption}];
  61902. }
  61903. else {
  61904. // Only one graphic instance can be instantiated. (We dont
  61905. // want that too many views are created in echarts._viewMap)
  61906. option.graphic = [option.graphic[0]];
  61907. }
  61908. }
  61909. else if (graphicOption && !graphicOption.elements) {
  61910. option.graphic = [{elements: [graphicOption]}];
  61911. }
  61912. });
  61913. // ------
  61914. // Model
  61915. // ------
  61916. var GraphicModel = extendComponentModel({
  61917. type: 'graphic',
  61918. defaultOption: {
  61919. // Extra properties for each elements:
  61920. //
  61921. // left/right/top/bottom: (like 12, '22%', 'center', default undefined)
  61922. // If left/rigth is set, shape.x/shape.cx/position will not be used.
  61923. // If top/bottom is set, shape.y/shape.cy/position will not be used.
  61924. // This mechanism is useful when you want to position a group/element
  61925. // against the right side or the center of this container.
  61926. //
  61927. // width/height: (can only be pixel value, default 0)
  61928. // Only be used to specify contianer(group) size, if needed. And
  61929. // can not be percentage value (like '33%'). See the reason in the
  61930. // layout algorithm below.
  61931. //
  61932. // bounding: (enum: 'all' (default) | 'raw')
  61933. // Specify how to calculate boundingRect when locating.
  61934. // 'all': Get uioned and transformed boundingRect
  61935. // from both itself and its descendants.
  61936. // This mode simplies confining a group of elements in the bounding
  61937. // of their ancester container (e.g., using 'right: 0').
  61938. // 'raw': Only use the boundingRect of itself and before transformed.
  61939. // This mode is similar to css behavior, which is useful when you
  61940. // want an element to be able to overflow its container. (Consider
  61941. // a rotated circle needs to be located in a corner.)
  61942. // info: custom info. enables user to mount some info on elements and use them
  61943. // in event handlers. Update them only when user specified, otherwise, remain.
  61944. // Note: elements is always behind its ancestors in this elements array.
  61945. elements: [],
  61946. parentId: null
  61947. },
  61948. /**
  61949. * Save el options for the sake of the performance (only update modified graphics).
  61950. * The order is the same as those in option. (ancesters -> descendants)
  61951. *
  61952. * @private
  61953. * @type {Array.<Object>}
  61954. */
  61955. _elOptionsToUpdate: null,
  61956. /**
  61957. * @override
  61958. */
  61959. mergeOption: function (option) {
  61960. // Prevent default merge to elements
  61961. var elements = this.option.elements;
  61962. this.option.elements = null;
  61963. GraphicModel.superApply(this, 'mergeOption', arguments);
  61964. this.option.elements = elements;
  61965. },
  61966. /**
  61967. * @override
  61968. */
  61969. optionUpdated: function (newOption, isInit) {
  61970. var thisOption = this.option;
  61971. var newList = (isInit ? thisOption : newOption).elements;
  61972. var existList = thisOption.elements = isInit ? [] : thisOption.elements;
  61973. var flattenedList = [];
  61974. this._flatten(newList, flattenedList);
  61975. var mappingResult = mappingToExists(existList, flattenedList);
  61976. makeIdAndName(mappingResult);
  61977. // Clear elOptionsToUpdate
  61978. var elOptionsToUpdate = this._elOptionsToUpdate = [];
  61979. each$1(mappingResult, function (resultItem, index) {
  61980. var newElOption = resultItem.option;
  61981. if (__DEV__) {
  61982. assert$1(
  61983. isObject$1(newElOption) || resultItem.exist,
  61984. 'Empty graphic option definition'
  61985. );
  61986. }
  61987. if (!newElOption) {
  61988. return;
  61989. }
  61990. elOptionsToUpdate.push(newElOption);
  61991. setKeyInfoToNewElOption(resultItem, newElOption);
  61992. mergeNewElOptionToExist(existList, index, newElOption);
  61993. setLayoutInfoToExist(existList[index], newElOption);
  61994. }, this);
  61995. // Clean
  61996. for (var i = existList.length - 1; i >= 0; i--) {
  61997. if (existList[i] == null) {
  61998. existList.splice(i, 1);
  61999. }
  62000. else {
  62001. // $action should be volatile, otherwise option gotten from
  62002. // `getOption` will contain unexpected $action.
  62003. delete existList[i].$action;
  62004. }
  62005. }
  62006. },
  62007. /**
  62008. * Convert
  62009. * [{
  62010. * type: 'group',
  62011. * id: 'xx',
  62012. * children: [{type: 'circle'}, {type: 'polygon'}]
  62013. * }]
  62014. * to
  62015. * [
  62016. * {type: 'group', id: 'xx'},
  62017. * {type: 'circle', parentId: 'xx'},
  62018. * {type: 'polygon', parentId: 'xx'}
  62019. * ]
  62020. *
  62021. * @private
  62022. * @param {Array.<Object>} optionList option list
  62023. * @param {Array.<Object>} result result of flatten
  62024. * @param {Object} parentOption parent option
  62025. */
  62026. _flatten: function (optionList, result, parentOption) {
  62027. each$1(optionList, function (option) {
  62028. if (!option) {
  62029. return;
  62030. }
  62031. if (parentOption) {
  62032. option.parentOption = parentOption;
  62033. }
  62034. result.push(option);
  62035. var children = option.children;
  62036. if (option.type === 'group' && children) {
  62037. this._flatten(children, result, option);
  62038. }
  62039. // Deleting for JSON output, and for not affecting group creation.
  62040. delete option.children;
  62041. }, this);
  62042. },
  62043. // FIXME
  62044. // Pass to view using payload? setOption has a payload?
  62045. useElOptionsToUpdate: function () {
  62046. var els = this._elOptionsToUpdate;
  62047. // Clear to avoid render duplicately when zooming.
  62048. this._elOptionsToUpdate = null;
  62049. return els;
  62050. }
  62051. });
  62052. // -----
  62053. // View
  62054. // -----
  62055. extendComponentView({
  62056. type: 'graphic',
  62057. /**
  62058. * @override
  62059. */
  62060. init: function (ecModel, api) {
  62061. /**
  62062. * @private
  62063. * @type {module:zrender/core/util.HashMap}
  62064. */
  62065. this._elMap = createHashMap();
  62066. /**
  62067. * @private
  62068. * @type {module:echarts/graphic/GraphicModel}
  62069. */
  62070. this._lastGraphicModel;
  62071. },
  62072. /**
  62073. * @override
  62074. */
  62075. render: function (graphicModel, ecModel, api) {
  62076. // Having leveraged between use cases and algorithm complexity, a very
  62077. // simple layout mechanism is used:
  62078. // The size(width/height) can be determined by itself or its parent (not
  62079. // implemented yet), but can not by its children. (Top-down travel)
  62080. // The location(x/y) can be determined by the bounding rect of itself
  62081. // (can including its descendants or not) and the size of its parent.
  62082. // (Bottom-up travel)
  62083. // When `chart.clear()` or `chart.setOption({...}, true)` with the same id,
  62084. // view will be reused.
  62085. if (graphicModel !== this._lastGraphicModel) {
  62086. this._clear();
  62087. }
  62088. this._lastGraphicModel = graphicModel;
  62089. this._updateElements(graphicModel);
  62090. this._relocate(graphicModel, api);
  62091. },
  62092. /**
  62093. * Update graphic elements.
  62094. *
  62095. * @private
  62096. * @param {Object} graphicModel graphic model
  62097. */
  62098. _updateElements: function (graphicModel) {
  62099. var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
  62100. if (!elOptionsToUpdate) {
  62101. return;
  62102. }
  62103. var elMap = this._elMap;
  62104. var rootGroup = this.group;
  62105. // Top-down tranverse to assign graphic settings to each elements.
  62106. each$1(elOptionsToUpdate, function (elOption) {
  62107. var $action = elOption.$action;
  62108. var id = elOption.id;
  62109. var existEl = elMap.get(id);
  62110. var parentId = elOption.parentId;
  62111. var targetElParent = parentId != null ? elMap.get(parentId) : rootGroup;
  62112. var elOptionStyle = elOption.style;
  62113. if (elOption.type === 'text' && elOptionStyle) {
  62114. // In top/bottom mode, textVerticalAlign should not be used, which cause
  62115. // inaccurately locating.
  62116. if (elOption.hv && elOption.hv[1]) {
  62117. elOptionStyle.textVerticalAlign = elOptionStyle.textBaseline = null;
  62118. }
  62119. // Compatible with previous setting: both support fill and textFill,
  62120. // stroke and textStroke.
  62121. !elOptionStyle.hasOwnProperty('textFill') && elOptionStyle.fill && (
  62122. elOptionStyle.textFill = elOptionStyle.fill
  62123. );
  62124. !elOptionStyle.hasOwnProperty('textStroke') && elOptionStyle.stroke && (
  62125. elOptionStyle.textStroke = elOptionStyle.stroke
  62126. );
  62127. }
  62128. // Remove unnecessary props to avoid potential problems.
  62129. var elOptionCleaned = getCleanedElOption(elOption);
  62130. // For simple, do not support parent change, otherwise reorder is needed.
  62131. if (__DEV__) {
  62132. existEl && assert$1(
  62133. targetElParent === existEl.parent,
  62134. 'Changing parent is not supported.'
  62135. );
  62136. }
  62137. if (!$action || $action === 'merge') {
  62138. existEl
  62139. ? existEl.attr(elOptionCleaned)
  62140. : createEl$1(id, targetElParent, elOptionCleaned, elMap);
  62141. }
  62142. else if ($action === 'replace') {
  62143. removeEl(existEl, elMap);
  62144. createEl$1(id, targetElParent, elOptionCleaned, elMap);
  62145. }
  62146. else if ($action === 'remove') {
  62147. removeEl(existEl, elMap);
  62148. }
  62149. var el = elMap.get(id);
  62150. if (el) {
  62151. el.__ecGraphicWidth = elOption.width;
  62152. el.__ecGraphicHeight = elOption.height;
  62153. setEventData(el, graphicModel, elOption);
  62154. }
  62155. });
  62156. },
  62157. /**
  62158. * Locate graphic elements.
  62159. *
  62160. * @private
  62161. * @param {Object} graphicModel graphic model
  62162. * @param {module:echarts/ExtensionAPI} api extension API
  62163. */
  62164. _relocate: function (graphicModel, api) {
  62165. var elOptions = graphicModel.option.elements;
  62166. var rootGroup = this.group;
  62167. var elMap = this._elMap;
  62168. // Bottom-up tranvese all elements (consider ec resize) to locate elements.
  62169. for (var i = elOptions.length - 1; i >= 0; i--) {
  62170. var elOption = elOptions[i];
  62171. var el = elMap.get(elOption.id);
  62172. if (!el) {
  62173. continue;
  62174. }
  62175. var parentEl = el.parent;
  62176. var containerInfo = parentEl === rootGroup
  62177. ? {
  62178. width: api.getWidth(),
  62179. height: api.getHeight()
  62180. }
  62181. : { // Like 'position:absolut' in css, default 0.
  62182. width: parentEl.__ecGraphicWidth || 0,
  62183. height: parentEl.__ecGraphicHeight || 0
  62184. };
  62185. positionElement(
  62186. el, elOption, containerInfo, null,
  62187. {hv: elOption.hv, boundingMode: elOption.bounding}
  62188. );
  62189. }
  62190. },
  62191. /**
  62192. * Clear all elements.
  62193. *
  62194. * @private
  62195. */
  62196. _clear: function () {
  62197. var elMap = this._elMap;
  62198. elMap.each(function (el) {
  62199. removeEl(el, elMap);
  62200. });
  62201. this._elMap = createHashMap();
  62202. },
  62203. /**
  62204. * @override
  62205. */
  62206. dispose: function () {
  62207. this._clear();
  62208. }
  62209. });
  62210. function createEl$1(id, targetElParent, elOption, elMap) {
  62211. var graphicType = elOption.type;
  62212. if (__DEV__) {
  62213. assert$1(graphicType, 'graphic type MUST be set');
  62214. }
  62215. var Clz = graphic[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];
  62216. if (__DEV__) {
  62217. assert$1(Clz, 'graphic type can not be found');
  62218. }
  62219. var el = new Clz(elOption);
  62220. targetElParent.add(el);
  62221. elMap.set(id, el);
  62222. el.__ecGraphicId = id;
  62223. }
  62224. function removeEl(existEl, elMap) {
  62225. var existElParent = existEl && existEl.parent;
  62226. if (existElParent) {
  62227. existEl.type === 'group' && existEl.traverse(function (el) {
  62228. removeEl(el, elMap);
  62229. });
  62230. elMap.removeKey(existEl.__ecGraphicId);
  62231. existElParent.remove(existEl);
  62232. }
  62233. }
  62234. // Remove unnecessary props to avoid potential problems.
  62235. function getCleanedElOption(elOption) {
  62236. elOption = extend({}, elOption);
  62237. each$1(
  62238. ['id', 'parentId', '$action', 'hv', 'bounding'].concat(LOCATION_PARAMS),
  62239. function (name) {
  62240. delete elOption[name];
  62241. }
  62242. );
  62243. return elOption;
  62244. }
  62245. function isSetLoc(obj, props) {
  62246. var isSet;
  62247. each$1(props, function (prop) {
  62248. obj[prop] != null && obj[prop] !== 'auto' && (isSet = true);
  62249. });
  62250. return isSet;
  62251. }
  62252. function setKeyInfoToNewElOption(resultItem, newElOption) {
  62253. var existElOption = resultItem.exist;
  62254. // Set id and type after id assigned.
  62255. newElOption.id = resultItem.keyInfo.id;
  62256. !newElOption.type && existElOption && (newElOption.type = existElOption.type);
  62257. // Set parent id if not specified
  62258. if (newElOption.parentId == null) {
  62259. var newElParentOption = newElOption.parentOption;
  62260. if (newElParentOption) {
  62261. newElOption.parentId = newElParentOption.id;
  62262. }
  62263. else if (existElOption) {
  62264. newElOption.parentId = existElOption.parentId;
  62265. }
  62266. }
  62267. // Clear
  62268. newElOption.parentOption = null;
  62269. }
  62270. function mergeNewElOptionToExist(existList, index, newElOption) {
  62271. // Update existing options, for `getOption` feature.
  62272. var newElOptCopy = extend({}, newElOption);
  62273. var existElOption = existList[index];
  62274. var $action = newElOption.$action || 'merge';
  62275. if ($action === 'merge') {
  62276. if (existElOption) {
  62277. if (__DEV__) {
  62278. var newType = newElOption.type;
  62279. assert$1(
  62280. !newType || existElOption.type === newType,
  62281. 'Please set $action: "replace" to change `type`'
  62282. );
  62283. }
  62284. // We can ensure that newElOptCopy and existElOption are not
  62285. // the same object, so `merge` will not change newElOptCopy.
  62286. merge(existElOption, newElOptCopy, true);
  62287. // Rigid body, use ignoreSize.
  62288. mergeLayoutParam(existElOption, newElOptCopy, {ignoreSize: true});
  62289. // Will be used in render.
  62290. copyLayoutParams(newElOption, existElOption);
  62291. }
  62292. else {
  62293. existList[index] = newElOptCopy;
  62294. }
  62295. }
  62296. else if ($action === 'replace') {
  62297. existList[index] = newElOptCopy;
  62298. }
  62299. else if ($action === 'remove') {
  62300. // null will be cleaned later.
  62301. existElOption && (existList[index] = null);
  62302. }
  62303. }
  62304. function setLayoutInfoToExist(existItem, newElOption) {
  62305. if (!existItem) {
  62306. return;
  62307. }
  62308. existItem.hv = newElOption.hv = [
  62309. // Rigid body, dont care `width`.
  62310. isSetLoc(newElOption, ['left', 'right']),
  62311. // Rigid body, dont care `height`.
  62312. isSetLoc(newElOption, ['top', 'bottom'])
  62313. ];
  62314. // Give default group size. Otherwise layout error may occur.
  62315. if (existItem.type === 'group') {
  62316. existItem.width == null && (existItem.width = newElOption.width = 0);
  62317. existItem.height == null && (existItem.height = newElOption.height = 0);
  62318. }
  62319. }
  62320. function setEventData(el, graphicModel, elOption) {
  62321. var eventData = el.eventData;
  62322. // Simple optimize for large amount of elements that no need event.
  62323. if (!el.silent && !el.ignore && !eventData) {
  62324. eventData = el.eventData = {
  62325. componentType: 'graphic',
  62326. componentIndex: graphicModel.componentIndex,
  62327. name: el.name
  62328. };
  62329. }
  62330. // `elOption.info` enables user to mount some info on
  62331. // elements and use them in event handlers.
  62332. if (eventData) {
  62333. eventData.info = el.info;
  62334. }
  62335. }
  62336. /*
  62337. * Licensed to the Apache Software Foundation (ASF) under one
  62338. * or more contributor license agreements. See the NOTICE file
  62339. * distributed with this work for additional information
  62340. * regarding copyright ownership. The ASF licenses this file
  62341. * to you under the Apache License, Version 2.0 (the
  62342. * "License"); you may not use this file except in compliance
  62343. * with the License. You may obtain a copy of the License at
  62344. *
  62345. * http://www.apache.org/licenses/LICENSE-2.0
  62346. *
  62347. * Unless required by applicable law or agreed to in writing,
  62348. * software distributed under the License is distributed on an
  62349. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62350. * KIND, either express or implied. See the License for the
  62351. * specific language governing permissions and limitations
  62352. * under the License.
  62353. */
  62354. /*
  62355. * Licensed to the Apache Software Foundation (ASF) under one
  62356. * or more contributor license agreements. See the NOTICE file
  62357. * distributed with this work for additional information
  62358. * regarding copyright ownership. The ASF licenses this file
  62359. * to you under the Apache License, Version 2.0 (the
  62360. * "License"); you may not use this file except in compliance
  62361. * with the License. You may obtain a copy of the License at
  62362. *
  62363. * http://www.apache.org/licenses/LICENSE-2.0
  62364. *
  62365. * Unless required by applicable law or agreed to in writing,
  62366. * software distributed under the License is distributed on an
  62367. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62368. * KIND, either express or implied. See the License for the
  62369. * specific language governing permissions and limitations
  62370. * under the License.
  62371. */
  62372. var LegendModel = extendComponentModel({
  62373. type: 'legend.plain',
  62374. dependencies: ['series'],
  62375. layoutMode: {
  62376. type: 'box',
  62377. // legend.width/height are maxWidth/maxHeight actually,
  62378. // whereas realy width/height is calculated by its content.
  62379. // (Setting {left: 10, right: 10} does not make sense).
  62380. // So consider the case:
  62381. // `setOption({legend: {left: 10});`
  62382. // then `setOption({legend: {right: 10});`
  62383. // The previous `left` should be cleared by setting `ignoreSize`.
  62384. ignoreSize: true
  62385. },
  62386. init: function (option, parentModel, ecModel) {
  62387. this.mergeDefaultAndTheme(option, ecModel);
  62388. option.selected = option.selected || {};
  62389. },
  62390. mergeOption: function (option) {
  62391. LegendModel.superCall(this, 'mergeOption', option);
  62392. },
  62393. optionUpdated: function () {
  62394. this._updateData(this.ecModel);
  62395. var legendData = this._data;
  62396. // If selectedMode is single, try to select one
  62397. if (legendData[0] && this.get('selectedMode') === 'single') {
  62398. var hasSelected = false;
  62399. // If has any selected in option.selected
  62400. for (var i = 0; i < legendData.length; i++) {
  62401. var name = legendData[i].get('name');
  62402. if (this.isSelected(name)) {
  62403. // Force to unselect others
  62404. this.select(name);
  62405. hasSelected = true;
  62406. break;
  62407. }
  62408. }
  62409. // Try select the first if selectedMode is single
  62410. !hasSelected && this.select(legendData[0].get('name'));
  62411. }
  62412. },
  62413. _updateData: function (ecModel) {
  62414. var potentialData = [];
  62415. var availableNames = [];
  62416. ecModel.eachRawSeries(function (seriesModel) {
  62417. var seriesName = seriesModel.name;
  62418. availableNames.push(seriesName);
  62419. var isPotential;
  62420. if (seriesModel.legendDataProvider) {
  62421. var data = seriesModel.legendDataProvider();
  62422. var names = data.mapArray(data.getName);
  62423. if (!ecModel.isSeriesFiltered(seriesModel)) {
  62424. availableNames = availableNames.concat(names);
  62425. }
  62426. if (names.length) {
  62427. potentialData = potentialData.concat(names);
  62428. }
  62429. else {
  62430. isPotential = true;
  62431. }
  62432. }
  62433. else {
  62434. isPotential = true;
  62435. }
  62436. if (isPotential && isNameSpecified(seriesModel)) {
  62437. potentialData.push(seriesModel.name);
  62438. }
  62439. });
  62440. /**
  62441. * @type {Array.<string>}
  62442. * @private
  62443. */
  62444. this._availableNames = availableNames;
  62445. // If legend.data not specified in option, use availableNames as data,
  62446. // which is convinient for user preparing option.
  62447. var rawData = this.get('data') || potentialData;
  62448. var legendData = map(rawData, function (dataItem) {
  62449. // Can be string or number
  62450. if (typeof dataItem === 'string' || typeof dataItem === 'number') {
  62451. dataItem = {
  62452. name: dataItem
  62453. };
  62454. }
  62455. return new Model(dataItem, this, this.ecModel);
  62456. }, this);
  62457. /**
  62458. * @type {Array.<module:echarts/model/Model>}
  62459. * @private
  62460. */
  62461. this._data = legendData;
  62462. },
  62463. /**
  62464. * @return {Array.<module:echarts/model/Model>}
  62465. */
  62466. getData: function () {
  62467. return this._data;
  62468. },
  62469. /**
  62470. * @param {string} name
  62471. */
  62472. select: function (name) {
  62473. var selected = this.option.selected;
  62474. var selectedMode = this.get('selectedMode');
  62475. if (selectedMode === 'single') {
  62476. var data = this._data;
  62477. each$1(data, function (dataItem) {
  62478. selected[dataItem.get('name')] = false;
  62479. });
  62480. }
  62481. selected[name] = true;
  62482. },
  62483. /**
  62484. * @param {string} name
  62485. */
  62486. unSelect: function (name) {
  62487. if (this.get('selectedMode') !== 'single') {
  62488. this.option.selected[name] = false;
  62489. }
  62490. },
  62491. /**
  62492. * @param {string} name
  62493. */
  62494. toggleSelected: function (name) {
  62495. var selected = this.option.selected;
  62496. // Default is true
  62497. if (!selected.hasOwnProperty(name)) {
  62498. selected[name] = true;
  62499. }
  62500. this[selected[name] ? 'unSelect' : 'select'](name);
  62501. },
  62502. /**
  62503. * @param {string} name
  62504. */
  62505. isSelected: function (name) {
  62506. var selected = this.option.selected;
  62507. return !(selected.hasOwnProperty(name) && !selected[name])
  62508. && indexOf(this._availableNames, name) >= 0;
  62509. },
  62510. defaultOption: {
  62511. // 一级层叠
  62512. zlevel: 0,
  62513. // 二级层叠
  62514. z: 4,
  62515. show: true,
  62516. // 布局方式,默认为水平布局,可选为:
  62517. // 'horizontal' | 'vertical'
  62518. orient: 'horizontal',
  62519. left: 'center',
  62520. // right: 'center',
  62521. top: 0,
  62522. // bottom: null,
  62523. // 水平对齐
  62524. // 'auto' | 'left' | 'right'
  62525. // 默认为 'auto', 根据 x 的位置判断是左对齐还是右对齐
  62526. align: 'auto',
  62527. backgroundColor: 'rgba(0,0,0,0)',
  62528. // 图例边框颜色
  62529. borderColor: '#ccc',
  62530. borderRadius: 0,
  62531. // 图例边框线宽,单位px,默认为0(无边框)
  62532. borderWidth: 0,
  62533. // 图例内边距,单位px,默认各方向内边距为5,
  62534. // 接受数组分别设定上右下左边距,同css
  62535. padding: 5,
  62536. // 各个item之间的间隔,单位px,默认为10,
  62537. // 横向布局时为水平间隔,纵向布局时为纵向间隔
  62538. itemGap: 10,
  62539. // 图例图形宽度
  62540. itemWidth: 25,
  62541. // 图例图形高度
  62542. itemHeight: 14,
  62543. // 图例关闭时候的颜色
  62544. inactiveColor: '#ccc',
  62545. textStyle: {
  62546. // 图例文字颜色
  62547. color: '#333'
  62548. },
  62549. // formatter: '',
  62550. // 选择模式,默认开启图例开关
  62551. selectedMode: true,
  62552. // 配置默认选中状态,可配合LEGEND.SELECTED事件做动态数据载入
  62553. // selected: null,
  62554. // 图例内容(详见legend.data,数组中每一项代表一个item
  62555. // data: [],
  62556. // Tooltip 相关配置
  62557. tooltip: {
  62558. show: false
  62559. }
  62560. }
  62561. });
  62562. /*
  62563. * Licensed to the Apache Software Foundation (ASF) under one
  62564. * or more contributor license agreements. See the NOTICE file
  62565. * distributed with this work for additional information
  62566. * regarding copyright ownership. The ASF licenses this file
  62567. * to you under the Apache License, Version 2.0 (the
  62568. * "License"); you may not use this file except in compliance
  62569. * with the License. You may obtain a copy of the License at
  62570. *
  62571. * http://www.apache.org/licenses/LICENSE-2.0
  62572. *
  62573. * Unless required by applicable law or agreed to in writing,
  62574. * software distributed under the License is distributed on an
  62575. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62576. * KIND, either express or implied. See the License for the
  62577. * specific language governing permissions and limitations
  62578. * under the License.
  62579. */
  62580. function legendSelectActionHandler(methodName, payload, ecModel) {
  62581. var selectedMap = {};
  62582. var isToggleSelect = methodName === 'toggleSelected';
  62583. var isSelected;
  62584. // Update all legend components
  62585. ecModel.eachComponent('legend', function (legendModel) {
  62586. if (isToggleSelect && isSelected != null) {
  62587. // Force other legend has same selected status
  62588. // Or the first is toggled to true and other are toggled to false
  62589. // In the case one legend has some item unSelected in option. And if other legend
  62590. // doesn't has the item, they will assume it is selected.
  62591. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  62592. }
  62593. else {
  62594. legendModel[methodName](payload.name);
  62595. isSelected = legendModel.isSelected(payload.name);
  62596. }
  62597. var legendData = legendModel.getData();
  62598. each$1(legendData, function (model) {
  62599. var name = model.get('name');
  62600. // Wrap element
  62601. if (name === '\n' || name === '') {
  62602. return;
  62603. }
  62604. var isItemSelected = legendModel.isSelected(name);
  62605. if (selectedMap.hasOwnProperty(name)) {
  62606. // Unselected if any legend is unselected
  62607. selectedMap[name] = selectedMap[name] && isItemSelected;
  62608. }
  62609. else {
  62610. selectedMap[name] = isItemSelected;
  62611. }
  62612. });
  62613. });
  62614. // Return the event explicitly
  62615. return {
  62616. name: payload.name,
  62617. selected: selectedMap
  62618. };
  62619. }
  62620. /**
  62621. * @event legendToggleSelect
  62622. * @type {Object}
  62623. * @property {string} type 'legendToggleSelect'
  62624. * @property {string} [from]
  62625. * @property {string} name Series name or data item name
  62626. */
  62627. registerAction(
  62628. 'legendToggleSelect', 'legendselectchanged',
  62629. curry(legendSelectActionHandler, 'toggleSelected')
  62630. );
  62631. /**
  62632. * @event legendSelect
  62633. * @type {Object}
  62634. * @property {string} type 'legendSelect'
  62635. * @property {string} name Series name or data item name
  62636. */
  62637. registerAction(
  62638. 'legendSelect', 'legendselected',
  62639. curry(legendSelectActionHandler, 'select')
  62640. );
  62641. /**
  62642. * @event legendUnSelect
  62643. * @type {Object}
  62644. * @property {string} type 'legendUnSelect'
  62645. * @property {string} name Series name or data item name
  62646. */
  62647. registerAction(
  62648. 'legendUnSelect', 'legendunselected',
  62649. curry(legendSelectActionHandler, 'unSelect')
  62650. );
  62651. /*
  62652. * Licensed to the Apache Software Foundation (ASF) under one
  62653. * or more contributor license agreements. See the NOTICE file
  62654. * distributed with this work for additional information
  62655. * regarding copyright ownership. The ASF licenses this file
  62656. * to you under the Apache License, Version 2.0 (the
  62657. * "License"); you may not use this file except in compliance
  62658. * with the License. You may obtain a copy of the License at
  62659. *
  62660. * http://www.apache.org/licenses/LICENSE-2.0
  62661. *
  62662. * Unless required by applicable law or agreed to in writing,
  62663. * software distributed under the License is distributed on an
  62664. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62665. * KIND, either express or implied. See the License for the
  62666. * specific language governing permissions and limitations
  62667. * under the License.
  62668. */
  62669. /**
  62670. * Layout list like component.
  62671. * It will box layout each items in group of component and then position the whole group in the viewport
  62672. * @param {module:zrender/group/Group} group
  62673. * @param {module:echarts/model/Component} componentModel
  62674. * @param {module:echarts/ExtensionAPI}
  62675. */
  62676. function layout$3(group, componentModel, api) {
  62677. var boxLayoutParams = componentModel.getBoxLayoutParams();
  62678. var padding = componentModel.get('padding');
  62679. var viewportSize = {width: api.getWidth(), height: api.getHeight()};
  62680. var rect = getLayoutRect(
  62681. boxLayoutParams,
  62682. viewportSize,
  62683. padding
  62684. );
  62685. box(
  62686. componentModel.get('orient'),
  62687. group,
  62688. componentModel.get('itemGap'),
  62689. rect.width,
  62690. rect.height
  62691. );
  62692. positionElement(
  62693. group,
  62694. boxLayoutParams,
  62695. viewportSize,
  62696. padding
  62697. );
  62698. }
  62699. function makeBackground(rect, componentModel) {
  62700. var padding = normalizeCssArray$1(
  62701. componentModel.get('padding')
  62702. );
  62703. var style = componentModel.getItemStyle(['color', 'opacity']);
  62704. style.fill = componentModel.get('backgroundColor');
  62705. var rect = new Rect({
  62706. shape: {
  62707. x: rect.x - padding[3],
  62708. y: rect.y - padding[0],
  62709. width: rect.width + padding[1] + padding[3],
  62710. height: rect.height + padding[0] + padding[2],
  62711. r: componentModel.get('borderRadius')
  62712. },
  62713. style: style,
  62714. silent: true,
  62715. z2: -1
  62716. });
  62717. // FIXME
  62718. // `subPixelOptimizeRect` may bring some gap between edge of viewpart
  62719. // and background rect when setting like `left: 0`, `top: 0`.
  62720. // graphic.subPixelOptimizeRect(rect);
  62721. return rect;
  62722. }
  62723. /*
  62724. * Licensed to the Apache Software Foundation (ASF) under one
  62725. * or more contributor license agreements. See the NOTICE file
  62726. * distributed with this work for additional information
  62727. * regarding copyright ownership. The ASF licenses this file
  62728. * to you under the Apache License, Version 2.0 (the
  62729. * "License"); you may not use this file except in compliance
  62730. * with the License. You may obtain a copy of the License at
  62731. *
  62732. * http://www.apache.org/licenses/LICENSE-2.0
  62733. *
  62734. * Unless required by applicable law or agreed to in writing,
  62735. * software distributed under the License is distributed on an
  62736. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62737. * KIND, either express or implied. See the License for the
  62738. * specific language governing permissions and limitations
  62739. * under the License.
  62740. */
  62741. var curry$4 = curry;
  62742. var each$16 = each$1;
  62743. var Group$3 = Group;
  62744. var LegendView = extendComponentView({
  62745. type: 'legend.plain',
  62746. newlineDisabled: false,
  62747. /**
  62748. * @override
  62749. */
  62750. init: function () {
  62751. /**
  62752. * @private
  62753. * @type {module:zrender/container/Group}
  62754. */
  62755. this.group.add(this._contentGroup = new Group$3());
  62756. /**
  62757. * @private
  62758. * @type {module:zrender/Element}
  62759. */
  62760. this._backgroundEl;
  62761. /**
  62762. * If first rendering, `contentGroup.position` is [0, 0], which
  62763. * does not make sense and may cause unexepcted animation if adopted.
  62764. * @private
  62765. * @type {boolean}
  62766. */
  62767. this._isFirstRender = true;
  62768. },
  62769. /**
  62770. * @protected
  62771. */
  62772. getContentGroup: function () {
  62773. return this._contentGroup;
  62774. },
  62775. /**
  62776. * @override
  62777. */
  62778. render: function (legendModel, ecModel, api) {
  62779. var isFirstRender = this._isFirstRender;
  62780. this._isFirstRender = false;
  62781. this.resetInner();
  62782. if (!legendModel.get('show', true)) {
  62783. return;
  62784. }
  62785. var itemAlign = legendModel.get('align');
  62786. if (!itemAlign || itemAlign === 'auto') {
  62787. itemAlign = (
  62788. legendModel.get('left') === 'right'
  62789. && legendModel.get('orient') === 'vertical'
  62790. ) ? 'right' : 'left';
  62791. }
  62792. this.renderInner(itemAlign, legendModel, ecModel, api);
  62793. // Perform layout.
  62794. var positionInfo = legendModel.getBoxLayoutParams();
  62795. var viewportSize = {width: api.getWidth(), height: api.getHeight()};
  62796. var padding = legendModel.get('padding');
  62797. var maxSize = getLayoutRect(positionInfo, viewportSize, padding);
  62798. var mainRect = this.layoutInner(legendModel, itemAlign, maxSize, isFirstRender);
  62799. // Place mainGroup, based on the calculated `mainRect`.
  62800. var layoutRect = getLayoutRect(
  62801. defaults({width: mainRect.width, height: mainRect.height}, positionInfo),
  62802. viewportSize,
  62803. padding
  62804. );
  62805. this.group.attr('position', [layoutRect.x - mainRect.x, layoutRect.y - mainRect.y]);
  62806. // Render background after group is layout.
  62807. this.group.add(
  62808. this._backgroundEl = makeBackground(mainRect, legendModel)
  62809. );
  62810. },
  62811. /**
  62812. * @protected
  62813. */
  62814. resetInner: function () {
  62815. this.getContentGroup().removeAll();
  62816. this._backgroundEl && this.group.remove(this._backgroundEl);
  62817. },
  62818. /**
  62819. * @protected
  62820. */
  62821. renderInner: function (itemAlign, legendModel, ecModel, api) {
  62822. var contentGroup = this.getContentGroup();
  62823. var legendDrawnMap = createHashMap();
  62824. var selectMode = legendModel.get('selectedMode');
  62825. var excludeSeriesId = [];
  62826. ecModel.eachRawSeries(function (seriesModel) {
  62827. !seriesModel.get('legendHoverLink') && excludeSeriesId.push(seriesModel.id);
  62828. });
  62829. each$16(legendModel.getData(), function (itemModel, dataIndex) {
  62830. var name = itemModel.get('name');
  62831. // Use empty string or \n as a newline string
  62832. if (!this.newlineDisabled && (name === '' || name === '\n')) {
  62833. contentGroup.add(new Group$3({
  62834. newline: true
  62835. }));
  62836. return;
  62837. }
  62838. // Representitive series.
  62839. var seriesModel = ecModel.getSeriesByName(name)[0];
  62840. if (legendDrawnMap.get(name)) {
  62841. // Have been drawed
  62842. return;
  62843. }
  62844. // Series legend
  62845. if (seriesModel) {
  62846. var data = seriesModel.getData();
  62847. var color = data.getVisual('color');
  62848. // If color is a callback function
  62849. if (typeof color === 'function') {
  62850. // Use the first data
  62851. color = color(seriesModel.getDataParams(0));
  62852. }
  62853. // Using rect symbol defaultly
  62854. var legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
  62855. var symbolType = data.getVisual('symbol');
  62856. var itemGroup = this._createItem(
  62857. name, dataIndex, itemModel, legendModel,
  62858. legendSymbolType, symbolType,
  62859. itemAlign, color,
  62860. selectMode
  62861. );
  62862. itemGroup.on('click', curry$4(dispatchSelectAction, name, api))
  62863. .on('mouseover', curry$4(dispatchHighlightAction, seriesModel.name, null, api, excludeSeriesId))
  62864. .on('mouseout', curry$4(dispatchDownplayAction, seriesModel.name, null, api, excludeSeriesId));
  62865. legendDrawnMap.set(name, true);
  62866. }
  62867. else {
  62868. // Data legend of pie, funnel
  62869. ecModel.eachRawSeries(function (seriesModel) {
  62870. // In case multiple series has same data name
  62871. if (legendDrawnMap.get(name)) {
  62872. return;
  62873. }
  62874. if (seriesModel.legendDataProvider) {
  62875. var data = seriesModel.legendDataProvider();
  62876. var idx = data.indexOfName(name);
  62877. if (idx < 0) {
  62878. return;
  62879. }
  62880. var color = data.getItemVisual(idx, 'color');
  62881. var legendSymbolType = 'roundRect';
  62882. var itemGroup = this._createItem(
  62883. name, dataIndex, itemModel, legendModel,
  62884. legendSymbolType, null,
  62885. itemAlign, color,
  62886. selectMode
  62887. );
  62888. // FIXME: consider different series has items with the same name.
  62889. itemGroup.on('click', curry$4(dispatchSelectAction, name, api))
  62890. // Should not specify the series name, consider legend controls
  62891. // more than one pie series.
  62892. .on('mouseover', curry$4(dispatchHighlightAction, null, name, api, excludeSeriesId))
  62893. .on('mouseout', curry$4(dispatchDownplayAction, null, name, api, excludeSeriesId));
  62894. legendDrawnMap.set(name, true);
  62895. }
  62896. }, this);
  62897. }
  62898. if (__DEV__) {
  62899. if (!legendDrawnMap.get(name)) {
  62900. console.warn(
  62901. name + ' series not exists. Legend data should be same with series name or data name.'
  62902. );
  62903. }
  62904. }
  62905. }, this);
  62906. },
  62907. _createItem: function (
  62908. name, dataIndex, itemModel, legendModel,
  62909. legendSymbolType, symbolType,
  62910. itemAlign, color, selectMode
  62911. ) {
  62912. var itemWidth = legendModel.get('itemWidth');
  62913. var itemHeight = legendModel.get('itemHeight');
  62914. var inactiveColor = legendModel.get('inactiveColor');
  62915. var symbolKeepAspect = legendModel.get('symbolKeepAspect');
  62916. var isSelected = legendModel.isSelected(name);
  62917. var itemGroup = new Group$3();
  62918. var textStyleModel = itemModel.getModel('textStyle');
  62919. var itemIcon = itemModel.get('icon');
  62920. var tooltipModel = itemModel.getModel('tooltip');
  62921. var legendGlobalTooltipModel = tooltipModel.parentModel;
  62922. // Use user given icon first
  62923. legendSymbolType = itemIcon || legendSymbolType;
  62924. itemGroup.add(createSymbol(
  62925. legendSymbolType,
  62926. 0,
  62927. 0,
  62928. itemWidth,
  62929. itemHeight,
  62930. isSelected ? color : inactiveColor,
  62931. // symbolKeepAspect default true for legend
  62932. symbolKeepAspect == null ? true : symbolKeepAspect
  62933. ));
  62934. // Compose symbols
  62935. // PENDING
  62936. if (!itemIcon && symbolType
  62937. // At least show one symbol, can't be all none
  62938. && ((symbolType !== legendSymbolType) || symbolType === 'none')
  62939. ) {
  62940. var size = itemHeight * 0.8;
  62941. if (symbolType === 'none') {
  62942. symbolType = 'circle';
  62943. }
  62944. // Put symbol in the center
  62945. itemGroup.add(createSymbol(
  62946. symbolType,
  62947. (itemWidth - size) / 2,
  62948. (itemHeight - size) / 2,
  62949. size,
  62950. size,
  62951. isSelected ? color : inactiveColor,
  62952. // symbolKeepAspect default true for legend
  62953. symbolKeepAspect == null ? true : symbolKeepAspect
  62954. ));
  62955. }
  62956. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  62957. var textAlign = itemAlign;
  62958. var formatter = legendModel.get('formatter');
  62959. var content = name;
  62960. if (typeof formatter === 'string' && formatter) {
  62961. content = formatter.replace('{name}', name != null ? name : '');
  62962. }
  62963. else if (typeof formatter === 'function') {
  62964. content = formatter(name);
  62965. }
  62966. itemGroup.add(new Text({
  62967. style: setTextStyle({}, textStyleModel, {
  62968. text: content,
  62969. x: textX,
  62970. y: itemHeight / 2,
  62971. textFill: isSelected ? textStyleModel.getTextColor() : inactiveColor,
  62972. textAlign: textAlign,
  62973. textVerticalAlign: 'middle'
  62974. })
  62975. }));
  62976. // Add a invisible rect to increase the area of mouse hover
  62977. var hitRect = new Rect({
  62978. shape: itemGroup.getBoundingRect(),
  62979. invisible: true,
  62980. tooltip: tooltipModel.get('show') ? extend({
  62981. content: name,
  62982. // Defaul formatter
  62983. formatter: legendGlobalTooltipModel.get('formatter', true) || function () {
  62984. return name;
  62985. },
  62986. formatterParams: {
  62987. componentType: 'legend',
  62988. legendIndex: legendModel.componentIndex,
  62989. name: name,
  62990. $vars: ['name']
  62991. }
  62992. }, tooltipModel.option) : null
  62993. });
  62994. itemGroup.add(hitRect);
  62995. itemGroup.eachChild(function (child) {
  62996. child.silent = true;
  62997. });
  62998. hitRect.silent = !selectMode;
  62999. this.getContentGroup().add(itemGroup);
  63000. setHoverStyle(itemGroup);
  63001. itemGroup.__legendDataIndex = dataIndex;
  63002. return itemGroup;
  63003. },
  63004. /**
  63005. * @protected
  63006. */
  63007. layoutInner: function (legendModel, itemAlign, maxSize) {
  63008. var contentGroup = this.getContentGroup();
  63009. // Place items in contentGroup.
  63010. box(
  63011. legendModel.get('orient'),
  63012. contentGroup,
  63013. legendModel.get('itemGap'),
  63014. maxSize.width,
  63015. maxSize.height
  63016. );
  63017. var contentRect = contentGroup.getBoundingRect();
  63018. contentGroup.attr('position', [-contentRect.x, -contentRect.y]);
  63019. return this.group.getBoundingRect();
  63020. },
  63021. /**
  63022. * @protected
  63023. */
  63024. remove: function () {
  63025. this.getContentGroup().removeAll();
  63026. this._isFirstRender = true;
  63027. }
  63028. });
  63029. function dispatchSelectAction(name, api) {
  63030. api.dispatchAction({
  63031. type: 'legendToggleSelect',
  63032. name: name
  63033. });
  63034. }
  63035. function dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId) {
  63036. // If element hover will move to a hoverLayer.
  63037. var el = api.getZr().storage.getDisplayList()[0];
  63038. if (!(el && el.useHoverLayer)) {
  63039. api.dispatchAction({
  63040. type: 'highlight',
  63041. seriesName: seriesName,
  63042. name: dataName,
  63043. excludeSeriesId: excludeSeriesId
  63044. });
  63045. }
  63046. }
  63047. function dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId) {
  63048. // If element hover will move to a hoverLayer.
  63049. var el = api.getZr().storage.getDisplayList()[0];
  63050. if (!(el && el.useHoverLayer)) {
  63051. api.dispatchAction({
  63052. type: 'downplay',
  63053. seriesName: seriesName,
  63054. name: dataName,
  63055. excludeSeriesId: excludeSeriesId
  63056. });
  63057. }
  63058. }
  63059. /*
  63060. * Licensed to the Apache Software Foundation (ASF) under one
  63061. * or more contributor license agreements. See the NOTICE file
  63062. * distributed with this work for additional information
  63063. * regarding copyright ownership. The ASF licenses this file
  63064. * to you under the Apache License, Version 2.0 (the
  63065. * "License"); you may not use this file except in compliance
  63066. * with the License. You may obtain a copy of the License at
  63067. *
  63068. * http://www.apache.org/licenses/LICENSE-2.0
  63069. *
  63070. * Unless required by applicable law or agreed to in writing,
  63071. * software distributed under the License is distributed on an
  63072. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63073. * KIND, either express or implied. See the License for the
  63074. * specific language governing permissions and limitations
  63075. * under the License.
  63076. */
  63077. var legendFilter = function (ecModel) {
  63078. var legendModels = ecModel.findComponents({
  63079. mainType: 'legend'
  63080. });
  63081. if (legendModels && legendModels.length) {
  63082. ecModel.filterSeries(function (series) {
  63083. // If in any legend component the status is not selected.
  63084. // Because in legend series is assumed selected when it is not in the legend data.
  63085. for (var i = 0; i < legendModels.length; i++) {
  63086. if (!legendModels[i].isSelected(series.name)) {
  63087. return false;
  63088. }
  63089. }
  63090. return true;
  63091. });
  63092. }
  63093. };
  63094. /*
  63095. * Licensed to the Apache Software Foundation (ASF) under one
  63096. * or more contributor license agreements. See the NOTICE file
  63097. * distributed with this work for additional information
  63098. * regarding copyright ownership. The ASF licenses this file
  63099. * to you under the Apache License, Version 2.0 (the
  63100. * "License"); you may not use this file except in compliance
  63101. * with the License. You may obtain a copy of the License at
  63102. *
  63103. * http://www.apache.org/licenses/LICENSE-2.0
  63104. *
  63105. * Unless required by applicable law or agreed to in writing,
  63106. * software distributed under the License is distributed on an
  63107. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63108. * KIND, either express or implied. See the License for the
  63109. * specific language governing permissions and limitations
  63110. * under the License.
  63111. */
  63112. // Do not contain scrollable legend, for sake of file size.
  63113. // Series Filter
  63114. registerProcessor(legendFilter);
  63115. ComponentModel.registerSubTypeDefaulter('legend', function () {
  63116. // Default 'plain' when no type specified.
  63117. return 'plain';
  63118. });
  63119. /*
  63120. * Licensed to the Apache Software Foundation (ASF) under one
  63121. * or more contributor license agreements. See the NOTICE file
  63122. * distributed with this work for additional information
  63123. * regarding copyright ownership. The ASF licenses this file
  63124. * to you under the Apache License, Version 2.0 (the
  63125. * "License"); you may not use this file except in compliance
  63126. * with the License. You may obtain a copy of the License at
  63127. *
  63128. * http://www.apache.org/licenses/LICENSE-2.0
  63129. *
  63130. * Unless required by applicable law or agreed to in writing,
  63131. * software distributed under the License is distributed on an
  63132. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63133. * KIND, either express or implied. See the License for the
  63134. * specific language governing permissions and limitations
  63135. * under the License.
  63136. */
  63137. var ScrollableLegendModel = LegendModel.extend({
  63138. type: 'legend.scroll',
  63139. /**
  63140. * @param {number} scrollDataIndex
  63141. */
  63142. setScrollDataIndex: function (scrollDataIndex) {
  63143. this.option.scrollDataIndex = scrollDataIndex;
  63144. },
  63145. defaultOption: {
  63146. scrollDataIndex: 0,
  63147. pageButtonItemGap: 5,
  63148. pageButtonGap: null,
  63149. pageButtonPosition: 'end', // 'start' or 'end'
  63150. pageFormatter: '{current}/{total}', // If null/undefined, do not show page.
  63151. pageIcons: {
  63152. horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
  63153. vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
  63154. },
  63155. pageIconColor: '#2f4554',
  63156. pageIconInactiveColor: '#aaa',
  63157. pageIconSize: 15, // Can be [10, 3], which represents [width, height]
  63158. pageTextStyle: {
  63159. color: '#333'
  63160. },
  63161. animationDurationUpdate: 800
  63162. },
  63163. /**
  63164. * @override
  63165. */
  63166. init: function (option, parentModel, ecModel, extraOpt) {
  63167. var inputPositionParams = getLayoutParams(option);
  63168. ScrollableLegendModel.superCall(this, 'init', option, parentModel, ecModel, extraOpt);
  63169. mergeAndNormalizeLayoutParams(this, option, inputPositionParams);
  63170. },
  63171. /**
  63172. * @override
  63173. */
  63174. mergeOption: function (option, extraOpt) {
  63175. ScrollableLegendModel.superCall(this, 'mergeOption', option, extraOpt);
  63176. mergeAndNormalizeLayoutParams(this, this.option, option);
  63177. },
  63178. getOrient: function () {
  63179. return this.get('orient') === 'vertical'
  63180. ? {index: 1, name: 'vertical'}
  63181. : {index: 0, name: 'horizontal'};
  63182. }
  63183. });
  63184. // Do not `ignoreSize` to enable setting {left: 10, right: 10}.
  63185. function mergeAndNormalizeLayoutParams(legendModel, target, raw) {
  63186. var orient = legendModel.getOrient();
  63187. var ignoreSize = [1, 1];
  63188. ignoreSize[orient.index] = 0;
  63189. mergeLayoutParam(target, raw, {
  63190. type: 'box', ignoreSize: ignoreSize
  63191. });
  63192. }
  63193. /*
  63194. * Licensed to the Apache Software Foundation (ASF) under one
  63195. * or more contributor license agreements. See the NOTICE file
  63196. * distributed with this work for additional information
  63197. * regarding copyright ownership. The ASF licenses this file
  63198. * to you under the Apache License, Version 2.0 (the
  63199. * "License"); you may not use this file except in compliance
  63200. * with the License. You may obtain a copy of the License at
  63201. *
  63202. * http://www.apache.org/licenses/LICENSE-2.0
  63203. *
  63204. * Unless required by applicable law or agreed to in writing,
  63205. * software distributed under the License is distributed on an
  63206. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63207. * KIND, either express or implied. See the License for the
  63208. * specific language governing permissions and limitations
  63209. * under the License.
  63210. */
  63211. /**
  63212. * Separate legend and scrollable legend to reduce package size.
  63213. */
  63214. var Group$4 = Group;
  63215. var WH$1 = ['width', 'height'];
  63216. var XY$1 = ['x', 'y'];
  63217. var ScrollableLegendView = LegendView.extend({
  63218. type: 'legend.scroll',
  63219. newlineDisabled: true,
  63220. init: function () {
  63221. ScrollableLegendView.superCall(this, 'init');
  63222. /**
  63223. * @private
  63224. * @type {number} For `scroll`.
  63225. */
  63226. this._currentIndex = 0;
  63227. /**
  63228. * @private
  63229. * @type {module:zrender/container/Group}
  63230. */
  63231. this.group.add(this._containerGroup = new Group$4());
  63232. this._containerGroup.add(this.getContentGroup());
  63233. /**
  63234. * @private
  63235. * @type {module:zrender/container/Group}
  63236. */
  63237. this.group.add(this._controllerGroup = new Group$4());
  63238. /**
  63239. *
  63240. * @private
  63241. */
  63242. this._showController;
  63243. },
  63244. /**
  63245. * @override
  63246. */
  63247. resetInner: function () {
  63248. ScrollableLegendView.superCall(this, 'resetInner');
  63249. this._controllerGroup.removeAll();
  63250. this._containerGroup.removeClipPath();
  63251. this._containerGroup.__rectSize = null;
  63252. },
  63253. /**
  63254. * @override
  63255. */
  63256. renderInner: function (itemAlign, legendModel, ecModel, api) {
  63257. var me = this;
  63258. // Render content items.
  63259. ScrollableLegendView.superCall(this, 'renderInner', itemAlign, legendModel, ecModel, api);
  63260. var controllerGroup = this._controllerGroup;
  63261. // FIXME: support be 'auto' adapt to size number text length,
  63262. // e.g., '3/12345' should not overlap with the control arrow button.
  63263. var pageIconSize = legendModel.get('pageIconSize', true);
  63264. if (!isArray(pageIconSize)) {
  63265. pageIconSize = [pageIconSize, pageIconSize];
  63266. }
  63267. createPageButton('pagePrev', 0);
  63268. var pageTextStyleModel = legendModel.getModel('pageTextStyle');
  63269. controllerGroup.add(new Text({
  63270. name: 'pageText',
  63271. style: {
  63272. textFill: pageTextStyleModel.getTextColor(),
  63273. font: pageTextStyleModel.getFont(),
  63274. textVerticalAlign: 'middle',
  63275. textAlign: 'center'
  63276. },
  63277. silent: true
  63278. }));
  63279. createPageButton('pageNext', 1);
  63280. function createPageButton(name, iconIdx) {
  63281. var pageDataIndexName = name + 'DataIndex';
  63282. var icon = createIcon(
  63283. legendModel.get('pageIcons', true)[legendModel.getOrient().name][iconIdx],
  63284. {
  63285. // Buttons will be created in each render, so we do not need
  63286. // to worry about avoiding using legendModel kept in scope.
  63287. onclick: bind(
  63288. me._pageGo, me, pageDataIndexName, legendModel, api
  63289. )
  63290. },
  63291. {
  63292. x: -pageIconSize[0] / 2,
  63293. y: -pageIconSize[1] / 2,
  63294. width: pageIconSize[0],
  63295. height: pageIconSize[1]
  63296. }
  63297. );
  63298. icon.name = name;
  63299. controllerGroup.add(icon);
  63300. }
  63301. },
  63302. /**
  63303. * @override
  63304. */
  63305. layoutInner: function (legendModel, itemAlign, maxSize, isFirstRender) {
  63306. var contentGroup = this.getContentGroup();
  63307. var containerGroup = this._containerGroup;
  63308. var controllerGroup = this._controllerGroup;
  63309. var orientIdx = legendModel.getOrient().index;
  63310. var wh = WH$1[orientIdx];
  63311. var hw = WH$1[1 - orientIdx];
  63312. var yx = XY$1[1 - orientIdx];
  63313. // Place items in contentGroup.
  63314. box(
  63315. legendModel.get('orient'),
  63316. contentGroup,
  63317. legendModel.get('itemGap'),
  63318. !orientIdx ? null : maxSize.width,
  63319. orientIdx ? null : maxSize.height
  63320. );
  63321. box(
  63322. // Buttons in controller are layout always horizontally.
  63323. 'horizontal',
  63324. controllerGroup,
  63325. legendModel.get('pageButtonItemGap', true)
  63326. );
  63327. var contentRect = contentGroup.getBoundingRect();
  63328. var controllerRect = controllerGroup.getBoundingRect();
  63329. var showController = this._showController = contentRect[wh] > maxSize[wh];
  63330. var contentPos = [-contentRect.x, -contentRect.y];
  63331. // Remain contentPos when scroll animation perfroming.
  63332. // If first rendering, `contentGroup.position` is [0, 0], which
  63333. // does not make sense and may cause unexepcted animation if adopted.
  63334. if (!isFirstRender) {
  63335. contentPos[orientIdx] = contentGroup.position[orientIdx];
  63336. }
  63337. // Layout container group based on 0.
  63338. var containerPos = [0, 0];
  63339. var controllerPos = [-controllerRect.x, -controllerRect.y];
  63340. var pageButtonGap = retrieve2(
  63341. legendModel.get('pageButtonGap', true), legendModel.get('itemGap', true)
  63342. );
  63343. // Place containerGroup and controllerGroup and contentGroup.
  63344. if (showController) {
  63345. var pageButtonPosition = legendModel.get('pageButtonPosition', true);
  63346. // controller is on the right / bottom.
  63347. if (pageButtonPosition === 'end') {
  63348. controllerPos[orientIdx] += maxSize[wh] - controllerRect[wh];
  63349. }
  63350. // controller is on the left / top.
  63351. else {
  63352. containerPos[orientIdx] += controllerRect[wh] + pageButtonGap;
  63353. }
  63354. }
  63355. // Always align controller to content as 'middle'.
  63356. controllerPos[1 - orientIdx] += contentRect[hw] / 2 - controllerRect[hw] / 2;
  63357. contentGroup.attr('position', contentPos);
  63358. containerGroup.attr('position', containerPos);
  63359. controllerGroup.attr('position', controllerPos);
  63360. // Calculate `mainRect` and set `clipPath`.
  63361. // mainRect should not be calculated by `this.group.getBoundingRect()`
  63362. // for sake of the overflow.
  63363. var mainRect = this.group.getBoundingRect();
  63364. var mainRect = {x: 0, y: 0};
  63365. // Consider content may be overflow (should be clipped).
  63366. mainRect[wh] = showController ? maxSize[wh] : contentRect[wh];
  63367. mainRect[hw] = Math.max(contentRect[hw], controllerRect[hw]);
  63368. // `containerRect[yx] + containerPos[1 - orientIdx]` is 0.
  63369. mainRect[yx] = Math.min(0, controllerRect[yx] + controllerPos[1 - orientIdx]);
  63370. containerGroup.__rectSize = maxSize[wh];
  63371. if (showController) {
  63372. var clipShape = {x: 0, y: 0};
  63373. clipShape[wh] = Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0);
  63374. clipShape[hw] = mainRect[hw];
  63375. containerGroup.setClipPath(new Rect({shape: clipShape}));
  63376. // Consider content may be larger than container, container rect
  63377. // can not be obtained from `containerGroup.getBoundingRect()`.
  63378. containerGroup.__rectSize = clipShape[wh];
  63379. }
  63380. else {
  63381. // Do not remove or ignore controller. Keep them set as place holders.
  63382. controllerGroup.eachChild(function (child) {
  63383. child.attr({invisible: true, silent: true});
  63384. });
  63385. }
  63386. // Content translate animation.
  63387. var pageInfo = this._getPageInfo(legendModel);
  63388. pageInfo.pageIndex != null && updateProps(
  63389. contentGroup,
  63390. {position: pageInfo.contentPosition},
  63391. // When switch from "show controller" to "not show controller", view should be
  63392. // updated immediately without animation, otherwise causes weird efffect.
  63393. showController ? legendModel : false
  63394. );
  63395. this._updatePageInfoView(legendModel, pageInfo);
  63396. return mainRect;
  63397. },
  63398. _pageGo: function (to, legendModel, api) {
  63399. var scrollDataIndex = this._getPageInfo(legendModel)[to];
  63400. scrollDataIndex != null && api.dispatchAction({
  63401. type: 'legendScroll',
  63402. scrollDataIndex: scrollDataIndex,
  63403. legendId: legendModel.id
  63404. });
  63405. },
  63406. _updatePageInfoView: function (legendModel, pageInfo) {
  63407. var controllerGroup = this._controllerGroup;
  63408. each$1(['pagePrev', 'pageNext'], function (name) {
  63409. var canJump = pageInfo[name + 'DataIndex'] != null;
  63410. var icon = controllerGroup.childOfName(name);
  63411. if (icon) {
  63412. icon.setStyle(
  63413. 'fill',
  63414. canJump
  63415. ? legendModel.get('pageIconColor', true)
  63416. : legendModel.get('pageIconInactiveColor', true)
  63417. );
  63418. icon.cursor = canJump ? 'pointer' : 'default';
  63419. }
  63420. });
  63421. var pageText = controllerGroup.childOfName('pageText');
  63422. var pageFormatter = legendModel.get('pageFormatter');
  63423. var pageIndex = pageInfo.pageIndex;
  63424. var current = pageIndex != null ? pageIndex + 1 : 0;
  63425. var total = pageInfo.pageCount;
  63426. pageText && pageFormatter && pageText.setStyle(
  63427. 'text',
  63428. isString(pageFormatter)
  63429. ? pageFormatter.replace('{current}', current).replace('{total}', total)
  63430. : pageFormatter({current: current, total: total})
  63431. );
  63432. },
  63433. /**
  63434. * @param {module:echarts/model/Model} legendModel
  63435. * @return {Object} {
  63436. * contentPosition: Array.<number>, null when data item not found.
  63437. * pageIndex: number, null when data item not found.
  63438. * pageCount: number, always be a number, can be 0.
  63439. * pagePrevDataIndex: number, null when no next page.
  63440. * pageNextDataIndex: number, null when no previous page.
  63441. * }
  63442. */
  63443. _getPageInfo: function (legendModel) {
  63444. var scrollDataIndex = legendModel.get('scrollDataIndex', true);
  63445. var contentGroup = this.getContentGroup();
  63446. var containerRectSize = this._containerGroup.__rectSize;
  63447. var orientIdx = legendModel.getOrient().index;
  63448. var wh = WH$1[orientIdx];
  63449. var xy = XY$1[orientIdx];
  63450. var targetItemIndex = this._findTargetItemIndex(scrollDataIndex);
  63451. var children = contentGroup.children();
  63452. var targetItem = children[targetItemIndex];
  63453. var itemCount = children.length;
  63454. var pCount = !itemCount ? 0 : 1;
  63455. var result = {
  63456. contentPosition: contentGroup.position.slice(),
  63457. pageCount: pCount,
  63458. pageIndex: pCount - 1,
  63459. pagePrevDataIndex: null,
  63460. pageNextDataIndex: null
  63461. };
  63462. if (!targetItem) {
  63463. return result;
  63464. }
  63465. var targetItemInfo = getItemInfo(targetItem);
  63466. result.contentPosition[orientIdx] = -targetItemInfo.s;
  63467. // Strategy:
  63468. // (1) Always align based on the left/top most item.
  63469. // (2) It is user-friendly that the last item shown in the
  63470. // current window is shown at the begining of next window.
  63471. // Otherwise if half of the last item is cut by the window,
  63472. // it will have no chance to display entirely.
  63473. // (3) Consider that item size probably be different, we
  63474. // have calculate pageIndex by size rather than item index,
  63475. // and we can not get page index directly by division.
  63476. // (4) The window is to narrow to contain more than
  63477. // one item, we should make sure that the page can be fliped.
  63478. for (var i = targetItemIndex + 1,
  63479. winStartItemInfo = targetItemInfo,
  63480. winEndItemInfo = targetItemInfo,
  63481. currItemInfo = null;
  63482. i <= itemCount;
  63483. ++i
  63484. ) {
  63485. currItemInfo = getItemInfo(children[i]);
  63486. if (
  63487. // Half of the last item is out of the window.
  63488. (!currItemInfo && winEndItemInfo.e > winStartItemInfo.s + containerRectSize)
  63489. // If the current item does not intersect with the window, the new page
  63490. // can be started at the current item or the last item.
  63491. || (currItemInfo && !intersect(currItemInfo, winStartItemInfo.s))
  63492. ) {
  63493. if (winEndItemInfo.i > winStartItemInfo.i) {
  63494. winStartItemInfo = winEndItemInfo;
  63495. }
  63496. else { // e.g., when page size is smaller than item size.
  63497. winStartItemInfo = currItemInfo;
  63498. }
  63499. if (winStartItemInfo) {
  63500. if (result.pageNextDataIndex == null) {
  63501. result.pageNextDataIndex = winStartItemInfo.i;
  63502. }
  63503. ++result.pageCount;
  63504. }
  63505. }
  63506. winEndItemInfo = currItemInfo;
  63507. }
  63508. for (var i = targetItemIndex - 1,
  63509. winStartItemInfo = targetItemInfo,
  63510. winEndItemInfo = targetItemInfo,
  63511. currItemInfo = null;
  63512. i >= -1;
  63513. --i
  63514. ) {
  63515. currItemInfo = getItemInfo(children[i]);
  63516. if (
  63517. // If the the end item does not intersect with the window started
  63518. // from the current item, a page can be settled.
  63519. (!currItemInfo || !intersect(winEndItemInfo, currItemInfo.s))
  63520. // e.g., when page size is smaller than item size.
  63521. && winStartItemInfo.i < winEndItemInfo.i
  63522. ) {
  63523. winEndItemInfo = winStartItemInfo;
  63524. if (result.pagePrevDataIndex == null) {
  63525. result.pagePrevDataIndex = winStartItemInfo.i;
  63526. }
  63527. ++result.pageCount;
  63528. ++result.pageIndex;
  63529. }
  63530. winStartItemInfo = currItemInfo;
  63531. }
  63532. return result;
  63533. function getItemInfo(el) {
  63534. if (el) {
  63535. var itemRect = el.getBoundingRect();
  63536. var start = itemRect[xy] + el.position[orientIdx];
  63537. return {
  63538. s: start,
  63539. e: start + itemRect[wh],
  63540. i: el.__legendDataIndex
  63541. };
  63542. }
  63543. }
  63544. function intersect(itemInfo, winStart) {
  63545. return itemInfo.e >= winStart && itemInfo.s <= winStart + containerRectSize;
  63546. }
  63547. },
  63548. _findTargetItemIndex: function (targetDataIndex) {
  63549. var index;
  63550. var contentGroup = this.getContentGroup();
  63551. if (this._showController) {
  63552. contentGroup.eachChild(function (child, idx) {
  63553. if (child.__legendDataIndex === targetDataIndex) {
  63554. index = idx;
  63555. }
  63556. });
  63557. }
  63558. else {
  63559. index = 0;
  63560. }
  63561. return index;
  63562. }
  63563. });
  63564. /*
  63565. * Licensed to the Apache Software Foundation (ASF) under one
  63566. * or more contributor license agreements. See the NOTICE file
  63567. * distributed with this work for additional information
  63568. * regarding copyright ownership. The ASF licenses this file
  63569. * to you under the Apache License, Version 2.0 (the
  63570. * "License"); you may not use this file except in compliance
  63571. * with the License. You may obtain a copy of the License at
  63572. *
  63573. * http://www.apache.org/licenses/LICENSE-2.0
  63574. *
  63575. * Unless required by applicable law or agreed to in writing,
  63576. * software distributed under the License is distributed on an
  63577. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63578. * KIND, either express or implied. See the License for the
  63579. * specific language governing permissions and limitations
  63580. * under the License.
  63581. */
  63582. /**
  63583. * @event legendScroll
  63584. * @type {Object}
  63585. * @property {string} type 'legendScroll'
  63586. * @property {string} scrollDataIndex
  63587. */
  63588. registerAction(
  63589. 'legendScroll', 'legendscroll',
  63590. function (payload, ecModel) {
  63591. var scrollDataIndex = payload.scrollDataIndex;
  63592. scrollDataIndex != null && ecModel.eachComponent(
  63593. {mainType: 'legend', subType: 'scroll', query: payload},
  63594. function (legendModel) {
  63595. legendModel.setScrollDataIndex(scrollDataIndex);
  63596. }
  63597. );
  63598. }
  63599. );
  63600. /*
  63601. * Licensed to the Apache Software Foundation (ASF) under one
  63602. * or more contributor license agreements. See the NOTICE file
  63603. * distributed with this work for additional information
  63604. * regarding copyright ownership. The ASF licenses this file
  63605. * to you under the Apache License, Version 2.0 (the
  63606. * "License"); you may not use this file except in compliance
  63607. * with the License. You may obtain a copy of the License at
  63608. *
  63609. * http://www.apache.org/licenses/LICENSE-2.0
  63610. *
  63611. * Unless required by applicable law or agreed to in writing,
  63612. * software distributed under the License is distributed on an
  63613. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63614. * KIND, either express or implied. See the License for the
  63615. * specific language governing permissions and limitations
  63616. * under the License.
  63617. */
  63618. /**
  63619. * Legend component entry file8
  63620. */
  63621. /*
  63622. * Licensed to the Apache Software Foundation (ASF) under one
  63623. * or more contributor license agreements. See the NOTICE file
  63624. * distributed with this work for additional information
  63625. * regarding copyright ownership. The ASF licenses this file
  63626. * to you under the Apache License, Version 2.0 (the
  63627. * "License"); you may not use this file except in compliance
  63628. * with the License. You may obtain a copy of the License at
  63629. *
  63630. * http://www.apache.org/licenses/LICENSE-2.0
  63631. *
  63632. * Unless required by applicable law or agreed to in writing,
  63633. * software distributed under the License is distributed on an
  63634. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63635. * KIND, either express or implied. See the License for the
  63636. * specific language governing permissions and limitations
  63637. * under the License.
  63638. */
  63639. extendComponentModel({
  63640. type: 'tooltip',
  63641. dependencies: ['axisPointer'],
  63642. defaultOption: {
  63643. zlevel: 0,
  63644. z: 60,
  63645. show: true,
  63646. // tooltip主体内容
  63647. showContent: true,
  63648. // 'trigger' only works on coordinate system.
  63649. // 'item' | 'axis' | 'none'
  63650. trigger: 'item',
  63651. // 'click' | 'mousemove' | 'none'
  63652. triggerOn: 'mousemove|click',
  63653. alwaysShowContent: false,
  63654. displayMode: 'single', // 'single' | 'multipleByCoordSys'
  63655. renderMode: 'auto', // 'auto' | 'html' | 'richText'
  63656. // 'auto': use html by default, and use non-html if `document` is not defined
  63657. // 'html': use html for tooltip
  63658. // 'richText': use canvas, svg, and etc. for tooltip
  63659. // 位置 {Array} | {Function}
  63660. // position: null
  63661. // Consider triggered from axisPointer handle, verticalAlign should be 'middle'
  63662. // align: null,
  63663. // verticalAlign: null,
  63664. // 是否约束 content 在 viewRect 中。默认 false 是为了兼容以前版本。
  63665. confine: false,
  63666. // 内容格式器:{string}(Template) ¦ {Function}
  63667. // formatter: null
  63668. showDelay: 0,
  63669. // 隐藏延迟,单位ms
  63670. hideDelay: 100,
  63671. // 动画变换时间,单位s
  63672. transitionDuration: 0.4,
  63673. enterable: false,
  63674. // 提示背景颜色,默认为透明度为0.7的黑色
  63675. backgroundColor: 'rgba(50,50,50,0.7)',
  63676. // 提示边框颜色
  63677. borderColor: '#333',
  63678. // 提示边框圆角,单位px,默认为4
  63679. borderRadius: 4,
  63680. // 提示边框线宽,单位px,默认为0(无边框)
  63681. borderWidth: 0,
  63682. // 提示内边距,单位px,默认各方向内边距为5,
  63683. // 接受数组分别设定上右下左边距,同css
  63684. padding: 5,
  63685. // Extra css text
  63686. extraCssText: '',
  63687. // 坐标轴指示器,坐标轴触发有效
  63688. axisPointer: {
  63689. // 默认为直线
  63690. // 可选为:'line' | 'shadow' | 'cross'
  63691. type: 'line',
  63692. // type 为 line 的时候有效,指定 tooltip line 所在的轴,可选
  63693. // 可选 'x' | 'y' | 'angle' | 'radius' | 'auto'
  63694. // 默认 'auto',会选择类型为 category 的轴,对于双数值轴,笛卡尔坐标系会默认选择 x 轴
  63695. // 极坐标系会默认选择 angle 轴
  63696. axis: 'auto',
  63697. animation: 'auto',
  63698. animationDurationUpdate: 200,
  63699. animationEasingUpdate: 'exponentialOut',
  63700. crossStyle: {
  63701. color: '#999',
  63702. width: 1,
  63703. type: 'dashed',
  63704. // TODO formatter
  63705. textStyle: {}
  63706. }
  63707. // lineStyle and shadowStyle should not be specified here,
  63708. // otherwise it will always override those styles on option.axisPointer.
  63709. },
  63710. textStyle: {
  63711. color: '#fff',
  63712. fontSize: 14
  63713. }
  63714. }
  63715. });
  63716. /*
  63717. * Licensed to the Apache Software Foundation (ASF) under one
  63718. * or more contributor license agreements. See the NOTICE file
  63719. * distributed with this work for additional information
  63720. * regarding copyright ownership. The ASF licenses this file
  63721. * to you under the Apache License, Version 2.0 (the
  63722. * "License"); you may not use this file except in compliance
  63723. * with the License. You may obtain a copy of the License at
  63724. *
  63725. * http://www.apache.org/licenses/LICENSE-2.0
  63726. *
  63727. * Unless required by applicable law or agreed to in writing,
  63728. * software distributed under the License is distributed on an
  63729. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63730. * KIND, either express or implied. See the License for the
  63731. * specific language governing permissions and limitations
  63732. * under the License.
  63733. */
  63734. var each$18 = each$1;
  63735. var toCamelCase$1 = toCamelCase;
  63736. var vendors = ['', '-webkit-', '-moz-', '-o-'];
  63737. var gCssText = 'position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;';
  63738. /**
  63739. * @param {number} duration
  63740. * @return {string}
  63741. * @inner
  63742. */
  63743. function assembleTransition(duration) {
  63744. var transitionCurve = 'cubic-bezier(0.23, 1, 0.32, 1)';
  63745. var transitionText = 'left ' + duration + 's ' + transitionCurve + ','
  63746. + 'top ' + duration + 's ' + transitionCurve;
  63747. return map(vendors, function (vendorPrefix) {
  63748. return vendorPrefix + 'transition:' + transitionText;
  63749. }).join(';');
  63750. }
  63751. /**
  63752. * @param {Object} textStyle
  63753. * @return {string}
  63754. * @inner
  63755. */
  63756. function assembleFont(textStyleModel) {
  63757. var cssText = [];
  63758. var fontSize = textStyleModel.get('fontSize');
  63759. var color = textStyleModel.getTextColor();
  63760. color && cssText.push('color:' + color);
  63761. cssText.push('font:' + textStyleModel.getFont());
  63762. fontSize
  63763. && cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
  63764. each$18(['decoration', 'align'], function (name) {
  63765. var val = textStyleModel.get(name);
  63766. val && cssText.push('text-' + name + ':' + val);
  63767. });
  63768. return cssText.join(';');
  63769. }
  63770. /**
  63771. * @param {Object} tooltipModel
  63772. * @return {string}
  63773. * @inner
  63774. */
  63775. function assembleCssText(tooltipModel) {
  63776. var cssText = [];
  63777. var transitionDuration = tooltipModel.get('transitionDuration');
  63778. var backgroundColor = tooltipModel.get('backgroundColor');
  63779. var textStyleModel = tooltipModel.getModel('textStyle');
  63780. var padding = tooltipModel.get('padding');
  63781. // Animation transition. Do not animate when transitionDuration is 0.
  63782. transitionDuration
  63783. && cssText.push(assembleTransition(transitionDuration));
  63784. if (backgroundColor) {
  63785. if (env$1.canvasSupported) {
  63786. cssText.push('background-Color:' + backgroundColor);
  63787. }
  63788. else {
  63789. // for ie
  63790. cssText.push(
  63791. 'background-Color:#' + toHex(backgroundColor)
  63792. );
  63793. cssText.push('filter:alpha(opacity=70)');
  63794. }
  63795. }
  63796. // Border style
  63797. each$18(['width', 'color', 'radius'], function (name) {
  63798. var borderName = 'border-' + name;
  63799. var camelCase = toCamelCase$1(borderName);
  63800. var val = tooltipModel.get(camelCase);
  63801. val != null
  63802. && cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  63803. });
  63804. // Text style
  63805. cssText.push(assembleFont(textStyleModel));
  63806. // Padding
  63807. if (padding != null) {
  63808. cssText.push('padding:' + normalizeCssArray$1(padding).join('px ') + 'px');
  63809. }
  63810. return cssText.join(';') + ';';
  63811. }
  63812. /**
  63813. * @alias module:echarts/component/tooltip/TooltipContent
  63814. * @constructor
  63815. */
  63816. function TooltipContent(container, api) {
  63817. if (env$1.wxa) {
  63818. return null;
  63819. }
  63820. var el = document.createElement('div');
  63821. var zr = this._zr = api.getZr();
  63822. this.el = el;
  63823. this._x = api.getWidth() / 2;
  63824. this._y = api.getHeight() / 2;
  63825. container.appendChild(el);
  63826. this._container = container;
  63827. this._show = false;
  63828. /**
  63829. * @private
  63830. */
  63831. this._hideTimeout;
  63832. var self = this;
  63833. el.onmouseenter = function () {
  63834. // clear the timeout in hideLater and keep showing tooltip
  63835. if (self._enterable) {
  63836. clearTimeout(self._hideTimeout);
  63837. self._show = true;
  63838. }
  63839. self._inContent = true;
  63840. };
  63841. el.onmousemove = function (e) {
  63842. e = e || window.event;
  63843. if (!self._enterable) {
  63844. // Try trigger zrender event to avoid mouse
  63845. // in and out shape too frequently
  63846. var handler = zr.handler;
  63847. normalizeEvent(container, e, true);
  63848. handler.dispatch('mousemove', e);
  63849. }
  63850. };
  63851. el.onmouseleave = function () {
  63852. if (self._enterable) {
  63853. if (self._show) {
  63854. self.hideLater(self._hideDelay);
  63855. }
  63856. }
  63857. self._inContent = false;
  63858. };
  63859. }
  63860. TooltipContent.prototype = {
  63861. constructor: TooltipContent,
  63862. /**
  63863. * @private
  63864. * @type {boolean}
  63865. */
  63866. _enterable: true,
  63867. /**
  63868. * Update when tooltip is rendered
  63869. */
  63870. update: function () {
  63871. // FIXME
  63872. // Move this logic to ec main?
  63873. var container = this._container;
  63874. var stl = container.currentStyle
  63875. || document.defaultView.getComputedStyle(container);
  63876. var domStyle = container.style;
  63877. if (domStyle.position !== 'absolute' && stl.position !== 'absolute') {
  63878. domStyle.position = 'relative';
  63879. }
  63880. // Hide the tooltip
  63881. // PENDING
  63882. // this.hide();
  63883. },
  63884. show: function (tooltipModel) {
  63885. clearTimeout(this._hideTimeout);
  63886. var el = this.el;
  63887. el.style.cssText = gCssText + assembleCssText(tooltipModel)
  63888. // http://stackoverflow.com/questions/21125587/css3-transition-not-working-in-chrome-anymore
  63889. + ';left:' + this._x + 'px;top:' + this._y + 'px;'
  63890. + (tooltipModel.get('extraCssText') || '');
  63891. el.style.display = el.innerHTML ? 'block' : 'none';
  63892. // If mouse occsionally move over the tooltip, a mouseout event will be
  63893. // triggered by canvas, and cuase some unexpectable result like dragging
  63894. // stop, "unfocusAdjacency". Here `pointer-events: none` is used to solve
  63895. // it. Although it is not suppored by IE8~IE10, fortunately it is a rare
  63896. // scenario.
  63897. el.style.pointerEvents = this._enterable ? 'auto' : 'none';
  63898. this._show = true;
  63899. },
  63900. setContent: function (content) {
  63901. this.el.innerHTML = content == null ? '' : content;
  63902. },
  63903. setEnterable: function (enterable) {
  63904. this._enterable = enterable;
  63905. },
  63906. getSize: function () {
  63907. var el = this.el;
  63908. return [el.clientWidth, el.clientHeight];
  63909. },
  63910. moveTo: function (x, y) {
  63911. // xy should be based on canvas root. But tooltipContent is
  63912. // the sibling of canvas root. So padding of ec container
  63913. // should be considered here.
  63914. var zr = this._zr;
  63915. var viewportRootOffset;
  63916. if (zr && zr.painter && (viewportRootOffset = zr.painter.getViewportRootOffset())) {
  63917. x += viewportRootOffset.offsetLeft;
  63918. y += viewportRootOffset.offsetTop;
  63919. }
  63920. var style = this.el.style;
  63921. style.left = x + 'px';
  63922. style.top = y + 'px';
  63923. this._x = x;
  63924. this._y = y;
  63925. },
  63926. hide: function () {
  63927. this.el.style.display = 'none';
  63928. this._show = false;
  63929. },
  63930. hideLater: function (time) {
  63931. if (this._show && !(this._inContent && this._enterable)) {
  63932. if (time) {
  63933. this._hideDelay = time;
  63934. // Set show false to avoid invoke hideLater mutiple times
  63935. this._show = false;
  63936. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  63937. }
  63938. else {
  63939. this.hide();
  63940. }
  63941. }
  63942. },
  63943. isShow: function () {
  63944. return this._show;
  63945. },
  63946. getOuterSize: function () {
  63947. var width = this.el.clientWidth;
  63948. var height = this.el.clientHeight;
  63949. // Consider browser compatibility.
  63950. // IE8 does not support getComputedStyle.
  63951. if (document.defaultView && document.defaultView.getComputedStyle) {
  63952. var stl = document.defaultView.getComputedStyle(this.el);
  63953. if (stl) {
  63954. width += parseInt(stl.paddingLeft, 10) + parseInt(stl.paddingRight, 10)
  63955. + parseInt(stl.borderLeftWidth, 10) + parseInt(stl.borderRightWidth, 10);
  63956. height += parseInt(stl.paddingTop, 10) + parseInt(stl.paddingBottom, 10)
  63957. + parseInt(stl.borderTopWidth, 10) + parseInt(stl.borderBottomWidth, 10);
  63958. }
  63959. }
  63960. return {width: width, height: height};
  63961. }
  63962. };
  63963. /*
  63964. * Licensed to the Apache Software Foundation (ASF) under one
  63965. * or more contributor license agreements. See the NOTICE file
  63966. * distributed with this work for additional information
  63967. * regarding copyright ownership. The ASF licenses this file
  63968. * to you under the Apache License, Version 2.0 (the
  63969. * "License"); you may not use this file except in compliance
  63970. * with the License. You may obtain a copy of the License at
  63971. *
  63972. * http://www.apache.org/licenses/LICENSE-2.0
  63973. *
  63974. * Unless required by applicable law or agreed to in writing,
  63975. * software distributed under the License is distributed on an
  63976. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63977. * KIND, either express or implied. See the License for the
  63978. * specific language governing permissions and limitations
  63979. * under the License.
  63980. */
  63981. // import Group from 'zrender/src/container/Group';
  63982. /**
  63983. * @alias module:echarts/component/tooltip/TooltipRichContent
  63984. * @constructor
  63985. */
  63986. function TooltipRichContent(api) {
  63987. this._zr = api.getZr();
  63988. this._show = false;
  63989. /**
  63990. * @private
  63991. */
  63992. this._hideTimeout;
  63993. }
  63994. TooltipRichContent.prototype = {
  63995. constructor: TooltipRichContent,
  63996. /**
  63997. * @private
  63998. * @type {boolean}
  63999. */
  64000. _enterable: true,
  64001. /**
  64002. * Update when tooltip is rendered
  64003. */
  64004. update: function () {
  64005. // noop
  64006. },
  64007. show: function (tooltipModel) {
  64008. if (this._hideTimeout) {
  64009. clearTimeout(this._hideTimeout);
  64010. }
  64011. this.el.attr('show', true);
  64012. this._show = true;
  64013. },
  64014. /**
  64015. * Set tooltip content
  64016. *
  64017. * @param {string} content rich text string of content
  64018. * @param {Object} markerRich rich text style
  64019. * @param {Object} tooltipModel tooltip model
  64020. */
  64021. setContent: function (content, markerRich, tooltipModel) {
  64022. if (this.el) {
  64023. this._zr.remove(this.el);
  64024. }
  64025. var markers = {};
  64026. var text = content;
  64027. var prefix = '{marker';
  64028. var suffix = '|}';
  64029. var startId = text.indexOf(prefix);
  64030. while (startId >= 0) {
  64031. var endId = text.indexOf(suffix);
  64032. var name = text.substr(startId + prefix.length, endId - startId - prefix.length);
  64033. if (name.indexOf('sub') > -1) {
  64034. markers['marker' + name] = {
  64035. textWidth: 4,
  64036. textHeight: 4,
  64037. textBorderRadius: 2,
  64038. textBackgroundColor: markerRich[name],
  64039. // TODO: textOffset is not implemented for rich text
  64040. textOffset: [3, 0]
  64041. };
  64042. }
  64043. else {
  64044. markers['marker' + name] = {
  64045. textWidth: 10,
  64046. textHeight: 10,
  64047. textBorderRadius: 5,
  64048. textBackgroundColor: markerRich[name]
  64049. };
  64050. }
  64051. text = text.substr(endId + 1);
  64052. startId = text.indexOf('{marker');
  64053. }
  64054. this.el = new Text({
  64055. style: {
  64056. rich: markers,
  64057. text: content,
  64058. textLineHeight: 20,
  64059. textBackgroundColor: tooltipModel.get('backgroundColor'),
  64060. textBorderRadius: tooltipModel.get('borderRadius'),
  64061. textFill: tooltipModel.get('textStyle.color'),
  64062. textPadding: tooltipModel.get('padding')
  64063. },
  64064. z: tooltipModel.get('z')
  64065. });
  64066. this._zr.add(this.el);
  64067. var self = this;
  64068. this.el.on('mouseover', function () {
  64069. // clear the timeout in hideLater and keep showing tooltip
  64070. if (self._enterable) {
  64071. clearTimeout(self._hideTimeout);
  64072. self._show = true;
  64073. }
  64074. self._inContent = true;
  64075. });
  64076. this.el.on('mouseout', function () {
  64077. if (self._enterable) {
  64078. if (self._show) {
  64079. self.hideLater(self._hideDelay);
  64080. }
  64081. }
  64082. self._inContent = false;
  64083. });
  64084. },
  64085. setEnterable: function (enterable) {
  64086. this._enterable = enterable;
  64087. },
  64088. getSize: function () {
  64089. var bounding = this.el.getBoundingRect();
  64090. return [bounding.width, bounding.height];
  64091. },
  64092. moveTo: function (x, y) {
  64093. if (this.el) {
  64094. this.el.attr('position', [x, y]);
  64095. }
  64096. },
  64097. hide: function () {
  64098. this.el.hide();
  64099. this._show = false;
  64100. },
  64101. hideLater: function (time) {
  64102. if (this._show && !(this._inContent && this._enterable)) {
  64103. if (time) {
  64104. this._hideDelay = time;
  64105. // Set show false to avoid invoke hideLater mutiple times
  64106. this._show = false;
  64107. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  64108. }
  64109. else {
  64110. this.hide();
  64111. }
  64112. }
  64113. },
  64114. isShow: function () {
  64115. return this._show;
  64116. },
  64117. getOuterSize: function () {
  64118. return this.getSize();
  64119. }
  64120. };
  64121. /*
  64122. * Licensed to the Apache Software Foundation (ASF) under one
  64123. * or more contributor license agreements. See the NOTICE file
  64124. * distributed with this work for additional information
  64125. * regarding copyright ownership. The ASF licenses this file
  64126. * to you under the Apache License, Version 2.0 (the
  64127. * "License"); you may not use this file except in compliance
  64128. * with the License. You may obtain a copy of the License at
  64129. *
  64130. * http://www.apache.org/licenses/LICENSE-2.0
  64131. *
  64132. * Unless required by applicable law or agreed to in writing,
  64133. * software distributed under the License is distributed on an
  64134. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  64135. * KIND, either express or implied. See the License for the
  64136. * specific language governing permissions and limitations
  64137. * under the License.
  64138. */
  64139. var bind$3 = bind;
  64140. var each$17 = each$1;
  64141. var parsePercent$2 = parsePercent$1;
  64142. var proxyRect = new Rect({
  64143. shape: {x: -1, y: -1, width: 2, height: 2}
  64144. });
  64145. extendComponentView({
  64146. type: 'tooltip',
  64147. init: function (ecModel, api) {
  64148. if (env$1.node) {
  64149. return;
  64150. }
  64151. var tooltipModel = ecModel.getComponent('tooltip');
  64152. var renderMode = tooltipModel.get('renderMode');
  64153. this._renderMode = getTooltipRenderMode(renderMode);
  64154. var tooltipContent;
  64155. if (this._renderMode === 'html') {
  64156. tooltipContent = new TooltipContent(api.getDom(), api);
  64157. this._newLine = '<br/>';
  64158. }
  64159. else {
  64160. tooltipContent = new TooltipRichContent(api);
  64161. this._newLine = '\n';
  64162. }
  64163. this._tooltipContent = tooltipContent;
  64164. },
  64165. render: function (tooltipModel, ecModel, api) {
  64166. if (env$1.node) {
  64167. return;
  64168. }
  64169. // Reset
  64170. this.group.removeAll();
  64171. /**
  64172. * @private
  64173. * @type {module:echarts/component/tooltip/TooltipModel}
  64174. */
  64175. this._tooltipModel = tooltipModel;
  64176. /**
  64177. * @private
  64178. * @type {module:echarts/model/Global}
  64179. */
  64180. this._ecModel = ecModel;
  64181. /**
  64182. * @private
  64183. * @type {module:echarts/ExtensionAPI}
  64184. */
  64185. this._api = api;
  64186. /**
  64187. * Should be cleaned when render.
  64188. * @private
  64189. * @type {Array.<Array.<Object>>}
  64190. */
  64191. this._lastDataByCoordSys = null;
  64192. /**
  64193. * @private
  64194. * @type {boolean}
  64195. */
  64196. this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
  64197. var tooltipContent = this._tooltipContent;
  64198. tooltipContent.update();
  64199. tooltipContent.setEnterable(tooltipModel.get('enterable'));
  64200. this._initGlobalListener();
  64201. this._keepShow();
  64202. },
  64203. _initGlobalListener: function () {
  64204. var tooltipModel = this._tooltipModel;
  64205. var triggerOn = tooltipModel.get('triggerOn');
  64206. register(
  64207. 'itemTooltip',
  64208. this._api,
  64209. bind$3(function (currTrigger, e, dispatchAction) {
  64210. // If 'none', it is not controlled by mouse totally.
  64211. if (triggerOn !== 'none') {
  64212. if (triggerOn.indexOf(currTrigger) >= 0) {
  64213. this._tryShow(e, dispatchAction);
  64214. }
  64215. else if (currTrigger === 'leave') {
  64216. this._hide(dispatchAction);
  64217. }
  64218. }
  64219. }, this)
  64220. );
  64221. },
  64222. _keepShow: function () {
  64223. var tooltipModel = this._tooltipModel;
  64224. var ecModel = this._ecModel;
  64225. var api = this._api;
  64226. // Try to keep the tooltip show when refreshing
  64227. if (this._lastX != null
  64228. && this._lastY != null
  64229. // When user is willing to control tooltip totally using API,
  64230. // self.manuallyShowTip({x, y}) might cause tooltip hide,
  64231. // which is not expected.
  64232. && tooltipModel.get('triggerOn') !== 'none'
  64233. ) {
  64234. var self = this;
  64235. clearTimeout(this._refreshUpdateTimeout);
  64236. this._refreshUpdateTimeout = setTimeout(function () {
  64237. // Show tip next tick after other charts are rendered
  64238. // In case highlight action has wrong result
  64239. // FIXME
  64240. self.manuallyShowTip(tooltipModel, ecModel, api, {
  64241. x: self._lastX,
  64242. y: self._lastY
  64243. });
  64244. });
  64245. }
  64246. },
  64247. /**
  64248. * Show tip manually by
  64249. * dispatchAction({
  64250. * type: 'showTip',
  64251. * x: 10,
  64252. * y: 10
  64253. * });
  64254. * Or
  64255. * dispatchAction({
  64256. * type: 'showTip',
  64257. * seriesIndex: 0,
  64258. * dataIndex or dataIndexInside or name
  64259. * });
  64260. *
  64261. * TODO Batch
  64262. */
  64263. manuallyShowTip: function (tooltipModel, ecModel, api, payload) {
  64264. if (payload.from === this.uid || env$1.node) {
  64265. return;
  64266. }
  64267. var dispatchAction = makeDispatchAction$1(payload, api);
  64268. // Reset ticket
  64269. this._ticket = '';
  64270. // When triggered from axisPointer.
  64271. var dataByCoordSys = payload.dataByCoordSys;
  64272. if (payload.tooltip && payload.x != null && payload.y != null) {
  64273. var el = proxyRect;
  64274. el.position = [payload.x, payload.y];
  64275. el.update();
  64276. el.tooltip = payload.tooltip;
  64277. // Manually show tooltip while view is not using zrender elements.
  64278. this._tryShow({
  64279. offsetX: payload.x,
  64280. offsetY: payload.y,
  64281. target: el
  64282. }, dispatchAction);
  64283. }
  64284. else if (dataByCoordSys) {
  64285. this._tryShow({
  64286. offsetX: payload.x,
  64287. offsetY: payload.y,
  64288. position: payload.position,
  64289. event: {},
  64290. dataByCoordSys: payload.dataByCoordSys,
  64291. tooltipOption: payload.tooltipOption
  64292. }, dispatchAction);
  64293. }
  64294. else if (payload.seriesIndex != null) {
  64295. if (this._manuallyAxisShowTip(tooltipModel, ecModel, api, payload)) {
  64296. return;
  64297. }
  64298. var pointInfo = findPointFromSeries(payload, ecModel);
  64299. var cx = pointInfo.point[0];
  64300. var cy = pointInfo.point[1];
  64301. if (cx != null && cy != null) {
  64302. this._tryShow({
  64303. offsetX: cx,
  64304. offsetY: cy,
  64305. position: payload.position,
  64306. target: pointInfo.el,
  64307. event: {}
  64308. }, dispatchAction);
  64309. }
  64310. }
  64311. else if (payload.x != null && payload.y != null) {
  64312. // FIXME
  64313. // should wrap dispatchAction like `axisPointer/globalListener` ?
  64314. api.dispatchAction({
  64315. type: 'updateAxisPointer',
  64316. x: payload.x,
  64317. y: payload.y
  64318. });
  64319. this._tryShow({
  64320. offsetX: payload.x,
  64321. offsetY: payload.y,
  64322. position: payload.position,
  64323. target: api.getZr().findHover(payload.x, payload.y).target,
  64324. event: {}
  64325. }, dispatchAction);
  64326. }
  64327. },
  64328. manuallyHideTip: function (tooltipModel, ecModel, api, payload) {
  64329. var tooltipContent = this._tooltipContent;
  64330. if (!this._alwaysShowContent && this._tooltipModel) {
  64331. tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  64332. }
  64333. this._lastX = this._lastY = null;
  64334. if (payload.from !== this.uid) {
  64335. this._hide(makeDispatchAction$1(payload, api));
  64336. }
  64337. },
  64338. // Be compatible with previous design, that is, when tooltip.type is 'axis' and
  64339. // dispatchAction 'showTip' with seriesIndex and dataIndex will trigger axis pointer
  64340. // and tooltip.
  64341. _manuallyAxisShowTip: function (tooltipModel, ecModel, api, payload) {
  64342. var seriesIndex = payload.seriesIndex;
  64343. var dataIndex = payload.dataIndex;
  64344. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  64345. if (seriesIndex == null || dataIndex == null || coordSysAxesInfo == null) {
  64346. return;
  64347. }
  64348. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  64349. if (!seriesModel) {
  64350. return;
  64351. }
  64352. var data = seriesModel.getData();
  64353. var tooltipModel = buildTooltipModel([
  64354. data.getItemModel(dataIndex),
  64355. seriesModel,
  64356. (seriesModel.coordinateSystem || {}).model,
  64357. tooltipModel
  64358. ]);
  64359. if (tooltipModel.get('trigger') !== 'axis') {
  64360. return;
  64361. }
  64362. api.dispatchAction({
  64363. type: 'updateAxisPointer',
  64364. seriesIndex: seriesIndex,
  64365. dataIndex: dataIndex,
  64366. position: payload.position
  64367. });
  64368. return true;
  64369. },
  64370. _tryShow: function (e, dispatchAction) {
  64371. var el = e.target;
  64372. var tooltipModel = this._tooltipModel;
  64373. if (!tooltipModel) {
  64374. return;
  64375. }
  64376. // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  64377. this._lastX = e.offsetX;
  64378. this._lastY = e.offsetY;
  64379. var dataByCoordSys = e.dataByCoordSys;
  64380. if (dataByCoordSys && dataByCoordSys.length) {
  64381. this._showAxisTooltip(dataByCoordSys, e);
  64382. }
  64383. // Always show item tooltip if mouse is on the element with dataIndex
  64384. else if (el && el.dataIndex != null) {
  64385. this._lastDataByCoordSys = null;
  64386. this._showSeriesItemTooltip(e, el, dispatchAction);
  64387. }
  64388. // Tooltip provided directly. Like legend.
  64389. else if (el && el.tooltip) {
  64390. this._lastDataByCoordSys = null;
  64391. this._showComponentItemTooltip(e, el, dispatchAction);
  64392. }
  64393. else {
  64394. this._lastDataByCoordSys = null;
  64395. this._hide(dispatchAction);
  64396. }
  64397. },
  64398. _showOrMove: function (tooltipModel, cb) {
  64399. // showDelay is used in this case: tooltip.enterable is set
  64400. // as true. User intent to move mouse into tooltip and click
  64401. // something. `showDelay` makes it easyer to enter the content
  64402. // but tooltip do not move immediately.
  64403. var delay = tooltipModel.get('showDelay');
  64404. cb = bind(cb, this);
  64405. clearTimeout(this._showTimout);
  64406. delay > 0
  64407. ? (this._showTimout = setTimeout(cb, delay))
  64408. : cb();
  64409. },
  64410. _showAxisTooltip: function (dataByCoordSys, e) {
  64411. var ecModel = this._ecModel;
  64412. var globalTooltipModel = this._tooltipModel;
  64413. var point = [e.offsetX, e.offsetY];
  64414. var singleDefaultHTML = [];
  64415. var singleParamsList = [];
  64416. var singleTooltipModel = buildTooltipModel([
  64417. e.tooltipOption,
  64418. globalTooltipModel
  64419. ]);
  64420. var renderMode = this._renderMode;
  64421. var newLine = this._newLine;
  64422. var markers = {};
  64423. each$17(dataByCoordSys, function (itemCoordSys) {
  64424. // var coordParamList = [];
  64425. // var coordDefaultHTML = [];
  64426. // var coordTooltipModel = buildTooltipModel([
  64427. // e.tooltipOption,
  64428. // itemCoordSys.tooltipOption,
  64429. // ecModel.getComponent(itemCoordSys.coordSysMainType, itemCoordSys.coordSysIndex),
  64430. // globalTooltipModel
  64431. // ]);
  64432. // var displayMode = coordTooltipModel.get('displayMode');
  64433. // var paramsList = displayMode === 'single' ? singleParamsList : [];
  64434. each$17(itemCoordSys.dataByAxis, function (item) {
  64435. var axisModel = ecModel.getComponent(item.axisDim + 'Axis', item.axisIndex);
  64436. var axisValue = item.value;
  64437. var seriesDefaultHTML = [];
  64438. if (!axisModel || axisValue == null) {
  64439. return;
  64440. }
  64441. var valueLabel = getValueLabel(
  64442. axisValue, axisModel.axis, ecModel,
  64443. item.seriesDataIndices,
  64444. item.valueLabelOpt
  64445. );
  64446. each$1(item.seriesDataIndices, function (idxItem) {
  64447. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  64448. var dataIndex = idxItem.dataIndexInside;
  64449. var dataParams = series && series.getDataParams(dataIndex);
  64450. dataParams.axisDim = item.axisDim;
  64451. dataParams.axisIndex = item.axisIndex;
  64452. dataParams.axisType = item.axisType;
  64453. dataParams.axisId = item.axisId;
  64454. dataParams.axisValue = getAxisRawValue(axisModel.axis, axisValue);
  64455. dataParams.axisValueLabel = valueLabel;
  64456. if (dataParams) {
  64457. singleParamsList.push(dataParams);
  64458. var seriesTooltip = series.formatTooltip(dataIndex, true, null, renderMode);
  64459. var html;
  64460. if (isObject$1(seriesTooltip)) {
  64461. html = seriesTooltip.html;
  64462. var newMarkers = seriesTooltip.markers;
  64463. merge(markers, newMarkers);
  64464. }
  64465. else {
  64466. html = seriesTooltip;
  64467. }
  64468. seriesDefaultHTML.push(html);
  64469. }
  64470. });
  64471. // Default tooltip content
  64472. // FIXME
  64473. // (1) shold be the first data which has name?
  64474. // (2) themeRiver, firstDataIndex is array, and first line is unnecessary.
  64475. var firstLine = valueLabel;
  64476. if (renderMode !== 'html') {
  64477. singleDefaultHTML.push(seriesDefaultHTML.join(newLine));
  64478. }
  64479. else {
  64480. singleDefaultHTML.push(
  64481. (firstLine ? encodeHTML(firstLine) + newLine : '')
  64482. + seriesDefaultHTML.join(newLine)
  64483. );
  64484. }
  64485. });
  64486. }, this);
  64487. // In most case, the second axis is shown upper than the first one.
  64488. singleDefaultHTML.reverse();
  64489. singleDefaultHTML = singleDefaultHTML.join(this._newLine + this._newLine);
  64490. var positionExpr = e.position;
  64491. this._showOrMove(singleTooltipModel, function () {
  64492. if (this._updateContentNotChangedOnAxis(dataByCoordSys)) {
  64493. this._updatePosition(
  64494. singleTooltipModel,
  64495. positionExpr,
  64496. point[0], point[1],
  64497. this._tooltipContent,
  64498. singleParamsList
  64499. );
  64500. }
  64501. else {
  64502. this._showTooltipContent(
  64503. singleTooltipModel, singleDefaultHTML, singleParamsList, Math.random(),
  64504. point[0], point[1], positionExpr, undefined, markers
  64505. );
  64506. }
  64507. });
  64508. // Do not trigger events here, because this branch only be entered
  64509. // from dispatchAction.
  64510. },
  64511. _showSeriesItemTooltip: function (e, el, dispatchAction) {
  64512. var ecModel = this._ecModel;
  64513. // Use dataModel in element if possible
  64514. // Used when mouseover on a element like markPoint or edge
  64515. // In which case, the data is not main data in series.
  64516. var seriesIndex = el.seriesIndex;
  64517. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  64518. // For example, graph link.
  64519. var dataModel = el.dataModel || seriesModel;
  64520. var dataIndex = el.dataIndex;
  64521. var dataType = el.dataType;
  64522. var data = dataModel.getData();
  64523. var tooltipModel = buildTooltipModel([
  64524. data.getItemModel(dataIndex),
  64525. dataModel,
  64526. seriesModel && (seriesModel.coordinateSystem || {}).model,
  64527. this._tooltipModel
  64528. ]);
  64529. var tooltipTrigger = tooltipModel.get('trigger');
  64530. if (tooltipTrigger != null && tooltipTrigger !== 'item') {
  64531. return;
  64532. }
  64533. var params = dataModel.getDataParams(dataIndex, dataType);
  64534. var seriesTooltip = dataModel.formatTooltip(dataIndex, false, dataType, this._renderMode);
  64535. var defaultHtml;
  64536. var markers;
  64537. if (isObject$1(seriesTooltip)) {
  64538. defaultHtml = seriesTooltip.html;
  64539. markers = seriesTooltip.markers;
  64540. }
  64541. else {
  64542. defaultHtml = seriesTooltip;
  64543. markers = null;
  64544. }
  64545. var asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;
  64546. this._showOrMove(tooltipModel, function () {
  64547. this._showTooltipContent(
  64548. tooltipModel, defaultHtml, params, asyncTicket,
  64549. e.offsetX, e.offsetY, e.position, e.target, markers
  64550. );
  64551. });
  64552. // FIXME
  64553. // duplicated showtip if manuallyShowTip is called from dispatchAction.
  64554. dispatchAction({
  64555. type: 'showTip',
  64556. dataIndexInside: dataIndex,
  64557. dataIndex: data.getRawIndex(dataIndex),
  64558. seriesIndex: seriesIndex,
  64559. from: this.uid
  64560. });
  64561. },
  64562. _showComponentItemTooltip: function (e, el, dispatchAction) {
  64563. var tooltipOpt = el.tooltip;
  64564. if (typeof tooltipOpt === 'string') {
  64565. var content = tooltipOpt;
  64566. tooltipOpt = {
  64567. content: content,
  64568. // Fixed formatter
  64569. formatter: content
  64570. };
  64571. }
  64572. var subTooltipModel = new Model(tooltipOpt, this._tooltipModel, this._ecModel);
  64573. var defaultHtml = subTooltipModel.get('content');
  64574. var asyncTicket = Math.random();
  64575. // Do not check whether `trigger` is 'none' here, because `trigger`
  64576. // only works on cooridinate system. In fact, we have not found case
  64577. // that requires setting `trigger` nothing on component yet.
  64578. this._showOrMove(subTooltipModel, function () {
  64579. this._showTooltipContent(
  64580. subTooltipModel, defaultHtml, subTooltipModel.get('formatterParams') || {},
  64581. asyncTicket, e.offsetX, e.offsetY, e.position, el
  64582. );
  64583. });
  64584. // If not dispatch showTip, tip may be hide triggered by axis.
  64585. dispatchAction({
  64586. type: 'showTip',
  64587. from: this.uid
  64588. });
  64589. },
  64590. _showTooltipContent: function (
  64591. tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, el, markers
  64592. ) {
  64593. // Reset ticket
  64594. this._ticket = '';
  64595. if (!tooltipModel.get('showContent') || !tooltipModel.get('show')) {
  64596. return;
  64597. }
  64598. var tooltipContent = this._tooltipContent;
  64599. var formatter = tooltipModel.get('formatter');
  64600. positionExpr = positionExpr || tooltipModel.get('position');
  64601. var html = defaultHtml;
  64602. if (formatter && typeof formatter === 'string') {
  64603. html = formatTpl(formatter, params, true);
  64604. }
  64605. else if (typeof formatter === 'function') {
  64606. var callback = bind$3(function (cbTicket, html) {
  64607. if (cbTicket === this._ticket) {
  64608. tooltipContent.setContent(html, markers, tooltipModel);
  64609. this._updatePosition(
  64610. tooltipModel, positionExpr, x, y, tooltipContent, params, el
  64611. );
  64612. }
  64613. }, this);
  64614. this._ticket = asyncTicket;
  64615. html = formatter(params, asyncTicket, callback);
  64616. }
  64617. tooltipContent.setContent(html, markers, tooltipModel);
  64618. tooltipContent.show(tooltipModel);
  64619. this._updatePosition(
  64620. tooltipModel, positionExpr, x, y, tooltipContent, params, el
  64621. );
  64622. },
  64623. /**
  64624. * @param {string|Function|Array.<number>|Object} positionExpr
  64625. * @param {number} x Mouse x
  64626. * @param {number} y Mouse y
  64627. * @param {boolean} confine Whether confine tooltip content in view rect.
  64628. * @param {Object|<Array.<Object>} params
  64629. * @param {module:zrender/Element} el target element
  64630. * @param {module:echarts/ExtensionAPI} api
  64631. * @return {Array.<number>}
  64632. */
  64633. _updatePosition: function (tooltipModel, positionExpr, x, y, content, params, el) {
  64634. var viewWidth = this._api.getWidth();
  64635. var viewHeight = this._api.getHeight();
  64636. positionExpr = positionExpr || tooltipModel.get('position');
  64637. var contentSize = content.getSize();
  64638. var align = tooltipModel.get('align');
  64639. var vAlign = tooltipModel.get('verticalAlign');
  64640. var rect = el && el.getBoundingRect().clone();
  64641. el && rect.applyTransform(el.transform);
  64642. if (typeof positionExpr === 'function') {
  64643. // Callback of position can be an array or a string specify the position
  64644. positionExpr = positionExpr([x, y], params, content.el, rect, {
  64645. viewSize: [viewWidth, viewHeight],
  64646. contentSize: contentSize.slice()
  64647. });
  64648. }
  64649. if (isArray(positionExpr)) {
  64650. x = parsePercent$2(positionExpr[0], viewWidth);
  64651. y = parsePercent$2(positionExpr[1], viewHeight);
  64652. }
  64653. else if (isObject$1(positionExpr)) {
  64654. positionExpr.width = contentSize[0];
  64655. positionExpr.height = contentSize[1];
  64656. var layoutRect = getLayoutRect(
  64657. positionExpr, {width: viewWidth, height: viewHeight}
  64658. );
  64659. x = layoutRect.x;
  64660. y = layoutRect.y;
  64661. align = null;
  64662. // When positionExpr is left/top/right/bottom,
  64663. // align and verticalAlign will not work.
  64664. vAlign = null;
  64665. }
  64666. // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  64667. else if (typeof positionExpr === 'string' && el) {
  64668. var pos = calcTooltipPosition(
  64669. positionExpr, rect, contentSize
  64670. );
  64671. x = pos[0];
  64672. y = pos[1];
  64673. }
  64674. else {
  64675. var pos = refixTooltipPosition(
  64676. x, y, content, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20
  64677. );
  64678. x = pos[0];
  64679. y = pos[1];
  64680. }
  64681. align && (x -= isCenterAlign(align) ? contentSize[0] / 2 : align === 'right' ? contentSize[0] : 0);
  64682. vAlign && (y -= isCenterAlign(vAlign) ? contentSize[1] / 2 : vAlign === 'bottom' ? contentSize[1] : 0);
  64683. if (tooltipModel.get('confine')) {
  64684. var pos = confineTooltipPosition(
  64685. x, y, content, viewWidth, viewHeight
  64686. );
  64687. x = pos[0];
  64688. y = pos[1];
  64689. }
  64690. content.moveTo(x, y);
  64691. },
  64692. // FIXME
  64693. // Should we remove this but leave this to user?
  64694. _updateContentNotChangedOnAxis: function (dataByCoordSys) {
  64695. var lastCoordSys = this._lastDataByCoordSys;
  64696. var contentNotChanged = !!lastCoordSys
  64697. && lastCoordSys.length === dataByCoordSys.length;
  64698. contentNotChanged && each$17(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
  64699. var lastDataByAxis = lastItemCoordSys.dataByAxis || {};
  64700. var thisItemCoordSys = dataByCoordSys[indexCoordSys] || {};
  64701. var thisDataByAxis = thisItemCoordSys.dataByAxis || [];
  64702. contentNotChanged &= lastDataByAxis.length === thisDataByAxis.length;
  64703. contentNotChanged && each$17(lastDataByAxis, function (lastItem, indexAxis) {
  64704. var thisItem = thisDataByAxis[indexAxis] || {};
  64705. var lastIndices = lastItem.seriesDataIndices || [];
  64706. var newIndices = thisItem.seriesDataIndices || [];
  64707. contentNotChanged
  64708. &= lastItem.value === thisItem.value
  64709. && lastItem.axisType === thisItem.axisType
  64710. && lastItem.axisId === thisItem.axisId
  64711. && lastIndices.length === newIndices.length;
  64712. contentNotChanged && each$17(lastIndices, function (lastIdxItem, j) {
  64713. var newIdxItem = newIndices[j];
  64714. contentNotChanged
  64715. &= lastIdxItem.seriesIndex === newIdxItem.seriesIndex
  64716. && lastIdxItem.dataIndex === newIdxItem.dataIndex;
  64717. });
  64718. });
  64719. });
  64720. this._lastDataByCoordSys = dataByCoordSys;
  64721. return !!contentNotChanged;
  64722. },
  64723. _hide: function (dispatchAction) {
  64724. // Do not directly hideLater here, because this behavior may be prevented
  64725. // in dispatchAction when showTip is dispatched.
  64726. // FIXME
  64727. // duplicated hideTip if manuallyHideTip is called from dispatchAction.
  64728. this._lastDataByCoordSys = null;
  64729. dispatchAction({
  64730. type: 'hideTip',
  64731. from: this.uid
  64732. });
  64733. },
  64734. dispose: function (ecModel, api) {
  64735. if (env$1.node) {
  64736. return;
  64737. }
  64738. this._tooltipContent.hide();
  64739. unregister('itemTooltip', api);
  64740. }
  64741. });
  64742. /**
  64743. * @param {Array.<Object|module:echarts/model/Model>} modelCascade
  64744. * From top to bottom. (the last one should be globalTooltipModel);
  64745. */
  64746. function buildTooltipModel(modelCascade) {
  64747. var resultModel = modelCascade.pop();
  64748. while (modelCascade.length) {
  64749. var tooltipOpt = modelCascade.pop();
  64750. if (tooltipOpt) {
  64751. if (Model.isInstance(tooltipOpt)) {
  64752. tooltipOpt = tooltipOpt.get('tooltip', true);
  64753. }
  64754. // In each data item tooltip can be simply write:
  64755. // {
  64756. // value: 10,
  64757. // tooltip: 'Something you need to know'
  64758. // }
  64759. if (typeof tooltipOpt === 'string') {
  64760. tooltipOpt = {formatter: tooltipOpt};
  64761. }
  64762. resultModel = new Model(tooltipOpt, resultModel, resultModel.ecModel);
  64763. }
  64764. }
  64765. return resultModel;
  64766. }
  64767. function makeDispatchAction$1(payload, api) {
  64768. return payload.dispatchAction || bind(api.dispatchAction, api);
  64769. }
  64770. function refixTooltipPosition(x, y, content, viewWidth, viewHeight, gapH, gapV) {
  64771. var size = content.getOuterSize();
  64772. var width = size.width;
  64773. var height = size.height;
  64774. if (gapH != null) {
  64775. if (x + width + gapH > viewWidth) {
  64776. x -= width + gapH;
  64777. }
  64778. else {
  64779. x += gapH;
  64780. }
  64781. }
  64782. if (gapV != null) {
  64783. if (y + height + gapV > viewHeight) {
  64784. y -= height + gapV;
  64785. }
  64786. else {
  64787. y += gapV;
  64788. }
  64789. }
  64790. return [x, y];
  64791. }
  64792. function confineTooltipPosition(x, y, content, viewWidth, viewHeight) {
  64793. var size = content.getOuterSize();
  64794. var width = size.width;
  64795. var height = size.height;
  64796. x = Math.min(x + width, viewWidth) - width;
  64797. y = Math.min(y + height, viewHeight) - height;
  64798. x = Math.max(x, 0);
  64799. y = Math.max(y, 0);
  64800. return [x, y];
  64801. }
  64802. function calcTooltipPosition(position, rect, contentSize) {
  64803. var domWidth = contentSize[0];
  64804. var domHeight = contentSize[1];
  64805. var gap = 5;
  64806. var x = 0;
  64807. var y = 0;
  64808. var rectWidth = rect.width;
  64809. var rectHeight = rect.height;
  64810. switch (position) {
  64811. case 'inside':
  64812. x = rect.x + rectWidth / 2 - domWidth / 2;
  64813. y = rect.y + rectHeight / 2 - domHeight / 2;
  64814. break;
  64815. case 'top':
  64816. x = rect.x + rectWidth / 2 - domWidth / 2;
  64817. y = rect.y - domHeight - gap;
  64818. break;
  64819. case 'bottom':
  64820. x = rect.x + rectWidth / 2 - domWidth / 2;
  64821. y = rect.y + rectHeight + gap;
  64822. break;
  64823. case 'left':
  64824. x = rect.x - domWidth - gap;
  64825. y = rect.y + rectHeight / 2 - domHeight / 2;
  64826. break;
  64827. case 'right':
  64828. x = rect.x + rectWidth + gap;
  64829. y = rect.y + rectHeight / 2 - domHeight / 2;
  64830. }
  64831. return [x, y];
  64832. }
  64833. function isCenterAlign(align) {
  64834. return align === 'center' || align === 'middle';
  64835. }
  64836. /*
  64837. * Licensed to the Apache Software Foundation (ASF) under one
  64838. * or more contributor license agreements. See the NOTICE file
  64839. * distributed with this work for additional information
  64840. * regarding copyright ownership. The ASF licenses this file
  64841. * to you under the Apache License, Version 2.0 (the
  64842. * "License"); you may not use this file except in compliance
  64843. * with the License. You may obtain a copy of the License at
  64844. *
  64845. * http://www.apache.org/licenses/LICENSE-2.0
  64846. *
  64847. * Unless required by applicable law or agreed to in writing,
  64848. * software distributed under the License is distributed on an
  64849. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  64850. * KIND, either express or implied. See the License for the
  64851. * specific language governing permissions and limitations
  64852. * under the License.
  64853. */
  64854. // FIXME Better way to pack data in graphic element
  64855. /**
  64856. * @action
  64857. * @property {string} type
  64858. * @property {number} seriesIndex
  64859. * @property {number} dataIndex
  64860. * @property {number} [x]
  64861. * @property {number} [y]
  64862. */
  64863. registerAction(
  64864. {
  64865. type: 'showTip',
  64866. event: 'showTip',
  64867. update: 'tooltip:manuallyShowTip'
  64868. },
  64869. // noop
  64870. function () {}
  64871. );
  64872. registerAction(
  64873. {
  64874. type: 'hideTip',
  64875. event: 'hideTip',
  64876. update: 'tooltip:manuallyHideTip'
  64877. },
  64878. // noop
  64879. function () {}
  64880. );
  64881. /*
  64882. * Licensed to the Apache Software Foundation (ASF) under one
  64883. * or more contributor license agreements. See the NOTICE file
  64884. * distributed with this work for additional information
  64885. * regarding copyright ownership. The ASF licenses this file
  64886. * to you under the Apache License, Version 2.0 (the
  64887. * "License"); you may not use this file except in compliance
  64888. * with the License. You may obtain a copy of the License at
  64889. *
  64890. * http://www.apache.org/licenses/LICENSE-2.0
  64891. *
  64892. * Unless required by applicable law or agreed to in writing,
  64893. * software distributed under the License is distributed on an
  64894. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  64895. * KIND, either express or implied. See the License for the
  64896. * specific language governing permissions and limitations
  64897. * under the License.
  64898. */
  64899. function getSeriesStackId$1(seriesModel) {
  64900. return seriesModel.get('stack')
  64901. || '__ec_stack_' + seriesModel.seriesIndex;
  64902. }
  64903. function getAxisKey$1(axis) {
  64904. return axis.dim;
  64905. }
  64906. /**
  64907. * @param {string} seriesType
  64908. * @param {module:echarts/model/Global} ecModel
  64909. * @param {module:echarts/ExtensionAPI} api
  64910. */
  64911. function barLayoutPolar(seriesType, ecModel, api) {
  64912. // FIXME
  64913. // Revert becuase it brings bar progressive bug.
  64914. // The complete fix will be added in the next version.
  64915. var width = api.getWidth();
  64916. var height = api.getHeight();
  64917. var lastStackCoords = {};
  64918. var barWidthAndOffset = calRadialBar(
  64919. filter(
  64920. ecModel.getSeriesByType(seriesType),
  64921. function (seriesModel) {
  64922. return !ecModel.isSeriesFiltered(seriesModel)
  64923. && seriesModel.coordinateSystem
  64924. && seriesModel.coordinateSystem.type === 'polar';
  64925. }
  64926. )
  64927. );
  64928. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  64929. // Check series coordinate, do layout for polar only
  64930. if (seriesModel.coordinateSystem.type !== 'polar') {
  64931. return;
  64932. }
  64933. var data = seriesModel.getData();
  64934. var polar = seriesModel.coordinateSystem;
  64935. var baseAxis = polar.getBaseAxis();
  64936. var stackId = getSeriesStackId$1(seriesModel);
  64937. var columnLayoutInfo
  64938. = barWidthAndOffset[getAxisKey$1(baseAxis)][stackId];
  64939. var columnOffset = columnLayoutInfo.offset;
  64940. var columnWidth = columnLayoutInfo.width;
  64941. var valueAxis = polar.getOtherAxis(baseAxis);
  64942. var cx = seriesModel.coordinateSystem.cx;
  64943. var cy = seriesModel.coordinateSystem.cy;
  64944. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  64945. var barMinAngle = seriesModel.get('barMinAngle') || 0;
  64946. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  64947. var valueDim = data.mapDimension(valueAxis.dim);
  64948. var baseDim = data.mapDimension(baseAxis.dim);
  64949. var stacked = isDimensionStacked(data, valueDim /*, baseDim*/);
  64950. var valueAxisStart = valueAxis.getExtent()[0];
  64951. for (var idx = 0, len = data.count(); idx < len; idx++) {
  64952. var value = data.get(valueDim, idx);
  64953. var baseValue = data.get(baseDim, idx);
  64954. if (isNaN(value)) {
  64955. continue;
  64956. }
  64957. var sign = value >= 0 ? 'p' : 'n';
  64958. var baseCoord = valueAxisStart;
  64959. // Because of the barMinHeight, we can not use the value in
  64960. // stackResultDimension directly.
  64961. // Only ordinal axis can be stacked.
  64962. if (stacked) {
  64963. if (!lastStackCoords[stackId][baseValue]) {
  64964. lastStackCoords[stackId][baseValue] = {
  64965. p: valueAxisStart, // Positive stack
  64966. n: valueAxisStart // Negative stack
  64967. };
  64968. }
  64969. // Should also consider #4243
  64970. baseCoord = lastStackCoords[stackId][baseValue][sign];
  64971. }
  64972. var r0;
  64973. var r;
  64974. var startAngle;
  64975. var endAngle;
  64976. // radial sector
  64977. if (valueAxis.dim === 'radius') {
  64978. var radiusSpan = valueAxis.dataToRadius(value) - valueAxisStart;
  64979. var angle = baseAxis.dataToAngle(baseValue);
  64980. if (Math.abs(radiusSpan) < barMinHeight) {
  64981. radiusSpan = (radiusSpan < 0 ? -1 : 1) * barMinHeight;
  64982. }
  64983. r0 = baseCoord;
  64984. r = baseCoord + radiusSpan;
  64985. startAngle = angle - columnOffset;
  64986. endAngle = startAngle - columnWidth;
  64987. stacked && (lastStackCoords[stackId][baseValue][sign] = r);
  64988. }
  64989. // tangential sector
  64990. else {
  64991. // angleAxis must be clamped.
  64992. var angleSpan = valueAxis.dataToAngle(value, true) - valueAxisStart;
  64993. var radius = baseAxis.dataToRadius(baseValue);
  64994. if (Math.abs(angleSpan) < barMinAngle) {
  64995. angleSpan = (angleSpan < 0 ? -1 : 1) * barMinAngle;
  64996. }
  64997. r0 = radius + columnOffset;
  64998. r = r0 + columnWidth;
  64999. startAngle = baseCoord;
  65000. endAngle = baseCoord + angleSpan;
  65001. // if the previous stack is at the end of the ring,
  65002. // add a round to differentiate it from origin
  65003. // var extent = angleAxis.getExtent();
  65004. // var stackCoord = angle;
  65005. // if (stackCoord === extent[0] && value > 0) {
  65006. // stackCoord = extent[1];
  65007. // }
  65008. // else if (stackCoord === extent[1] && value < 0) {
  65009. // stackCoord = extent[0];
  65010. // }
  65011. stacked && (lastStackCoords[stackId][baseValue][sign] = endAngle);
  65012. }
  65013. data.setItemLayout(idx, {
  65014. cx: cx,
  65015. cy: cy,
  65016. r0: r0,
  65017. r: r,
  65018. // Consider that positive angle is anti-clockwise,
  65019. // while positive radian of sector is clockwise
  65020. startAngle: -startAngle * Math.PI / 180,
  65021. endAngle: -endAngle * Math.PI / 180
  65022. });
  65023. }
  65024. }, this);
  65025. }
  65026. /**
  65027. * Calculate bar width and offset for radial bar charts
  65028. */
  65029. function calRadialBar(barSeries, api) {
  65030. // Columns info on each category axis. Key is polar name
  65031. var columnsMap = {};
  65032. each$1(barSeries, function (seriesModel, idx) {
  65033. var data = seriesModel.getData();
  65034. var polar = seriesModel.coordinateSystem;
  65035. var baseAxis = polar.getBaseAxis();
  65036. var axisExtent = baseAxis.getExtent();
  65037. var bandWidth = baseAxis.type === 'category'
  65038. ? baseAxis.getBandWidth()
  65039. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  65040. var columnsOnAxis = columnsMap[getAxisKey$1(baseAxis)] || {
  65041. bandWidth: bandWidth,
  65042. remainedWidth: bandWidth,
  65043. autoWidthCount: 0,
  65044. categoryGap: '20%',
  65045. gap: '30%',
  65046. stacks: {}
  65047. };
  65048. var stacks = columnsOnAxis.stacks;
  65049. columnsMap[getAxisKey$1(baseAxis)] = columnsOnAxis;
  65050. var stackId = getSeriesStackId$1(seriesModel);
  65051. if (!stacks[stackId]) {
  65052. columnsOnAxis.autoWidthCount++;
  65053. }
  65054. stacks[stackId] = stacks[stackId] || {
  65055. width: 0,
  65056. maxWidth: 0
  65057. };
  65058. var barWidth = parsePercent$1(
  65059. seriesModel.get('barWidth'),
  65060. bandWidth
  65061. );
  65062. var barMaxWidth = parsePercent$1(
  65063. seriesModel.get('barMaxWidth'),
  65064. bandWidth
  65065. );
  65066. var barGap = seriesModel.get('barGap');
  65067. var barCategoryGap = seriesModel.get('barCategoryGap');
  65068. if (barWidth && !stacks[stackId].width) {
  65069. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  65070. stacks[stackId].width = barWidth;
  65071. columnsOnAxis.remainedWidth -= barWidth;
  65072. }
  65073. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  65074. (barGap != null) && (columnsOnAxis.gap = barGap);
  65075. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  65076. });
  65077. var result = {};
  65078. each$1(columnsMap, function (columnsOnAxis, coordSysName) {
  65079. result[coordSysName] = {};
  65080. var stacks = columnsOnAxis.stacks;
  65081. var bandWidth = columnsOnAxis.bandWidth;
  65082. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  65083. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  65084. var remainedWidth = columnsOnAxis.remainedWidth;
  65085. var autoWidthCount = columnsOnAxis.autoWidthCount;
  65086. var autoWidth = (remainedWidth - categoryGap)
  65087. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  65088. autoWidth = Math.max(autoWidth, 0);
  65089. // Find if any auto calculated bar exceeded maxBarWidth
  65090. each$1(stacks, function (column, stack) {
  65091. var maxWidth = column.maxWidth;
  65092. if (maxWidth && maxWidth < autoWidth) {
  65093. maxWidth = Math.min(maxWidth, remainedWidth);
  65094. if (column.width) {
  65095. maxWidth = Math.min(maxWidth, column.width);
  65096. }
  65097. remainedWidth -= maxWidth;
  65098. column.width = maxWidth;
  65099. autoWidthCount--;
  65100. }
  65101. });
  65102. // Recalculate width again
  65103. autoWidth = (remainedWidth - categoryGap)
  65104. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  65105. autoWidth = Math.max(autoWidth, 0);
  65106. var widthSum = 0;
  65107. var lastColumn;
  65108. each$1(stacks, function (column, idx) {
  65109. if (!column.width) {
  65110. column.width = autoWidth;
  65111. }
  65112. lastColumn = column;
  65113. widthSum += column.width * (1 + barGapPercent);
  65114. });
  65115. if (lastColumn) {
  65116. widthSum -= lastColumn.width * barGapPercent;
  65117. }
  65118. var offset = -widthSum / 2;
  65119. each$1(stacks, function (column, stackId) {
  65120. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  65121. offset: offset,
  65122. width: column.width
  65123. };
  65124. offset += column.width * (1 + barGapPercent);
  65125. });
  65126. });
  65127. return result;
  65128. }
  65129. /*
  65130. * Licensed to the Apache Software Foundation (ASF) under one
  65131. * or more contributor license agreements. See the NOTICE file
  65132. * distributed with this work for additional information
  65133. * regarding copyright ownership. The ASF licenses this file
  65134. * to you under the Apache License, Version 2.0 (the
  65135. * "License"); you may not use this file except in compliance
  65136. * with the License. You may obtain a copy of the License at
  65137. *
  65138. * http://www.apache.org/licenses/LICENSE-2.0
  65139. *
  65140. * Unless required by applicable law or agreed to in writing,
  65141. * software distributed under the License is distributed on an
  65142. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65143. * KIND, either express or implied. See the License for the
  65144. * specific language governing permissions and limitations
  65145. * under the License.
  65146. */
  65147. function RadiusAxis(scale, radiusExtent) {
  65148. Axis.call(this, 'radius', scale, radiusExtent);
  65149. /**
  65150. * Axis type
  65151. * - 'category'
  65152. * - 'value'
  65153. * - 'time'
  65154. * - 'log'
  65155. * @type {string}
  65156. */
  65157. this.type = 'category';
  65158. }
  65159. RadiusAxis.prototype = {
  65160. constructor: RadiusAxis,
  65161. /**
  65162. * @override
  65163. */
  65164. pointToData: function (point, clamp) {
  65165. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  65166. },
  65167. dataToRadius: Axis.prototype.dataToCoord,
  65168. radiusToData: Axis.prototype.coordToData
  65169. };
  65170. inherits(RadiusAxis, Axis);
  65171. /*
  65172. * Licensed to the Apache Software Foundation (ASF) under one
  65173. * or more contributor license agreements. See the NOTICE file
  65174. * distributed with this work for additional information
  65175. * regarding copyright ownership. The ASF licenses this file
  65176. * to you under the Apache License, Version 2.0 (the
  65177. * "License"); you may not use this file except in compliance
  65178. * with the License. You may obtain a copy of the License at
  65179. *
  65180. * http://www.apache.org/licenses/LICENSE-2.0
  65181. *
  65182. * Unless required by applicable law or agreed to in writing,
  65183. * software distributed under the License is distributed on an
  65184. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65185. * KIND, either express or implied. See the License for the
  65186. * specific language governing permissions and limitations
  65187. * under the License.
  65188. */
  65189. var inner$12 = makeInner();
  65190. function AngleAxis(scale, angleExtent) {
  65191. angleExtent = angleExtent || [0, 360];
  65192. Axis.call(this, 'angle', scale, angleExtent);
  65193. /**
  65194. * Axis type
  65195. * - 'category'
  65196. * - 'value'
  65197. * - 'time'
  65198. * - 'log'
  65199. * @type {string}
  65200. */
  65201. this.type = 'category';
  65202. }
  65203. AngleAxis.prototype = {
  65204. constructor: AngleAxis,
  65205. /**
  65206. * @override
  65207. */
  65208. pointToData: function (point, clamp) {
  65209. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  65210. },
  65211. dataToAngle: Axis.prototype.dataToCoord,
  65212. angleToData: Axis.prototype.coordToData,
  65213. /**
  65214. * Only be called in category axis.
  65215. * Angle axis uses text height to decide interval
  65216. *
  65217. * @override
  65218. * @return {number} Auto interval for cateogry axis tick and label
  65219. */
  65220. calculateCategoryInterval: function () {
  65221. var axis = this;
  65222. var labelModel = axis.getLabelModel();
  65223. var ordinalScale = axis.scale;
  65224. var ordinalExtent = ordinalScale.getExtent();
  65225. // Providing this method is for optimization:
  65226. // avoid generating a long array by `getTicks`
  65227. // in large category data case.
  65228. var tickCount = ordinalScale.count();
  65229. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  65230. return 0;
  65231. }
  65232. var tickValue = ordinalExtent[0];
  65233. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  65234. var unitH = Math.abs(unitSpan);
  65235. // Not precise, just use height as text width
  65236. // and each distance from axis line yet.
  65237. var rect = getBoundingRect(
  65238. tickValue, labelModel.getFont(), 'center', 'top'
  65239. );
  65240. var maxH = Math.max(rect.height, 7);
  65241. var dh = maxH / unitH;
  65242. // 0/0 is NaN, 1/0 is Infinity.
  65243. isNaN(dh) && (dh = Infinity);
  65244. var interval = Math.max(0, Math.floor(dh));
  65245. var cache = inner$12(axis.model);
  65246. var lastAutoInterval = cache.lastAutoInterval;
  65247. var lastTickCount = cache.lastTickCount;
  65248. // Use cache to keep interval stable while moving zoom window,
  65249. // otherwise the calculated interval might jitter when the zoom
  65250. // window size is close to the interval-changing size.
  65251. if (lastAutoInterval != null
  65252. && lastTickCount != null
  65253. && Math.abs(lastAutoInterval - interval) <= 1
  65254. && Math.abs(lastTickCount - tickCount) <= 1
  65255. // Always choose the bigger one, otherwise the critical
  65256. // point is not the same when zooming in or zooming out.
  65257. && lastAutoInterval > interval
  65258. ) {
  65259. interval = lastAutoInterval;
  65260. }
  65261. // Only update cache if cache not used, otherwise the
  65262. // changing of interval is too insensitive.
  65263. else {
  65264. cache.lastTickCount = tickCount;
  65265. cache.lastAutoInterval = interval;
  65266. }
  65267. return interval;
  65268. }
  65269. };
  65270. inherits(AngleAxis, Axis);
  65271. /*
  65272. * Licensed to the Apache Software Foundation (ASF) under one
  65273. * or more contributor license agreements. See the NOTICE file
  65274. * distributed with this work for additional information
  65275. * regarding copyright ownership. The ASF licenses this file
  65276. * to you under the Apache License, Version 2.0 (the
  65277. * "License"); you may not use this file except in compliance
  65278. * with the License. You may obtain a copy of the License at
  65279. *
  65280. * http://www.apache.org/licenses/LICENSE-2.0
  65281. *
  65282. * Unless required by applicable law or agreed to in writing,
  65283. * software distributed under the License is distributed on an
  65284. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65285. * KIND, either express or implied. See the License for the
  65286. * specific language governing permissions and limitations
  65287. * under the License.
  65288. */
  65289. /**
  65290. * @module echarts/coord/polar/Polar
  65291. */
  65292. /**
  65293. * @alias {module:echarts/coord/polar/Polar}
  65294. * @constructor
  65295. * @param {string} name
  65296. */
  65297. var Polar = function (name) {
  65298. /**
  65299. * @type {string}
  65300. */
  65301. this.name = name || '';
  65302. /**
  65303. * x of polar center
  65304. * @type {number}
  65305. */
  65306. this.cx = 0;
  65307. /**
  65308. * y of polar center
  65309. * @type {number}
  65310. */
  65311. this.cy = 0;
  65312. /**
  65313. * @type {module:echarts/coord/polar/RadiusAxis}
  65314. * @private
  65315. */
  65316. this._radiusAxis = new RadiusAxis();
  65317. /**
  65318. * @type {module:echarts/coord/polar/AngleAxis}
  65319. * @private
  65320. */
  65321. this._angleAxis = new AngleAxis();
  65322. this._radiusAxis.polar = this._angleAxis.polar = this;
  65323. };
  65324. Polar.prototype = {
  65325. type: 'polar',
  65326. axisPointerEnabled: true,
  65327. constructor: Polar,
  65328. /**
  65329. * @param {Array.<string>}
  65330. * @readOnly
  65331. */
  65332. dimensions: ['radius', 'angle'],
  65333. /**
  65334. * @type {module:echarts/coord/PolarModel}
  65335. */
  65336. model: null,
  65337. /**
  65338. * If contain coord
  65339. * @param {Array.<number>} point
  65340. * @return {boolean}
  65341. */
  65342. containPoint: function (point) {
  65343. var coord = this.pointToCoord(point);
  65344. return this._radiusAxis.contain(coord[0])
  65345. && this._angleAxis.contain(coord[1]);
  65346. },
  65347. /**
  65348. * If contain data
  65349. * @param {Array.<number>} data
  65350. * @return {boolean}
  65351. */
  65352. containData: function (data) {
  65353. return this._radiusAxis.containData(data[0])
  65354. && this._angleAxis.containData(data[1]);
  65355. },
  65356. /**
  65357. * @param {string} dim
  65358. * @return {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  65359. */
  65360. getAxis: function (dim) {
  65361. return this['_' + dim + 'Axis'];
  65362. },
  65363. /**
  65364. * @return {Array.<module:echarts/coord/Axis>}
  65365. */
  65366. getAxes: function () {
  65367. return [this._radiusAxis, this._angleAxis];
  65368. },
  65369. /**
  65370. * Get axes by type of scale
  65371. * @param {string} scaleType
  65372. * @return {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  65373. */
  65374. getAxesByScale: function (scaleType) {
  65375. var axes = [];
  65376. var angleAxis = this._angleAxis;
  65377. var radiusAxis = this._radiusAxis;
  65378. angleAxis.scale.type === scaleType && axes.push(angleAxis);
  65379. radiusAxis.scale.type === scaleType && axes.push(radiusAxis);
  65380. return axes;
  65381. },
  65382. /**
  65383. * @return {module:echarts/coord/polar/AngleAxis}
  65384. */
  65385. getAngleAxis: function () {
  65386. return this._angleAxis;
  65387. },
  65388. /**
  65389. * @return {module:echarts/coord/polar/RadiusAxis}
  65390. */
  65391. getRadiusAxis: function () {
  65392. return this._radiusAxis;
  65393. },
  65394. /**
  65395. * @param {module:echarts/coord/polar/Axis}
  65396. * @return {module:echarts/coord/polar/Axis}
  65397. */
  65398. getOtherAxis: function (axis) {
  65399. var angleAxis = this._angleAxis;
  65400. return axis === angleAxis ? this._radiusAxis : angleAxis;
  65401. },
  65402. /**
  65403. * Base axis will be used on stacking.
  65404. *
  65405. * @return {module:echarts/coord/polar/Axis}
  65406. */
  65407. getBaseAxis: function () {
  65408. return this.getAxesByScale('ordinal')[0]
  65409. || this.getAxesByScale('time')[0]
  65410. || this.getAngleAxis();
  65411. },
  65412. /**
  65413. * @param {string} [dim] 'radius' or 'angle' or 'auto' or null/undefined
  65414. * @return {Object} {baseAxes: [], otherAxes: []}
  65415. */
  65416. getTooltipAxes: function (dim) {
  65417. var baseAxis = (dim != null && dim !== 'auto')
  65418. ? this.getAxis(dim) : this.getBaseAxis();
  65419. return {
  65420. baseAxes: [baseAxis],
  65421. otherAxes: [this.getOtherAxis(baseAxis)]
  65422. };
  65423. },
  65424. /**
  65425. * Convert a single data item to (x, y) point.
  65426. * Parameter data is an array which the first element is radius and the second is angle
  65427. * @param {Array.<number>} data
  65428. * @param {boolean} [clamp=false]
  65429. * @return {Array.<number>}
  65430. */
  65431. dataToPoint: function (data, clamp) {
  65432. return this.coordToPoint([
  65433. this._radiusAxis.dataToRadius(data[0], clamp),
  65434. this._angleAxis.dataToAngle(data[1], clamp)
  65435. ]);
  65436. },
  65437. /**
  65438. * Convert a (x, y) point to data
  65439. * @param {Array.<number>} point
  65440. * @param {boolean} [clamp=false]
  65441. * @return {Array.<number>}
  65442. */
  65443. pointToData: function (point, clamp) {
  65444. var coord = this.pointToCoord(point);
  65445. return [
  65446. this._radiusAxis.radiusToData(coord[0], clamp),
  65447. this._angleAxis.angleToData(coord[1], clamp)
  65448. ];
  65449. },
  65450. /**
  65451. * Convert a (x, y) point to (radius, angle) coord
  65452. * @param {Array.<number>} point
  65453. * @return {Array.<number>}
  65454. */
  65455. pointToCoord: function (point) {
  65456. var dx = point[0] - this.cx;
  65457. var dy = point[1] - this.cy;
  65458. var angleAxis = this.getAngleAxis();
  65459. var extent = angleAxis.getExtent();
  65460. var minAngle = Math.min(extent[0], extent[1]);
  65461. var maxAngle = Math.max(extent[0], extent[1]);
  65462. // Fix fixed extent in polarCreator
  65463. // FIXME
  65464. angleAxis.inverse
  65465. ? (minAngle = maxAngle - 360)
  65466. : (maxAngle = minAngle + 360);
  65467. var radius = Math.sqrt(dx * dx + dy * dy);
  65468. dx /= radius;
  65469. dy /= radius;
  65470. var radian = Math.atan2(-dy, dx) / Math.PI * 180;
  65471. // move to angleExtent
  65472. var dir = radian < minAngle ? 1 : -1;
  65473. while (radian < minAngle || radian > maxAngle) {
  65474. radian += dir * 360;
  65475. }
  65476. return [radius, radian];
  65477. },
  65478. /**
  65479. * Convert a (radius, angle) coord to (x, y) point
  65480. * @param {Array.<number>} coord
  65481. * @return {Array.<number>}
  65482. */
  65483. coordToPoint: function (coord) {
  65484. var radius = coord[0];
  65485. var radian = coord[1] / 180 * Math.PI;
  65486. var x = Math.cos(radian) * radius + this.cx;
  65487. // Inverse the y
  65488. var y = -Math.sin(radian) * radius + this.cy;
  65489. return [x, y];
  65490. }
  65491. };
  65492. /*
  65493. * Licensed to the Apache Software Foundation (ASF) under one
  65494. * or more contributor license agreements. See the NOTICE file
  65495. * distributed with this work for additional information
  65496. * regarding copyright ownership. The ASF licenses this file
  65497. * to you under the Apache License, Version 2.0 (the
  65498. * "License"); you may not use this file except in compliance
  65499. * with the License. You may obtain a copy of the License at
  65500. *
  65501. * http://www.apache.org/licenses/LICENSE-2.0
  65502. *
  65503. * Unless required by applicable law or agreed to in writing,
  65504. * software distributed under the License is distributed on an
  65505. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65506. * KIND, either express or implied. See the License for the
  65507. * specific language governing permissions and limitations
  65508. * under the License.
  65509. */
  65510. var PolarAxisModel = ComponentModel.extend({
  65511. type: 'polarAxis',
  65512. /**
  65513. * @type {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  65514. */
  65515. axis: null,
  65516. /**
  65517. * @override
  65518. */
  65519. getCoordSysModel: function () {
  65520. return this.ecModel.queryComponents({
  65521. mainType: 'polar',
  65522. index: this.option.polarIndex,
  65523. id: this.option.polarId
  65524. })[0];
  65525. }
  65526. });
  65527. merge(PolarAxisModel.prototype, axisModelCommonMixin);
  65528. var polarAxisDefaultExtendedOption = {
  65529. angle: {
  65530. // polarIndex: 0,
  65531. // polarId: '',
  65532. startAngle: 90,
  65533. clockwise: true,
  65534. splitNumber: 12,
  65535. axisLabel: {
  65536. rotate: false
  65537. }
  65538. },
  65539. radius: {
  65540. // polarIndex: 0,
  65541. // polarId: '',
  65542. splitNumber: 5
  65543. }
  65544. };
  65545. function getAxisType$3(axisDim, option) {
  65546. // Default axis with data is category axis
  65547. return option.type || (option.data ? 'category' : 'value');
  65548. }
  65549. axisModelCreator('angle', PolarAxisModel, getAxisType$3, polarAxisDefaultExtendedOption.angle);
  65550. axisModelCreator('radius', PolarAxisModel, getAxisType$3, polarAxisDefaultExtendedOption.radius);
  65551. /*
  65552. * Licensed to the Apache Software Foundation (ASF) under one
  65553. * or more contributor license agreements. See the NOTICE file
  65554. * distributed with this work for additional information
  65555. * regarding copyright ownership. The ASF licenses this file
  65556. * to you under the Apache License, Version 2.0 (the
  65557. * "License"); you may not use this file except in compliance
  65558. * with the License. You may obtain a copy of the License at
  65559. *
  65560. * http://www.apache.org/licenses/LICENSE-2.0
  65561. *
  65562. * Unless required by applicable law or agreed to in writing,
  65563. * software distributed under the License is distributed on an
  65564. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65565. * KIND, either express or implied. See the License for the
  65566. * specific language governing permissions and limitations
  65567. * under the License.
  65568. */
  65569. extendComponentModel({
  65570. type: 'polar',
  65571. dependencies: ['polarAxis', 'angleAxis'],
  65572. /**
  65573. * @type {module:echarts/coord/polar/Polar}
  65574. */
  65575. coordinateSystem: null,
  65576. /**
  65577. * @param {string} axisType
  65578. * @return {module:echarts/coord/polar/AxisModel}
  65579. */
  65580. findAxisModel: function (axisType) {
  65581. var foundAxisModel;
  65582. var ecModel = this.ecModel;
  65583. ecModel.eachComponent(axisType, function (axisModel) {
  65584. if (axisModel.getCoordSysModel() === this) {
  65585. foundAxisModel = axisModel;
  65586. }
  65587. }, this);
  65588. return foundAxisModel;
  65589. },
  65590. defaultOption: {
  65591. zlevel: 0,
  65592. z: 0,
  65593. center: ['50%', '50%'],
  65594. radius: '80%'
  65595. }
  65596. });
  65597. /*
  65598. * Licensed to the Apache Software Foundation (ASF) under one
  65599. * or more contributor license agreements. See the NOTICE file
  65600. * distributed with this work for additional information
  65601. * regarding copyright ownership. The ASF licenses this file
  65602. * to you under the Apache License, Version 2.0 (the
  65603. * "License"); you may not use this file except in compliance
  65604. * with the License. You may obtain a copy of the License at
  65605. *
  65606. * http://www.apache.org/licenses/LICENSE-2.0
  65607. *
  65608. * Unless required by applicable law or agreed to in writing,
  65609. * software distributed under the License is distributed on an
  65610. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65611. * KIND, either express or implied. See the License for the
  65612. * specific language governing permissions and limitations
  65613. * under the License.
  65614. */
  65615. // TODO Axis scale
  65616. /**
  65617. * Resize method bound to the polar
  65618. * @param {module:echarts/coord/polar/PolarModel} polarModel
  65619. * @param {module:echarts/ExtensionAPI} api
  65620. */
  65621. function resizePolar(polar, polarModel, api) {
  65622. var center = polarModel.get('center');
  65623. var width = api.getWidth();
  65624. var height = api.getHeight();
  65625. polar.cx = parsePercent$1(center[0], width);
  65626. polar.cy = parsePercent$1(center[1], height);
  65627. var radiusAxis = polar.getRadiusAxis();
  65628. var size = Math.min(width, height) / 2;
  65629. var radius = parsePercent$1(polarModel.get('radius'), size);
  65630. radiusAxis.inverse
  65631. ? radiusAxis.setExtent(radius, 0)
  65632. : radiusAxis.setExtent(0, radius);
  65633. }
  65634. /**
  65635. * Update polar
  65636. */
  65637. function updatePolarScale(ecModel, api) {
  65638. var polar = this;
  65639. var angleAxis = polar.getAngleAxis();
  65640. var radiusAxis = polar.getRadiusAxis();
  65641. // Reset scale
  65642. angleAxis.scale.setExtent(Infinity, -Infinity);
  65643. radiusAxis.scale.setExtent(Infinity, -Infinity);
  65644. ecModel.eachSeries(function (seriesModel) {
  65645. if (seriesModel.coordinateSystem === polar) {
  65646. var data = seriesModel.getData();
  65647. each$1(data.mapDimension('radius', true), function (dim) {
  65648. radiusAxis.scale.unionExtentFromData(
  65649. data, getStackedDimension(data, dim)
  65650. );
  65651. });
  65652. each$1(data.mapDimension('angle', true), function (dim) {
  65653. angleAxis.scale.unionExtentFromData(
  65654. data, getStackedDimension(data, dim)
  65655. );
  65656. });
  65657. }
  65658. });
  65659. niceScaleExtent(angleAxis.scale, angleAxis.model);
  65660. niceScaleExtent(radiusAxis.scale, radiusAxis.model);
  65661. // Fix extent of category angle axis
  65662. if (angleAxis.type === 'category' && !angleAxis.onBand) {
  65663. var extent = angleAxis.getExtent();
  65664. var diff = 360 / angleAxis.scale.count();
  65665. angleAxis.inverse ? (extent[1] += diff) : (extent[1] -= diff);
  65666. angleAxis.setExtent(extent[0], extent[1]);
  65667. }
  65668. }
  65669. /**
  65670. * Set common axis properties
  65671. * @param {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  65672. * @param {module:echarts/coord/polar/AxisModel}
  65673. * @inner
  65674. */
  65675. function setAxis(axis, axisModel) {
  65676. axis.type = axisModel.get('type');
  65677. axis.scale = createScaleByModel(axisModel);
  65678. axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category';
  65679. axis.inverse = axisModel.get('inverse');
  65680. if (axisModel.mainType === 'angleAxis') {
  65681. axis.inverse ^= axisModel.get('clockwise');
  65682. var startAngle = axisModel.get('startAngle');
  65683. axis.setExtent(startAngle, startAngle + (axis.inverse ? -360 : 360));
  65684. }
  65685. // Inject axis instance
  65686. axisModel.axis = axis;
  65687. axis.model = axisModel;
  65688. }
  65689. var polarCreator = {
  65690. dimensions: Polar.prototype.dimensions,
  65691. create: function (ecModel, api) {
  65692. var polarList = [];
  65693. ecModel.eachComponent('polar', function (polarModel, idx) {
  65694. var polar = new Polar(idx);
  65695. // Inject resize and update method
  65696. polar.update = updatePolarScale;
  65697. var radiusAxis = polar.getRadiusAxis();
  65698. var angleAxis = polar.getAngleAxis();
  65699. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  65700. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  65701. setAxis(radiusAxis, radiusAxisModel);
  65702. setAxis(angleAxis, angleAxisModel);
  65703. resizePolar(polar, polarModel, api);
  65704. polarList.push(polar);
  65705. polarModel.coordinateSystem = polar;
  65706. polar.model = polarModel;
  65707. });
  65708. // Inject coordinateSystem to series
  65709. ecModel.eachSeries(function (seriesModel) {
  65710. if (seriesModel.get('coordinateSystem') === 'polar') {
  65711. var polarModel = ecModel.queryComponents({
  65712. mainType: 'polar',
  65713. index: seriesModel.get('polarIndex'),
  65714. id: seriesModel.get('polarId')
  65715. })[0];
  65716. if (__DEV__) {
  65717. if (!polarModel) {
  65718. throw new Error(
  65719. 'Polar "' + retrieve(
  65720. seriesModel.get('polarIndex'),
  65721. seriesModel.get('polarId'),
  65722. 0
  65723. ) + '" not found'
  65724. );
  65725. }
  65726. }
  65727. seriesModel.coordinateSystem = polarModel.coordinateSystem;
  65728. }
  65729. });
  65730. return polarList;
  65731. }
  65732. };
  65733. CoordinateSystemManager.register('polar', polarCreator);
  65734. /*
  65735. * Licensed to the Apache Software Foundation (ASF) under one
  65736. * or more contributor license agreements. See the NOTICE file
  65737. * distributed with this work for additional information
  65738. * regarding copyright ownership. The ASF licenses this file
  65739. * to you under the Apache License, Version 2.0 (the
  65740. * "License"); you may not use this file except in compliance
  65741. * with the License. You may obtain a copy of the License at
  65742. *
  65743. * http://www.apache.org/licenses/LICENSE-2.0
  65744. *
  65745. * Unless required by applicable law or agreed to in writing,
  65746. * software distributed under the License is distributed on an
  65747. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65748. * KIND, either express or implied. See the License for the
  65749. * specific language governing permissions and limitations
  65750. * under the License.
  65751. */
  65752. var elementList$1 = ['axisLine', 'axisLabel', 'axisTick', 'splitLine', 'splitArea'];
  65753. function getAxisLineShape(polar, rExtent, angle) {
  65754. rExtent[1] > rExtent[0] && (rExtent = rExtent.slice().reverse());
  65755. var start = polar.coordToPoint([rExtent[0], angle]);
  65756. var end = polar.coordToPoint([rExtent[1], angle]);
  65757. return {
  65758. x1: start[0],
  65759. y1: start[1],
  65760. x2: end[0],
  65761. y2: end[1]
  65762. };
  65763. }
  65764. function getRadiusIdx(polar) {
  65765. var radiusAxis = polar.getRadiusAxis();
  65766. return radiusAxis.inverse ? 0 : 1;
  65767. }
  65768. // Remove the last tick which will overlap the first tick
  65769. function fixAngleOverlap(list) {
  65770. var firstItem = list[0];
  65771. var lastItem = list[list.length - 1];
  65772. if (firstItem
  65773. && lastItem
  65774. && Math.abs(Math.abs(firstItem.coord - lastItem.coord) - 360) < 1e-4
  65775. ) {
  65776. list.pop();
  65777. }
  65778. }
  65779. AxisView.extend({
  65780. type: 'angleAxis',
  65781. axisPointerClass: 'PolarAxisPointer',
  65782. render: function (angleAxisModel, ecModel) {
  65783. this.group.removeAll();
  65784. if (!angleAxisModel.get('show')) {
  65785. return;
  65786. }
  65787. var angleAxis = angleAxisModel.axis;
  65788. var polar = angleAxis.polar;
  65789. var radiusExtent = polar.getRadiusAxis().getExtent();
  65790. var ticksAngles = angleAxis.getTicksCoords();
  65791. var labels = map(angleAxis.getViewLabels(), function (labelItem) {
  65792. var labelItem = clone(labelItem);
  65793. labelItem.coord = angleAxis.dataToCoord(labelItem.tickValue);
  65794. return labelItem;
  65795. });
  65796. fixAngleOverlap(labels);
  65797. fixAngleOverlap(ticksAngles);
  65798. each$1(elementList$1, function (name) {
  65799. if (angleAxisModel.get(name + '.show')
  65800. && (!angleAxis.scale.isBlank() || name === 'axisLine')
  65801. ) {
  65802. this['_' + name](angleAxisModel, polar, ticksAngles, radiusExtent, labels);
  65803. }
  65804. }, this);
  65805. },
  65806. /**
  65807. * @private
  65808. */
  65809. _axisLine: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  65810. var lineStyleModel = angleAxisModel.getModel('axisLine.lineStyle');
  65811. var circle = new Circle({
  65812. shape: {
  65813. cx: polar.cx,
  65814. cy: polar.cy,
  65815. r: radiusExtent[getRadiusIdx(polar)]
  65816. },
  65817. style: lineStyleModel.getLineStyle(),
  65818. z2: 1,
  65819. silent: true
  65820. });
  65821. circle.style.fill = null;
  65822. this.group.add(circle);
  65823. },
  65824. /**
  65825. * @private
  65826. */
  65827. _axisTick: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  65828. var tickModel = angleAxisModel.getModel('axisTick');
  65829. var tickLen = (tickModel.get('inside') ? -1 : 1) * tickModel.get('length');
  65830. var radius = radiusExtent[getRadiusIdx(polar)];
  65831. var lines = map(ticksAngles, function (tickAngleItem) {
  65832. return new Line({
  65833. shape: getAxisLineShape(polar, [radius, radius + tickLen], tickAngleItem.coord)
  65834. });
  65835. });
  65836. this.group.add(mergePath(
  65837. lines, {
  65838. style: defaults(
  65839. tickModel.getModel('lineStyle').getLineStyle(),
  65840. {
  65841. stroke: angleAxisModel.get('axisLine.lineStyle.color')
  65842. }
  65843. )
  65844. }
  65845. ));
  65846. },
  65847. /**
  65848. * @private
  65849. */
  65850. _axisLabel: function (angleAxisModel, polar, ticksAngles, radiusExtent, labels) {
  65851. var rawCategoryData = angleAxisModel.getCategories(true);
  65852. var commonLabelModel = angleAxisModel.getModel('axisLabel');
  65853. var labelMargin = commonLabelModel.get('margin');
  65854. // Use length of ticksAngles because it may remove the last tick to avoid overlapping
  65855. each$1(labels, function (labelItem, idx) {
  65856. var labelModel = commonLabelModel;
  65857. var tickValue = labelItem.tickValue;
  65858. var r = radiusExtent[getRadiusIdx(polar)];
  65859. var p = polar.coordToPoint([r + labelMargin, labelItem.coord]);
  65860. var cx = polar.cx;
  65861. var cy = polar.cy;
  65862. var labelTextAlign = Math.abs(p[0] - cx) / r < 0.3
  65863. ? 'center' : (p[0] > cx ? 'left' : 'right');
  65864. var labelTextVerticalAlign = Math.abs(p[1] - cy) / r < 0.3
  65865. ? 'middle' : (p[1] > cy ? 'top' : 'bottom');
  65866. if (rawCategoryData && rawCategoryData[tickValue] && rawCategoryData[tickValue].textStyle) {
  65867. labelModel = new Model(
  65868. rawCategoryData[tickValue].textStyle, commonLabelModel, commonLabelModel.ecModel
  65869. );
  65870. }
  65871. var textEl = new Text({silent: true});
  65872. this.group.add(textEl);
  65873. setTextStyle(textEl.style, labelModel, {
  65874. x: p[0],
  65875. y: p[1],
  65876. textFill: labelModel.getTextColor() || angleAxisModel.get('axisLine.lineStyle.color'),
  65877. text: labelItem.formattedLabel,
  65878. textAlign: labelTextAlign,
  65879. textVerticalAlign: labelTextVerticalAlign
  65880. });
  65881. }, this);
  65882. },
  65883. /**
  65884. * @private
  65885. */
  65886. _splitLine: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  65887. var splitLineModel = angleAxisModel.getModel('splitLine');
  65888. var lineStyleModel = splitLineModel.getModel('lineStyle');
  65889. var lineColors = lineStyleModel.get('color');
  65890. var lineCount = 0;
  65891. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  65892. var splitLines = [];
  65893. for (var i = 0; i < ticksAngles.length; i++) {
  65894. var colorIndex = (lineCount++) % lineColors.length;
  65895. splitLines[colorIndex] = splitLines[colorIndex] || [];
  65896. splitLines[colorIndex].push(new Line({
  65897. shape: getAxisLineShape(polar, radiusExtent, ticksAngles[i].coord)
  65898. }));
  65899. }
  65900. // Simple optimization
  65901. // Batching the lines if color are the same
  65902. for (var i = 0; i < splitLines.length; i++) {
  65903. this.group.add(mergePath(splitLines[i], {
  65904. style: defaults({
  65905. stroke: lineColors[i % lineColors.length]
  65906. }, lineStyleModel.getLineStyle()),
  65907. silent: true,
  65908. z: angleAxisModel.get('z')
  65909. }));
  65910. }
  65911. },
  65912. /**
  65913. * @private
  65914. */
  65915. _splitArea: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  65916. if (!ticksAngles.length) {
  65917. return;
  65918. }
  65919. var splitAreaModel = angleAxisModel.getModel('splitArea');
  65920. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  65921. var areaColors = areaStyleModel.get('color');
  65922. var lineCount = 0;
  65923. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  65924. var splitAreas = [];
  65925. var RADIAN = Math.PI / 180;
  65926. var prevAngle = -ticksAngles[0].coord * RADIAN;
  65927. var r0 = Math.min(radiusExtent[0], radiusExtent[1]);
  65928. var r1 = Math.max(radiusExtent[0], radiusExtent[1]);
  65929. var clockwise = angleAxisModel.get('clockwise');
  65930. for (var i = 1; i < ticksAngles.length; i++) {
  65931. var colorIndex = (lineCount++) % areaColors.length;
  65932. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  65933. splitAreas[colorIndex].push(new Sector({
  65934. shape: {
  65935. cx: polar.cx,
  65936. cy: polar.cy,
  65937. r0: r0,
  65938. r: r1,
  65939. startAngle: prevAngle,
  65940. endAngle: -ticksAngles[i].coord * RADIAN,
  65941. clockwise: clockwise
  65942. },
  65943. silent: true
  65944. }));
  65945. prevAngle = -ticksAngles[i].coord * RADIAN;
  65946. }
  65947. // Simple optimization
  65948. // Batching the lines if color are the same
  65949. for (var i = 0; i < splitAreas.length; i++) {
  65950. this.group.add(mergePath(splitAreas[i], {
  65951. style: defaults({
  65952. fill: areaColors[i % areaColors.length]
  65953. }, areaStyleModel.getAreaStyle()),
  65954. silent: true
  65955. }));
  65956. }
  65957. }
  65958. });
  65959. /*
  65960. * Licensed to the Apache Software Foundation (ASF) under one
  65961. * or more contributor license agreements. See the NOTICE file
  65962. * distributed with this work for additional information
  65963. * regarding copyright ownership. The ASF licenses this file
  65964. * to you under the Apache License, Version 2.0 (the
  65965. * "License"); you may not use this file except in compliance
  65966. * with the License. You may obtain a copy of the License at
  65967. *
  65968. * http://www.apache.org/licenses/LICENSE-2.0
  65969. *
  65970. * Unless required by applicable law or agreed to in writing,
  65971. * software distributed under the License is distributed on an
  65972. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65973. * KIND, either express or implied. See the License for the
  65974. * specific language governing permissions and limitations
  65975. * under the License.
  65976. */
  65977. /*
  65978. * Licensed to the Apache Software Foundation (ASF) under one
  65979. * or more contributor license agreements. See the NOTICE file
  65980. * distributed with this work for additional information
  65981. * regarding copyright ownership. The ASF licenses this file
  65982. * to you under the Apache License, Version 2.0 (the
  65983. * "License"); you may not use this file except in compliance
  65984. * with the License. You may obtain a copy of the License at
  65985. *
  65986. * http://www.apache.org/licenses/LICENSE-2.0
  65987. *
  65988. * Unless required by applicable law or agreed to in writing,
  65989. * software distributed under the License is distributed on an
  65990. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65991. * KIND, either express or implied. See the License for the
  65992. * specific language governing permissions and limitations
  65993. * under the License.
  65994. */
  65995. var axisBuilderAttrs$3 = [
  65996. 'axisLine', 'axisTickLabel', 'axisName'
  65997. ];
  65998. var selfBuilderAttrs$1 = [
  65999. 'splitLine', 'splitArea'
  66000. ];
  66001. AxisView.extend({
  66002. type: 'radiusAxis',
  66003. axisPointerClass: 'PolarAxisPointer',
  66004. render: function (radiusAxisModel, ecModel) {
  66005. this.group.removeAll();
  66006. if (!radiusAxisModel.get('show')) {
  66007. return;
  66008. }
  66009. var radiusAxis = radiusAxisModel.axis;
  66010. var polar = radiusAxis.polar;
  66011. var angleAxis = polar.getAngleAxis();
  66012. var ticksCoords = radiusAxis.getTicksCoords();
  66013. var axisAngle = angleAxis.getExtent()[0];
  66014. var radiusExtent = radiusAxis.getExtent();
  66015. var layout = layoutAxis(polar, radiusAxisModel, axisAngle);
  66016. var axisBuilder = new AxisBuilder(radiusAxisModel, layout);
  66017. each$1(axisBuilderAttrs$3, axisBuilder.add, axisBuilder);
  66018. this.group.add(axisBuilder.getGroup());
  66019. each$1(selfBuilderAttrs$1, function (name) {
  66020. if (radiusAxisModel.get(name + '.show') && !radiusAxis.scale.isBlank()) {
  66021. this['_' + name](radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords);
  66022. }
  66023. }, this);
  66024. },
  66025. /**
  66026. * @private
  66027. */
  66028. _splitLine: function (radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  66029. var splitLineModel = radiusAxisModel.getModel('splitLine');
  66030. var lineStyleModel = splitLineModel.getModel('lineStyle');
  66031. var lineColors = lineStyleModel.get('color');
  66032. var lineCount = 0;
  66033. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  66034. var splitLines = [];
  66035. for (var i = 0; i < ticksCoords.length; i++) {
  66036. var colorIndex = (lineCount++) % lineColors.length;
  66037. splitLines[colorIndex] = splitLines[colorIndex] || [];
  66038. splitLines[colorIndex].push(new Circle({
  66039. shape: {
  66040. cx: polar.cx,
  66041. cy: polar.cy,
  66042. r: ticksCoords[i].coord
  66043. },
  66044. silent: true
  66045. }));
  66046. }
  66047. // Simple optimization
  66048. // Batching the lines if color are the same
  66049. for (var i = 0; i < splitLines.length; i++) {
  66050. this.group.add(mergePath(splitLines[i], {
  66051. style: defaults({
  66052. stroke: lineColors[i % lineColors.length],
  66053. fill: null
  66054. }, lineStyleModel.getLineStyle()),
  66055. silent: true
  66056. }));
  66057. }
  66058. },
  66059. /**
  66060. * @private
  66061. */
  66062. _splitArea: function (radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  66063. if (!ticksCoords.length) {
  66064. return;
  66065. }
  66066. var splitAreaModel = radiusAxisModel.getModel('splitArea');
  66067. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  66068. var areaColors = areaStyleModel.get('color');
  66069. var lineCount = 0;
  66070. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  66071. var splitAreas = [];
  66072. var prevRadius = ticksCoords[0].coord;
  66073. for (var i = 1; i < ticksCoords.length; i++) {
  66074. var colorIndex = (lineCount++) % areaColors.length;
  66075. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  66076. splitAreas[colorIndex].push(new Sector({
  66077. shape: {
  66078. cx: polar.cx,
  66079. cy: polar.cy,
  66080. r0: prevRadius,
  66081. r: ticksCoords[i].coord,
  66082. startAngle: 0,
  66083. endAngle: Math.PI * 2
  66084. },
  66085. silent: true
  66086. }));
  66087. prevRadius = ticksCoords[i].coord;
  66088. }
  66089. // Simple optimization
  66090. // Batching the lines if color are the same
  66091. for (var i = 0; i < splitAreas.length; i++) {
  66092. this.group.add(mergePath(splitAreas[i], {
  66093. style: defaults({
  66094. fill: areaColors[i % areaColors.length]
  66095. }, areaStyleModel.getAreaStyle()),
  66096. silent: true
  66097. }));
  66098. }
  66099. }
  66100. });
  66101. /**
  66102. * @inner
  66103. */
  66104. function layoutAxis(polar, radiusAxisModel, axisAngle) {
  66105. return {
  66106. position: [polar.cx, polar.cy],
  66107. rotation: axisAngle / 180 * Math.PI,
  66108. labelDirection: -1,
  66109. tickDirection: -1,
  66110. nameDirection: 1,
  66111. labelRotate: radiusAxisModel.getModel('axisLabel').get('rotate'),
  66112. // Over splitLine and splitArea
  66113. z2: 1
  66114. };
  66115. }
  66116. /*
  66117. * Licensed to the Apache Software Foundation (ASF) under one
  66118. * or more contributor license agreements. See the NOTICE file
  66119. * distributed with this work for additional information
  66120. * regarding copyright ownership. The ASF licenses this file
  66121. * to you under the Apache License, Version 2.0 (the
  66122. * "License"); you may not use this file except in compliance
  66123. * with the License. You may obtain a copy of the License at
  66124. *
  66125. * http://www.apache.org/licenses/LICENSE-2.0
  66126. *
  66127. * Unless required by applicable law or agreed to in writing,
  66128. * software distributed under the License is distributed on an
  66129. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66130. * KIND, either express or implied. See the License for the
  66131. * specific language governing permissions and limitations
  66132. * under the License.
  66133. */
  66134. /*
  66135. * Licensed to the Apache Software Foundation (ASF) under one
  66136. * or more contributor license agreements. See the NOTICE file
  66137. * distributed with this work for additional information
  66138. * regarding copyright ownership. The ASF licenses this file
  66139. * to you under the Apache License, Version 2.0 (the
  66140. * "License"); you may not use this file except in compliance
  66141. * with the License. You may obtain a copy of the License at
  66142. *
  66143. * http://www.apache.org/licenses/LICENSE-2.0
  66144. *
  66145. * Unless required by applicable law or agreed to in writing,
  66146. * software distributed under the License is distributed on an
  66147. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66148. * KIND, either express or implied. See the License for the
  66149. * specific language governing permissions and limitations
  66150. * under the License.
  66151. */
  66152. var PolarAxisPointer = BaseAxisPointer.extend({
  66153. /**
  66154. * @override
  66155. */
  66156. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  66157. var axis = axisModel.axis;
  66158. if (axis.dim === 'angle') {
  66159. this.animationThreshold = Math.PI / 18;
  66160. }
  66161. var polar = axis.polar;
  66162. var otherAxis = polar.getOtherAxis(axis);
  66163. var otherExtent = otherAxis.getExtent();
  66164. var coordValue;
  66165. coordValue = axis['dataTo' + capitalFirst(axis.dim)](value);
  66166. var axisPointerType = axisPointerModel.get('type');
  66167. if (axisPointerType && axisPointerType !== 'none') {
  66168. var elStyle = buildElStyle(axisPointerModel);
  66169. var pointerOption = pointerShapeBuilder$2[axisPointerType](
  66170. axis, polar, coordValue, otherExtent, elStyle
  66171. );
  66172. pointerOption.style = elStyle;
  66173. elOption.graphicKey = pointerOption.type;
  66174. elOption.pointer = pointerOption;
  66175. }
  66176. var labelMargin = axisPointerModel.get('label.margin');
  66177. var labelPos = getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin);
  66178. buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos);
  66179. }
  66180. // Do not support handle, utill any user requires it.
  66181. });
  66182. function getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin) {
  66183. var axis = axisModel.axis;
  66184. var coord = axis.dataToCoord(value);
  66185. var axisAngle = polar.getAngleAxis().getExtent()[0];
  66186. axisAngle = axisAngle / 180 * Math.PI;
  66187. var radiusExtent = polar.getRadiusAxis().getExtent();
  66188. var position;
  66189. var align;
  66190. var verticalAlign;
  66191. if (axis.dim === 'radius') {
  66192. var transform = create$1();
  66193. rotate(transform, transform, axisAngle);
  66194. translate(transform, transform, [polar.cx, polar.cy]);
  66195. position = applyTransform$1([coord, -labelMargin], transform);
  66196. var labelRotation = axisModel.getModel('axisLabel').get('rotate') || 0;
  66197. var labelLayout = AxisBuilder.innerTextLayout(
  66198. axisAngle, labelRotation * Math.PI / 180, -1
  66199. );
  66200. align = labelLayout.textAlign;
  66201. verticalAlign = labelLayout.textVerticalAlign;
  66202. }
  66203. else { // angle axis
  66204. var r = radiusExtent[1];
  66205. position = polar.coordToPoint([r + labelMargin, coord]);
  66206. var cx = polar.cx;
  66207. var cy = polar.cy;
  66208. align = Math.abs(position[0] - cx) / r < 0.3
  66209. ? 'center' : (position[0] > cx ? 'left' : 'right');
  66210. verticalAlign = Math.abs(position[1] - cy) / r < 0.3
  66211. ? 'middle' : (position[1] > cy ? 'top' : 'bottom');
  66212. }
  66213. return {
  66214. position: position,
  66215. align: align,
  66216. verticalAlign: verticalAlign
  66217. };
  66218. }
  66219. var pointerShapeBuilder$2 = {
  66220. line: function (axis, polar, coordValue, otherExtent, elStyle) {
  66221. return axis.dim === 'angle'
  66222. ? {
  66223. type: 'Line',
  66224. shape: makeLineShape(
  66225. polar.coordToPoint([otherExtent[0], coordValue]),
  66226. polar.coordToPoint([otherExtent[1], coordValue])
  66227. )
  66228. }
  66229. : {
  66230. type: 'Circle',
  66231. shape: {
  66232. cx: polar.cx,
  66233. cy: polar.cy,
  66234. r: coordValue
  66235. }
  66236. };
  66237. },
  66238. shadow: function (axis, polar, coordValue, otherExtent, elStyle) {
  66239. var bandWidth = Math.max(1, axis.getBandWidth());
  66240. var radian = Math.PI / 180;
  66241. return axis.dim === 'angle'
  66242. ? {
  66243. type: 'Sector',
  66244. shape: makeSectorShape(
  66245. polar.cx, polar.cy,
  66246. otherExtent[0], otherExtent[1],
  66247. // In ECharts y is negative if angle is positive
  66248. (-coordValue - bandWidth / 2) * radian,
  66249. (-coordValue + bandWidth / 2) * radian
  66250. )
  66251. }
  66252. : {
  66253. type: 'Sector',
  66254. shape: makeSectorShape(
  66255. polar.cx, polar.cy,
  66256. coordValue - bandWidth / 2,
  66257. coordValue + bandWidth / 2,
  66258. 0, Math.PI * 2
  66259. )
  66260. };
  66261. }
  66262. };
  66263. AxisView.registerAxisPointerClass('PolarAxisPointer', PolarAxisPointer);
  66264. /*
  66265. * Licensed to the Apache Software Foundation (ASF) under one
  66266. * or more contributor license agreements. See the NOTICE file
  66267. * distributed with this work for additional information
  66268. * regarding copyright ownership. The ASF licenses this file
  66269. * to you under the Apache License, Version 2.0 (the
  66270. * "License"); you may not use this file except in compliance
  66271. * with the License. You may obtain a copy of the License at
  66272. *
  66273. * http://www.apache.org/licenses/LICENSE-2.0
  66274. *
  66275. * Unless required by applicable law or agreed to in writing,
  66276. * software distributed under the License is distributed on an
  66277. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66278. * KIND, either express or implied. See the License for the
  66279. * specific language governing permissions and limitations
  66280. * under the License.
  66281. */
  66282. // For reducing size of echarts.min, barLayoutPolar is required by polar.
  66283. registerLayout(curry(barLayoutPolar, 'bar'));
  66284. // Polar view
  66285. extendComponentView({
  66286. type: 'polar'
  66287. });
  66288. /*
  66289. * Licensed to the Apache Software Foundation (ASF) under one
  66290. * or more contributor license agreements. See the NOTICE file
  66291. * distributed with this work for additional information
  66292. * regarding copyright ownership. The ASF licenses this file
  66293. * to you under the Apache License, Version 2.0 (the
  66294. * "License"); you may not use this file except in compliance
  66295. * with the License. You may obtain a copy of the License at
  66296. *
  66297. * http://www.apache.org/licenses/LICENSE-2.0
  66298. *
  66299. * Unless required by applicable law or agreed to in writing,
  66300. * software distributed under the License is distributed on an
  66301. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66302. * KIND, either express or implied. See the License for the
  66303. * specific language governing permissions and limitations
  66304. * under the License.
  66305. */
  66306. var GeoModel = ComponentModel.extend({
  66307. type: 'geo',
  66308. /**
  66309. * @type {module:echarts/coord/geo/Geo}
  66310. */
  66311. coordinateSystem: null,
  66312. layoutMode: 'box',
  66313. init: function (option) {
  66314. ComponentModel.prototype.init.apply(this, arguments);
  66315. // Default label emphasis `show`
  66316. defaultEmphasis(option, 'label', ['show']);
  66317. },
  66318. optionUpdated: function () {
  66319. var option = this.option;
  66320. var self = this;
  66321. option.regions = geoCreator.getFilledRegions(option.regions, option.map, option.nameMap);
  66322. this._optionModelMap = reduce(option.regions || [], function (optionModelMap, regionOpt) {
  66323. if (regionOpt.name) {
  66324. optionModelMap.set(regionOpt.name, new Model(regionOpt, self));
  66325. }
  66326. return optionModelMap;
  66327. }, createHashMap());
  66328. this.updateSelectedMap(option.regions);
  66329. },
  66330. defaultOption: {
  66331. zlevel: 0,
  66332. z: 0,
  66333. show: true,
  66334. left: 'center',
  66335. top: 'center',
  66336. // width:,
  66337. // height:,
  66338. // right
  66339. // bottom
  66340. // Aspect is width / height. Inited to be geoJson bbox aspect
  66341. // This parameter is used for scale this aspect
  66342. // If svg used, aspectScale is 1 by default.
  66343. // aspectScale: 0.75,
  66344. aspectScale: null,
  66345. ///// Layout with center and size
  66346. // If you wan't to put map in a fixed size box with right aspect ratio
  66347. // This two properties may more conveninet
  66348. // layoutCenter: [50%, 50%]
  66349. // layoutSize: 100
  66350. silent: false,
  66351. // Map type
  66352. map: '',
  66353. // Define left-top, right-bottom coords to control view
  66354. // For example, [ [180, 90], [-180, -90] ]
  66355. boundingCoords: null,
  66356. // Default on center of map
  66357. center: null,
  66358. zoom: 1,
  66359. scaleLimit: null,
  66360. // selectedMode: false
  66361. label: {
  66362. show: false,
  66363. color: '#000'
  66364. },
  66365. itemStyle: {
  66366. // color: 各异,
  66367. borderWidth: 0.5,
  66368. borderColor: '#444',
  66369. color: '#eee'
  66370. },
  66371. emphasis: {
  66372. label: {
  66373. show: true,
  66374. color: 'rgb(100,0,0)'
  66375. },
  66376. itemStyle: {
  66377. color: 'rgba(255,215,0,0.8)'
  66378. }
  66379. },
  66380. regions: []
  66381. },
  66382. /**
  66383. * Get model of region
  66384. * @param {string} name
  66385. * @return {module:echarts/model/Model}
  66386. */
  66387. getRegionModel: function (name) {
  66388. return this._optionModelMap.get(name) || new Model(null, this, this.ecModel);
  66389. },
  66390. /**
  66391. * Format label
  66392. * @param {string} name Region name
  66393. * @param {string} [status='normal'] 'normal' or 'emphasis'
  66394. * @return {string}
  66395. */
  66396. getFormattedLabel: function (name, status) {
  66397. var regionModel = this.getRegionModel(name);
  66398. var formatter = regionModel.get('label.' + status + '.formatter');
  66399. var params = {
  66400. name: name
  66401. };
  66402. if (typeof formatter === 'function') {
  66403. params.status = status;
  66404. return formatter(params);
  66405. }
  66406. else if (typeof formatter === 'string') {
  66407. return formatter.replace('{a}', name != null ? name : '');
  66408. }
  66409. },
  66410. setZoom: function (zoom) {
  66411. this.option.zoom = zoom;
  66412. },
  66413. setCenter: function (center) {
  66414. this.option.center = center;
  66415. }
  66416. });
  66417. mixin(GeoModel, selectableMixin);
  66418. /*
  66419. * Licensed to the Apache Software Foundation (ASF) under one
  66420. * or more contributor license agreements. See the NOTICE file
  66421. * distributed with this work for additional information
  66422. * regarding copyright ownership. The ASF licenses this file
  66423. * to you under the Apache License, Version 2.0 (the
  66424. * "License"); you may not use this file except in compliance
  66425. * with the License. You may obtain a copy of the License at
  66426. *
  66427. * http://www.apache.org/licenses/LICENSE-2.0
  66428. *
  66429. * Unless required by applicable law or agreed to in writing,
  66430. * software distributed under the License is distributed on an
  66431. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66432. * KIND, either express or implied. See the License for the
  66433. * specific language governing permissions and limitations
  66434. * under the License.
  66435. */
  66436. extendComponentView({
  66437. type: 'geo',
  66438. init: function (ecModel, api) {
  66439. var mapDraw = new MapDraw(api, true);
  66440. this._mapDraw = mapDraw;
  66441. this.group.add(mapDraw.group);
  66442. },
  66443. render: function (geoModel, ecModel, api, payload) {
  66444. // Not render if it is an toggleSelect action from self
  66445. if (payload && payload.type === 'geoToggleSelect'
  66446. && payload.from === this.uid
  66447. ) {
  66448. return;
  66449. }
  66450. var mapDraw = this._mapDraw;
  66451. if (geoModel.get('show')) {
  66452. mapDraw.draw(geoModel, ecModel, api, this, payload);
  66453. }
  66454. else {
  66455. this._mapDraw.group.removeAll();
  66456. }
  66457. this.group.silent = geoModel.get('silent');
  66458. },
  66459. dispose: function () {
  66460. this._mapDraw && this._mapDraw.remove();
  66461. }
  66462. });
  66463. /*
  66464. * Licensed to the Apache Software Foundation (ASF) under one
  66465. * or more contributor license agreements. See the NOTICE file
  66466. * distributed with this work for additional information
  66467. * regarding copyright ownership. The ASF licenses this file
  66468. * to you under the Apache License, Version 2.0 (the
  66469. * "License"); you may not use this file except in compliance
  66470. * with the License. You may obtain a copy of the License at
  66471. *
  66472. * http://www.apache.org/licenses/LICENSE-2.0
  66473. *
  66474. * Unless required by applicable law or agreed to in writing,
  66475. * software distributed under the License is distributed on an
  66476. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66477. * KIND, either express or implied. See the License for the
  66478. * specific language governing permissions and limitations
  66479. * under the License.
  66480. */
  66481. function makeAction(method, actionInfo) {
  66482. actionInfo.update = 'updateView';
  66483. registerAction(actionInfo, function (payload, ecModel) {
  66484. var selected = {};
  66485. ecModel.eachComponent(
  66486. { mainType: 'geo', query: payload},
  66487. function (geoModel) {
  66488. geoModel[method](payload.name);
  66489. var geo = geoModel.coordinateSystem;
  66490. each$1(geo.regions, function (region) {
  66491. selected[region.name] = geoModel.isSelected(region.name) || false;
  66492. });
  66493. }
  66494. );
  66495. return {
  66496. selected: selected,
  66497. name: payload.name
  66498. };
  66499. });
  66500. }
  66501. makeAction('toggleSelected', {
  66502. type: 'geoToggleSelect',
  66503. event: 'geoselectchanged'
  66504. });
  66505. makeAction('select', {
  66506. type: 'geoSelect',
  66507. event: 'geoselected'
  66508. });
  66509. makeAction('unSelect', {
  66510. type: 'geoUnSelect',
  66511. event: 'geounselected'
  66512. });
  66513. /*
  66514. * Licensed to the Apache Software Foundation (ASF) under one
  66515. * or more contributor license agreements. See the NOTICE file
  66516. * distributed with this work for additional information
  66517. * regarding copyright ownership. The ASF licenses this file
  66518. * to you under the Apache License, Version 2.0 (the
  66519. * "License"); you may not use this file except in compliance
  66520. * with the License. You may obtain a copy of the License at
  66521. *
  66522. * http://www.apache.org/licenses/LICENSE-2.0
  66523. *
  66524. * Unless required by applicable law or agreed to in writing,
  66525. * software distributed under the License is distributed on an
  66526. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66527. * KIND, either express or implied. See the License for the
  66528. * specific language governing permissions and limitations
  66529. * under the License.
  66530. */
  66531. var DEFAULT_TOOLBOX_BTNS = ['rect', 'polygon', 'keep', 'clear'];
  66532. var preprocessor$1 = function (option, isNew) {
  66533. var brushComponents = option && option.brush;
  66534. if (!isArray(brushComponents)) {
  66535. brushComponents = brushComponents ? [brushComponents] : [];
  66536. }
  66537. if (!brushComponents.length) {
  66538. return;
  66539. }
  66540. var brushComponentSpecifiedBtns = [];
  66541. each$1(brushComponents, function (brushOpt) {
  66542. var tbs = brushOpt.hasOwnProperty('toolbox')
  66543. ? brushOpt.toolbox : [];
  66544. if (tbs instanceof Array) {
  66545. brushComponentSpecifiedBtns = brushComponentSpecifiedBtns.concat(tbs);
  66546. }
  66547. });
  66548. var toolbox = option && option.toolbox;
  66549. if (isArray(toolbox)) {
  66550. toolbox = toolbox[0];
  66551. }
  66552. if (!toolbox) {
  66553. toolbox = {feature: {}};
  66554. option.toolbox = [toolbox];
  66555. }
  66556. var toolboxFeature = (toolbox.feature || (toolbox.feature = {}));
  66557. var toolboxBrush = toolboxFeature.brush || (toolboxFeature.brush = {});
  66558. var brushTypes = toolboxBrush.type || (toolboxBrush.type = []);
  66559. brushTypes.push.apply(brushTypes, brushComponentSpecifiedBtns);
  66560. removeDuplicate(brushTypes);
  66561. if (isNew && !brushTypes.length) {
  66562. brushTypes.push.apply(brushTypes, DEFAULT_TOOLBOX_BTNS);
  66563. }
  66564. };
  66565. function removeDuplicate(arr) {
  66566. var map$$1 = {};
  66567. each$1(arr, function (val) {
  66568. map$$1[val] = 1;
  66569. });
  66570. arr.length = 0;
  66571. each$1(map$$1, function (flag, val) {
  66572. arr.push(val);
  66573. });
  66574. }
  66575. /*
  66576. * Licensed to the Apache Software Foundation (ASF) under one
  66577. * or more contributor license agreements. See the NOTICE file
  66578. * distributed with this work for additional information
  66579. * regarding copyright ownership. The ASF licenses this file
  66580. * to you under the Apache License, Version 2.0 (the
  66581. * "License"); you may not use this file except in compliance
  66582. * with the License. You may obtain a copy of the License at
  66583. *
  66584. * http://www.apache.org/licenses/LICENSE-2.0
  66585. *
  66586. * Unless required by applicable law or agreed to in writing,
  66587. * software distributed under the License is distributed on an
  66588. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66589. * KIND, either express or implied. See the License for the
  66590. * specific language governing permissions and limitations
  66591. * under the License.
  66592. */
  66593. /**
  66594. * @file Visual solution, for consistent option specification.
  66595. */
  66596. var each$19 = each$1;
  66597. function hasKeys(obj) {
  66598. if (obj) {
  66599. for (var name in obj) {
  66600. if (obj.hasOwnProperty(name)) {
  66601. return true;
  66602. }
  66603. }
  66604. }
  66605. }
  66606. /**
  66607. * @param {Object} option
  66608. * @param {Array.<string>} stateList
  66609. * @param {Function} [supplementVisualOption]
  66610. * @return {Object} visualMappings <state, <visualType, module:echarts/visual/VisualMapping>>
  66611. */
  66612. function createVisualMappings(option, stateList, supplementVisualOption) {
  66613. var visualMappings = {};
  66614. each$19(stateList, function (state) {
  66615. var mappings = visualMappings[state] = createMappings();
  66616. each$19(option[state], function (visualData, visualType) {
  66617. if (!VisualMapping.isValidType(visualType)) {
  66618. return;
  66619. }
  66620. var mappingOption = {
  66621. type: visualType,
  66622. visual: visualData
  66623. };
  66624. supplementVisualOption && supplementVisualOption(mappingOption, state);
  66625. mappings[visualType] = new VisualMapping(mappingOption);
  66626. // Prepare a alpha for opacity, for some case that opacity
  66627. // is not supported, such as rendering using gradient color.
  66628. if (visualType === 'opacity') {
  66629. mappingOption = clone(mappingOption);
  66630. mappingOption.type = 'colorAlpha';
  66631. mappings.__hidden.__alphaForOpacity = new VisualMapping(mappingOption);
  66632. }
  66633. });
  66634. });
  66635. return visualMappings;
  66636. function createMappings() {
  66637. var Creater = function () {};
  66638. // Make sure hidden fields will not be visited by
  66639. // object iteration (with hasOwnProperty checking).
  66640. Creater.prototype.__hidden = Creater.prototype;
  66641. var obj = new Creater();
  66642. return obj;
  66643. }
  66644. }
  66645. /**
  66646. * @param {Object} thisOption
  66647. * @param {Object} newOption
  66648. * @param {Array.<string>} keys
  66649. */
  66650. function replaceVisualOption(thisOption, newOption, keys) {
  66651. // Visual attributes merge is not supported, otherwise it
  66652. // brings overcomplicated merge logic. See #2853. So if
  66653. // newOption has anyone of these keys, all of these keys
  66654. // will be reset. Otherwise, all keys remain.
  66655. var has;
  66656. each$1(keys, function (key) {
  66657. if (newOption.hasOwnProperty(key) && hasKeys(newOption[key])) {
  66658. has = true;
  66659. }
  66660. });
  66661. has && each$1(keys, function (key) {
  66662. if (newOption.hasOwnProperty(key) && hasKeys(newOption[key])) {
  66663. thisOption[key] = clone(newOption[key]);
  66664. }
  66665. else {
  66666. delete thisOption[key];
  66667. }
  66668. });
  66669. }
  66670. /**
  66671. * @param {Array.<string>} stateList
  66672. * @param {Object} visualMappings <state, Object.<visualType, module:echarts/visual/VisualMapping>>
  66673. * @param {module:echarts/data/List} list
  66674. * @param {Function} getValueState param: valueOrIndex, return: state.
  66675. * @param {object} [scope] Scope for getValueState
  66676. * @param {string} [dimension] Concrete dimension, if used.
  66677. */
  66678. // ???! handle brush?
  66679. function applyVisual(stateList, visualMappings, data, getValueState, scope, dimension) {
  66680. var visualTypesMap = {};
  66681. each$1(stateList, function (state) {
  66682. var visualTypes = VisualMapping.prepareVisualTypes(visualMappings[state]);
  66683. visualTypesMap[state] = visualTypes;
  66684. });
  66685. var dataIndex;
  66686. function getVisual(key) {
  66687. return data.getItemVisual(dataIndex, key);
  66688. }
  66689. function setVisual(key, value) {
  66690. data.setItemVisual(dataIndex, key, value);
  66691. }
  66692. if (dimension == null) {
  66693. data.each(eachItem);
  66694. }
  66695. else {
  66696. data.each([dimension], eachItem);
  66697. }
  66698. function eachItem(valueOrIndex, index) {
  66699. dataIndex = dimension == null ? valueOrIndex : index;
  66700. var rawDataItem = data.getRawDataItem(dataIndex);
  66701. // Consider performance
  66702. if (rawDataItem && rawDataItem.visualMap === false) {
  66703. return;
  66704. }
  66705. var valueState = getValueState.call(scope, valueOrIndex);
  66706. var mappings = visualMappings[valueState];
  66707. var visualTypes = visualTypesMap[valueState];
  66708. for (var i = 0, len = visualTypes.length; i < len; i++) {
  66709. var type = visualTypes[i];
  66710. mappings[type] && mappings[type].applyVisual(
  66711. valueOrIndex, getVisual, setVisual
  66712. );
  66713. }
  66714. }
  66715. }
  66716. /**
  66717. * @param {module:echarts/data/List} data
  66718. * @param {Array.<string>} stateList
  66719. * @param {Object} visualMappings <state, Object.<visualType, module:echarts/visual/VisualMapping>>
  66720. * @param {Function} getValueState param: valueOrIndex, return: state.
  66721. * @param {number} [dim] dimension or dimension index.
  66722. */
  66723. function incrementalApplyVisual(stateList, visualMappings, getValueState, dim) {
  66724. var visualTypesMap = {};
  66725. each$1(stateList, function (state) {
  66726. var visualTypes = VisualMapping.prepareVisualTypes(visualMappings[state]);
  66727. visualTypesMap[state] = visualTypes;
  66728. });
  66729. function progress(params, data) {
  66730. if (dim != null) {
  66731. dim = data.getDimension(dim);
  66732. }
  66733. function getVisual(key) {
  66734. return data.getItemVisual(dataIndex, key);
  66735. }
  66736. function setVisual(key, value) {
  66737. data.setItemVisual(dataIndex, key, value);
  66738. }
  66739. var dataIndex;
  66740. while ((dataIndex = params.next()) != null) {
  66741. var rawDataItem = data.getRawDataItem(dataIndex);
  66742. // Consider performance
  66743. if (rawDataItem && rawDataItem.visualMap === false) {
  66744. continue;
  66745. }
  66746. var value = dim != null
  66747. ? data.get(dim, dataIndex, true)
  66748. : dataIndex;
  66749. var valueState = getValueState(value);
  66750. var mappings = visualMappings[valueState];
  66751. var visualTypes = visualTypesMap[valueState];
  66752. for (var i = 0, len = visualTypes.length; i < len; i++) {
  66753. var type = visualTypes[i];
  66754. mappings[type] && mappings[type].applyVisual(value, getVisual, setVisual);
  66755. }
  66756. }
  66757. }
  66758. return {progress: progress};
  66759. }
  66760. /*
  66761. * Licensed to the Apache Software Foundation (ASF) under one
  66762. * or more contributor license agreements. See the NOTICE file
  66763. * distributed with this work for additional information
  66764. * regarding copyright ownership. The ASF licenses this file
  66765. * to you under the Apache License, Version 2.0 (the
  66766. * "License"); you may not use this file except in compliance
  66767. * with the License. You may obtain a copy of the License at
  66768. *
  66769. * http://www.apache.org/licenses/LICENSE-2.0
  66770. *
  66771. * Unless required by applicable law or agreed to in writing,
  66772. * software distributed under the License is distributed on an
  66773. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66774. * KIND, either express or implied. See the License for the
  66775. * specific language governing permissions and limitations
  66776. * under the License.
  66777. */
  66778. // Key of the first level is brushType: `line`, `rect`, `polygon`.
  66779. // Key of the second level is chart element type: `point`, `rect`.
  66780. // See moudule:echarts/component/helper/BrushController
  66781. // function param:
  66782. // {Object} itemLayout fetch from data.getItemLayout(dataIndex)
  66783. // {Object} selectors {point: selector, rect: selector, ...}
  66784. // {Object} area {range: [[], [], ..], boudingRect}
  66785. // function return:
  66786. // {boolean} Whether in the given brush.
  66787. var selector = {
  66788. lineX: getLineSelectors(0),
  66789. lineY: getLineSelectors(1),
  66790. rect: {
  66791. point: function (itemLayout, selectors, area) {
  66792. return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]);
  66793. },
  66794. rect: function (itemLayout, selectors, area) {
  66795. return itemLayout && area.boundingRect.intersect(itemLayout);
  66796. }
  66797. },
  66798. polygon: {
  66799. point: function (itemLayout, selectors, area) {
  66800. return itemLayout
  66801. && area.boundingRect.contain(itemLayout[0], itemLayout[1])
  66802. && contain$1(area.range, itemLayout[0], itemLayout[1]);
  66803. },
  66804. rect: function (itemLayout, selectors, area) {
  66805. var points = area.range;
  66806. if (!itemLayout || points.length <= 1) {
  66807. return false;
  66808. }
  66809. var x = itemLayout.x;
  66810. var y = itemLayout.y;
  66811. var width = itemLayout.width;
  66812. var height = itemLayout.height;
  66813. var p = points[0];
  66814. if (contain$1(points, x, y)
  66815. || contain$1(points, x + width, y)
  66816. || contain$1(points, x, y + height)
  66817. || contain$1(points, x + width, y + height)
  66818. || BoundingRect.create(itemLayout).contain(p[0], p[1])
  66819. || lineIntersectPolygon(x, y, x + width, y, points)
  66820. || lineIntersectPolygon(x, y, x, y + height, points)
  66821. || lineIntersectPolygon(x + width, y, x + width, y + height, points)
  66822. || lineIntersectPolygon(x, y + height, x + width, y + height, points)
  66823. ) {
  66824. return true;
  66825. }
  66826. }
  66827. }
  66828. };
  66829. function getLineSelectors(xyIndex) {
  66830. var xy = ['x', 'y'];
  66831. var wh = ['width', 'height'];
  66832. return {
  66833. point: function (itemLayout, selectors, area) {
  66834. if (itemLayout) {
  66835. var range = area.range;
  66836. var p = itemLayout[xyIndex];
  66837. return inLineRange(p, range);
  66838. }
  66839. },
  66840. rect: function (itemLayout, selectors, area) {
  66841. if (itemLayout) {
  66842. var range = area.range;
  66843. var layoutRange = [
  66844. itemLayout[xy[xyIndex]],
  66845. itemLayout[xy[xyIndex]] + itemLayout[wh[xyIndex]]
  66846. ];
  66847. layoutRange[1] < layoutRange[0] && layoutRange.reverse();
  66848. return inLineRange(layoutRange[0], range)
  66849. || inLineRange(layoutRange[1], range)
  66850. || inLineRange(range[0], layoutRange)
  66851. || inLineRange(range[1], layoutRange);
  66852. }
  66853. }
  66854. };
  66855. }
  66856. function inLineRange(p, range) {
  66857. return range[0] <= p && p <= range[1];
  66858. }
  66859. function lineIntersectPolygon(lx, ly, l2x, l2y, points) {
  66860. for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
  66861. var p = points[i];
  66862. if (lineIntersect(lx, ly, l2x, l2y, p[0], p[1], p2[0], p2[1])) {
  66863. return true;
  66864. }
  66865. p2 = p;
  66866. }
  66867. }
  66868. // Code from <http://blog.csdn.net/rickliuxiao/article/details/6259322> with some fix.
  66869. // See <https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection>
  66870. function lineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  66871. var delta = determinant(a2x - a1x, b1x - b2x, a2y - a1y, b1y - b2y);
  66872. if (nearZero(delta)) { // parallel
  66873. return false;
  66874. }
  66875. var namenda = determinant(b1x - a1x, b1x - b2x, b1y - a1y, b1y - b2y) / delta;
  66876. if (namenda < 0 || namenda > 1) {
  66877. return false;
  66878. }
  66879. var miu = determinant(a2x - a1x, b1x - a1x, a2y - a1y, b1y - a1y) / delta;
  66880. if (miu < 0 || miu > 1) {
  66881. return false;
  66882. }
  66883. return true;
  66884. }
  66885. function nearZero(val) {
  66886. return val <= (1e-6) && val >= -(1e-6);
  66887. }
  66888. function determinant(v1, v2, v3, v4) {
  66889. return v1 * v4 - v2 * v3;
  66890. }
  66891. /*
  66892. * Licensed to the Apache Software Foundation (ASF) under one
  66893. * or more contributor license agreements. See the NOTICE file
  66894. * distributed with this work for additional information
  66895. * regarding copyright ownership. The ASF licenses this file
  66896. * to you under the Apache License, Version 2.0 (the
  66897. * "License"); you may not use this file except in compliance
  66898. * with the License. You may obtain a copy of the License at
  66899. *
  66900. * http://www.apache.org/licenses/LICENSE-2.0
  66901. *
  66902. * Unless required by applicable law or agreed to in writing,
  66903. * software distributed under the License is distributed on an
  66904. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66905. * KIND, either express or implied. See the License for the
  66906. * specific language governing permissions and limitations
  66907. * under the License.
  66908. */
  66909. var each$20 = each$1;
  66910. var indexOf$1 = indexOf;
  66911. var curry$5 = curry;
  66912. var COORD_CONVERTS = ['dataToPoint', 'pointToData'];
  66913. // FIXME
  66914. // how to genarialize to more coordinate systems.
  66915. var INCLUDE_FINDER_MAIN_TYPES = [
  66916. 'grid', 'xAxis', 'yAxis', 'geo', 'graph',
  66917. 'polar', 'radiusAxis', 'angleAxis', 'bmap'
  66918. ];
  66919. /**
  66920. * [option in constructor]:
  66921. * {
  66922. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  66923. * }
  66924. *
  66925. *
  66926. * [targetInfo]:
  66927. *
  66928. * There can be multiple axes in a single targetInfo. Consider the case
  66929. * of `grid` component, a targetInfo represents a grid which contains one or more
  66930. * cartesian and one or more axes. And consider the case of parallel system,
  66931. * which has multiple axes in a coordinate system.
  66932. * Can be {
  66933. * panelId: ...,
  66934. * coordSys: <a representitive cartesian in grid (first cartesian by default)>,
  66935. * coordSyses: all cartesians.
  66936. * gridModel: <grid component>
  66937. * xAxes: correspond to coordSyses on index
  66938. * yAxes: correspond to coordSyses on index
  66939. * }
  66940. * or {
  66941. * panelId: ...,
  66942. * coordSys: <geo coord sys>
  66943. * coordSyses: [<geo coord sys>]
  66944. * geoModel: <geo component>
  66945. * }
  66946. *
  66947. *
  66948. * [panelOpt]:
  66949. *
  66950. * Make from targetInfo. Input to BrushController.
  66951. * {
  66952. * panelId: ...,
  66953. * rect: ...
  66954. * }
  66955. *
  66956. *
  66957. * [area]:
  66958. *
  66959. * Generated by BrushController or user input.
  66960. * {
  66961. * panelId: Used to locate coordInfo directly. If user inpput, no panelId.
  66962. * brushType: determine how to convert to/from coord('rect' or 'polygon' or 'lineX/Y').
  66963. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  66964. * range: pixel range.
  66965. * coordRange: representitive coord range (the first one of coordRanges).
  66966. * coordRanges: <Array> coord ranges, used in multiple cartesian in one grid.
  66967. * }
  66968. */
  66969. /**
  66970. * @param {Object} option contains Index/Id/Name of xAxis/yAxis/geo/grid
  66971. * Each can be {number|Array.<number>}. like: {xAxisIndex: [3, 4]}
  66972. * @param {module:echarts/model/Global} ecModel
  66973. * @param {Object} [opt]
  66974. * @param {Array.<string>} [opt.include] include coordinate system types.
  66975. */
  66976. function BrushTargetManager(option, ecModel, opt) {
  66977. /**
  66978. * @private
  66979. * @type {Array.<Object>}
  66980. */
  66981. var targetInfoList = this._targetInfoList = [];
  66982. var info = {};
  66983. var foundCpts = parseFinder$1(ecModel, option);
  66984. each$20(targetInfoBuilders, function (builder, type) {
  66985. if (!opt || !opt.include || indexOf$1(opt.include, type) >= 0) {
  66986. builder(foundCpts, targetInfoList, info);
  66987. }
  66988. });
  66989. }
  66990. var proto$2 = BrushTargetManager.prototype;
  66991. proto$2.setOutputRanges = function (areas, ecModel) {
  66992. this.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  66993. (area.coordRanges || (area.coordRanges = [])).push(coordRange);
  66994. // area.coordRange is the first of area.coordRanges
  66995. if (!area.coordRange) {
  66996. area.coordRange = coordRange;
  66997. // In 'category' axis, coord to pixel is not reversible, so we can not
  66998. // rebuild range by coordRange accrately, which may bring trouble when
  66999. // brushing only one item. So we use __rangeOffset to rebuilding range
  67000. // by coordRange. And this it only used in brush component so it is no
  67001. // need to be adapted to coordRanges.
  67002. var result = coordConvert[area.brushType](0, coordSys, coordRange);
  67003. area.__rangeOffset = {
  67004. offset: diffProcessor[area.brushType](result.values, area.range, [1, 1]),
  67005. xyMinMax: result.xyMinMax
  67006. };
  67007. }
  67008. });
  67009. };
  67010. proto$2.matchOutputRanges = function (areas, ecModel, cb) {
  67011. each$20(areas, function (area) {
  67012. var targetInfo = this.findTargetInfo(area, ecModel);
  67013. if (targetInfo && targetInfo !== true) {
  67014. each$1(
  67015. targetInfo.coordSyses,
  67016. function (coordSys) {
  67017. var result = coordConvert[area.brushType](1, coordSys, area.range);
  67018. cb(area, result.values, coordSys, ecModel);
  67019. }
  67020. );
  67021. }
  67022. }, this);
  67023. };
  67024. proto$2.setInputRanges = function (areas, ecModel) {
  67025. each$20(areas, function (area) {
  67026. var targetInfo = this.findTargetInfo(area, ecModel);
  67027. if (__DEV__) {
  67028. assert$1(
  67029. !targetInfo || targetInfo === true || area.coordRange,
  67030. 'coordRange must be specified when coord index specified.'
  67031. );
  67032. assert$1(
  67033. !targetInfo || targetInfo !== true || area.range,
  67034. 'range must be specified in global brush.'
  67035. );
  67036. }
  67037. area.range = area.range || [];
  67038. // convert coordRange to global range and set panelId.
  67039. if (targetInfo && targetInfo !== true) {
  67040. area.panelId = targetInfo.panelId;
  67041. // (1) area.range shoule always be calculate from coordRange but does
  67042. // not keep its original value, for the sake of the dataZoom scenario,
  67043. // where area.coordRange remains unchanged but area.range may be changed.
  67044. // (2) Only support converting one coordRange to pixel range in brush
  67045. // component. So do not consider `coordRanges`.
  67046. // (3) About __rangeOffset, see comment above.
  67047. var result = coordConvert[area.brushType](0, targetInfo.coordSys, area.coordRange);
  67048. var rangeOffset = area.__rangeOffset;
  67049. area.range = rangeOffset
  67050. ? diffProcessor[area.brushType](
  67051. result.values,
  67052. rangeOffset.offset,
  67053. getScales(result.xyMinMax, rangeOffset.xyMinMax)
  67054. )
  67055. : result.values;
  67056. }
  67057. }, this);
  67058. };
  67059. proto$2.makePanelOpts = function (api, getDefaultBrushType) {
  67060. return map(this._targetInfoList, function (targetInfo) {
  67061. var rect = targetInfo.getPanelRect();
  67062. return {
  67063. panelId: targetInfo.panelId,
  67064. defaultBrushType: getDefaultBrushType && getDefaultBrushType(targetInfo),
  67065. clipPath: makeRectPanelClipPath(rect),
  67066. isTargetByCursor: makeRectIsTargetByCursor(
  67067. rect, api, targetInfo.coordSysModel
  67068. ),
  67069. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect)
  67070. };
  67071. });
  67072. };
  67073. proto$2.controlSeries = function (area, seriesModel, ecModel) {
  67074. // Check whether area is bound in coord, and series do not belong to that coord.
  67075. // If do not do this check, some brush (like lineX) will controll all axes.
  67076. var targetInfo = this.findTargetInfo(area, ecModel);
  67077. return targetInfo === true || (
  67078. targetInfo && indexOf$1(targetInfo.coordSyses, seriesModel.coordinateSystem) >= 0
  67079. );
  67080. };
  67081. /**
  67082. * If return Object, a coord found.
  67083. * If reutrn true, global found.
  67084. * Otherwise nothing found.
  67085. *
  67086. * @param {Object} area
  67087. * @param {Array} targetInfoList
  67088. * @return {Object|boolean}
  67089. */
  67090. proto$2.findTargetInfo = function (area, ecModel) {
  67091. var targetInfoList = this._targetInfoList;
  67092. var foundCpts = parseFinder$1(ecModel, area);
  67093. for (var i = 0; i < targetInfoList.length; i++) {
  67094. var targetInfo = targetInfoList[i];
  67095. var areaPanelId = area.panelId;
  67096. if (areaPanelId) {
  67097. if (targetInfo.panelId === areaPanelId) {
  67098. return targetInfo;
  67099. }
  67100. }
  67101. else {
  67102. for (var i = 0; i < targetInfoMatchers.length; i++) {
  67103. if (targetInfoMatchers[i](foundCpts, targetInfo)) {
  67104. return targetInfo;
  67105. }
  67106. }
  67107. }
  67108. }
  67109. return true;
  67110. };
  67111. function formatMinMax(minMax) {
  67112. minMax[0] > minMax[1] && minMax.reverse();
  67113. return minMax;
  67114. }
  67115. function parseFinder$1(ecModel, option) {
  67116. return parseFinder(
  67117. ecModel, option, {includeMainTypes: INCLUDE_FINDER_MAIN_TYPES}
  67118. );
  67119. }
  67120. var targetInfoBuilders = {
  67121. grid: function (foundCpts, targetInfoList) {
  67122. var xAxisModels = foundCpts.xAxisModels;
  67123. var yAxisModels = foundCpts.yAxisModels;
  67124. var gridModels = foundCpts.gridModels;
  67125. // Remove duplicated.
  67126. var gridModelMap = createHashMap();
  67127. var xAxesHas = {};
  67128. var yAxesHas = {};
  67129. if (!xAxisModels && !yAxisModels && !gridModels) {
  67130. return;
  67131. }
  67132. each$20(xAxisModels, function (axisModel) {
  67133. var gridModel = axisModel.axis.grid.model;
  67134. gridModelMap.set(gridModel.id, gridModel);
  67135. xAxesHas[gridModel.id] = true;
  67136. });
  67137. each$20(yAxisModels, function (axisModel) {
  67138. var gridModel = axisModel.axis.grid.model;
  67139. gridModelMap.set(gridModel.id, gridModel);
  67140. yAxesHas[gridModel.id] = true;
  67141. });
  67142. each$20(gridModels, function (gridModel) {
  67143. gridModelMap.set(gridModel.id, gridModel);
  67144. xAxesHas[gridModel.id] = true;
  67145. yAxesHas[gridModel.id] = true;
  67146. });
  67147. gridModelMap.each(function (gridModel) {
  67148. var grid = gridModel.coordinateSystem;
  67149. var cartesians = [];
  67150. each$20(grid.getCartesians(), function (cartesian, index) {
  67151. if (indexOf$1(xAxisModels, cartesian.getAxis('x').model) >= 0
  67152. || indexOf$1(yAxisModels, cartesian.getAxis('y').model) >= 0
  67153. ) {
  67154. cartesians.push(cartesian);
  67155. }
  67156. });
  67157. targetInfoList.push({
  67158. panelId: 'grid--' + gridModel.id,
  67159. gridModel: gridModel,
  67160. coordSysModel: gridModel,
  67161. // Use the first one as the representitive coordSys.
  67162. coordSys: cartesians[0],
  67163. coordSyses: cartesians,
  67164. getPanelRect: panelRectBuilder.grid,
  67165. xAxisDeclared: xAxesHas[gridModel.id],
  67166. yAxisDeclared: yAxesHas[gridModel.id]
  67167. });
  67168. });
  67169. },
  67170. geo: function (foundCpts, targetInfoList) {
  67171. each$20(foundCpts.geoModels, function (geoModel) {
  67172. var coordSys = geoModel.coordinateSystem;
  67173. targetInfoList.push({
  67174. panelId: 'geo--' + geoModel.id,
  67175. geoModel: geoModel,
  67176. coordSysModel: geoModel,
  67177. coordSys: coordSys,
  67178. coordSyses: [coordSys],
  67179. getPanelRect: panelRectBuilder.geo
  67180. });
  67181. });
  67182. }
  67183. };
  67184. var targetInfoMatchers = [
  67185. // grid
  67186. function (foundCpts, targetInfo) {
  67187. var xAxisModel = foundCpts.xAxisModel;
  67188. var yAxisModel = foundCpts.yAxisModel;
  67189. var gridModel = foundCpts.gridModel;
  67190. !gridModel && xAxisModel && (gridModel = xAxisModel.axis.grid.model);
  67191. !gridModel && yAxisModel && (gridModel = yAxisModel.axis.grid.model);
  67192. return gridModel && gridModel === targetInfo.gridModel;
  67193. },
  67194. // geo
  67195. function (foundCpts, targetInfo) {
  67196. var geoModel = foundCpts.geoModel;
  67197. return geoModel && geoModel === targetInfo.geoModel;
  67198. }
  67199. ];
  67200. var panelRectBuilder = {
  67201. grid: function () {
  67202. // grid is not Transformable.
  67203. return this.coordSys.grid.getRect().clone();
  67204. },
  67205. geo: function () {
  67206. var coordSys = this.coordSys;
  67207. var rect = coordSys.getBoundingRect().clone();
  67208. // geo roam and zoom transform
  67209. rect.applyTransform(getTransform(coordSys));
  67210. return rect;
  67211. }
  67212. };
  67213. var coordConvert = {
  67214. lineX: curry$5(axisConvert, 0),
  67215. lineY: curry$5(axisConvert, 1),
  67216. rect: function (to, coordSys, rangeOrCoordRange) {
  67217. var xminymin = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]]);
  67218. var xmaxymax = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]]);
  67219. var values = [
  67220. formatMinMax([xminymin[0], xmaxymax[0]]),
  67221. formatMinMax([xminymin[1], xmaxymax[1]])
  67222. ];
  67223. return {values: values, xyMinMax: values};
  67224. },
  67225. polygon: function (to, coordSys, rangeOrCoordRange) {
  67226. var xyMinMax = [[Infinity, -Infinity], [Infinity, -Infinity]];
  67227. var values = map(rangeOrCoordRange, function (item) {
  67228. var p = coordSys[COORD_CONVERTS[to]](item);
  67229. xyMinMax[0][0] = Math.min(xyMinMax[0][0], p[0]);
  67230. xyMinMax[1][0] = Math.min(xyMinMax[1][0], p[1]);
  67231. xyMinMax[0][1] = Math.max(xyMinMax[0][1], p[0]);
  67232. xyMinMax[1][1] = Math.max(xyMinMax[1][1], p[1]);
  67233. return p;
  67234. });
  67235. return {values: values, xyMinMax: xyMinMax};
  67236. }
  67237. };
  67238. function axisConvert(axisNameIndex, to, coordSys, rangeOrCoordRange) {
  67239. if (__DEV__) {
  67240. assert$1(
  67241. coordSys.type === 'cartesian2d',
  67242. 'lineX/lineY brush is available only in cartesian2d.'
  67243. );
  67244. }
  67245. var axis = coordSys.getAxis(['x', 'y'][axisNameIndex]);
  67246. var values = formatMinMax(map([0, 1], function (i) {
  67247. return to
  67248. ? axis.coordToData(axis.toLocalCoord(rangeOrCoordRange[i]))
  67249. : axis.toGlobalCoord(axis.dataToCoord(rangeOrCoordRange[i]));
  67250. }));
  67251. var xyMinMax = [];
  67252. xyMinMax[axisNameIndex] = values;
  67253. xyMinMax[1 - axisNameIndex] = [NaN, NaN];
  67254. return {values: values, xyMinMax: xyMinMax};
  67255. }
  67256. var diffProcessor = {
  67257. lineX: curry$5(axisDiffProcessor, 0),
  67258. lineY: curry$5(axisDiffProcessor, 1),
  67259. rect: function (values, refer, scales) {
  67260. return [
  67261. [values[0][0] - scales[0] * refer[0][0], values[0][1] - scales[0] * refer[0][1]],
  67262. [values[1][0] - scales[1] * refer[1][0], values[1][1] - scales[1] * refer[1][1]]
  67263. ];
  67264. },
  67265. polygon: function (values, refer, scales) {
  67266. return map(values, function (item, idx) {
  67267. return [item[0] - scales[0] * refer[idx][0], item[1] - scales[1] * refer[idx][1]];
  67268. });
  67269. }
  67270. };
  67271. function axisDiffProcessor(axisNameIndex, values, refer, scales) {
  67272. return [
  67273. values[0] - scales[axisNameIndex] * refer[0],
  67274. values[1] - scales[axisNameIndex] * refer[1]
  67275. ];
  67276. }
  67277. // We have to process scale caused by dataZoom manually,
  67278. // although it might be not accurate.
  67279. function getScales(xyMinMaxCurr, xyMinMaxOrigin) {
  67280. var sizeCurr = getSize(xyMinMaxCurr);
  67281. var sizeOrigin = getSize(xyMinMaxOrigin);
  67282. var scales = [sizeCurr[0] / sizeOrigin[0], sizeCurr[1] / sizeOrigin[1]];
  67283. isNaN(scales[0]) && (scales[0] = 1);
  67284. isNaN(scales[1]) && (scales[1] = 1);
  67285. return scales;
  67286. }
  67287. function getSize(xyMinMax) {
  67288. return xyMinMax
  67289. ? [xyMinMax[0][1] - xyMinMax[0][0], xyMinMax[1][1] - xyMinMax[1][0]]
  67290. : [NaN, NaN];
  67291. }
  67292. /*
  67293. * Licensed to the Apache Software Foundation (ASF) under one
  67294. * or more contributor license agreements. See the NOTICE file
  67295. * distributed with this work for additional information
  67296. * regarding copyright ownership. The ASF licenses this file
  67297. * to you under the Apache License, Version 2.0 (the
  67298. * "License"); you may not use this file except in compliance
  67299. * with the License. You may obtain a copy of the License at
  67300. *
  67301. * http://www.apache.org/licenses/LICENSE-2.0
  67302. *
  67303. * Unless required by applicable law or agreed to in writing,
  67304. * software distributed under the License is distributed on an
  67305. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67306. * KIND, either express or implied. See the License for the
  67307. * specific language governing permissions and limitations
  67308. * under the License.
  67309. */
  67310. var STATE_LIST = ['inBrush', 'outOfBrush'];
  67311. var DISPATCH_METHOD = '__ecBrushSelect';
  67312. var DISPATCH_FLAG = '__ecInBrushSelectEvent';
  67313. var PRIORITY_BRUSH = PRIORITY.VISUAL.BRUSH;
  67314. /**
  67315. * Layout for visual, the priority higher than other layout, and before brush visual.
  67316. */
  67317. registerLayout(PRIORITY_BRUSH, function (ecModel, api, payload) {
  67318. ecModel.eachComponent({mainType: 'brush'}, function (brushModel) {
  67319. payload && payload.type === 'takeGlobalCursor' && brushModel.setBrushOption(
  67320. payload.key === 'brush' ? payload.brushOption : {brushType: false}
  67321. );
  67322. var brushTargetManager = brushModel.brushTargetManager = new BrushTargetManager(brushModel.option, ecModel);
  67323. brushTargetManager.setInputRanges(brushModel.areas, ecModel);
  67324. });
  67325. });
  67326. /**
  67327. * Register the visual encoding if this modules required.
  67328. */
  67329. registerVisual(PRIORITY_BRUSH, function (ecModel, api, payload) {
  67330. var brushSelected = [];
  67331. var throttleType;
  67332. var throttleDelay;
  67333. ecModel.eachComponent({mainType: 'brush'}, function (brushModel, brushIndex) {
  67334. var thisBrushSelected = {
  67335. brushId: brushModel.id,
  67336. brushIndex: brushIndex,
  67337. brushName: brushModel.name,
  67338. areas: clone(brushModel.areas),
  67339. selected: []
  67340. };
  67341. // Every brush component exists in event params, convenient
  67342. // for user to find by index.
  67343. brushSelected.push(thisBrushSelected);
  67344. var brushOption = brushModel.option;
  67345. var brushLink = brushOption.brushLink;
  67346. var linkedSeriesMap = [];
  67347. var selectedDataIndexForLink = [];
  67348. var rangeInfoBySeries = [];
  67349. var hasBrushExists = 0;
  67350. if (!brushIndex) { // Only the first throttle setting works.
  67351. throttleType = brushOption.throttleType;
  67352. throttleDelay = brushOption.throttleDelay;
  67353. }
  67354. // Add boundingRect and selectors to range.
  67355. var areas = map(brushModel.areas, function (area) {
  67356. return bindSelector(
  67357. defaults(
  67358. {boundingRect: boundingRectBuilders[area.brushType](area)},
  67359. area
  67360. )
  67361. );
  67362. });
  67363. var visualMappings = createVisualMappings(
  67364. brushModel.option, STATE_LIST, function (mappingOption) {
  67365. mappingOption.mappingMethod = 'fixed';
  67366. }
  67367. );
  67368. isArray(brushLink) && each$1(brushLink, function (seriesIndex) {
  67369. linkedSeriesMap[seriesIndex] = 1;
  67370. });
  67371. function linkOthers(seriesIndex) {
  67372. return brushLink === 'all' || linkedSeriesMap[seriesIndex];
  67373. }
  67374. // If no supported brush or no brush on the series,
  67375. // all visuals should be in original state.
  67376. function brushed(rangeInfoList) {
  67377. return !!rangeInfoList.length;
  67378. }
  67379. /**
  67380. * Logic for each series: (If the logic has to be modified one day, do it carefully!)
  67381. *
  67382. * ( brushed ┬ && ┬hasBrushExist ┬ && linkOthers ) => StepA: ┬record, ┬ StepB: ┬visualByRecord.
  67383. * !brushed┘ ├hasBrushExist ┤ └nothing,┘ ├visualByRecord.
  67384. * └!hasBrushExist┘ └nothing.
  67385. * ( !brushed && ┬hasBrushExist ┬ && linkOthers ) => StepA: nothing, StepB: ┬visualByRecord.
  67386. * └!hasBrushExist┘ └nothing.
  67387. * ( brushed ┬ && !linkOthers ) => StepA: nothing, StepB: ┬visualByCheck.
  67388. * !brushed┘ └nothing.
  67389. * ( !brushed && !linkOthers ) => StepA: nothing, StepB: nothing.
  67390. */
  67391. // Step A
  67392. ecModel.eachSeries(function (seriesModel, seriesIndex) {
  67393. var rangeInfoList = rangeInfoBySeries[seriesIndex] = [];
  67394. seriesModel.subType === 'parallel'
  67395. ? stepAParallel(seriesModel, seriesIndex, rangeInfoList)
  67396. : stepAOthers(seriesModel, seriesIndex, rangeInfoList);
  67397. });
  67398. function stepAParallel(seriesModel, seriesIndex) {
  67399. var coordSys = seriesModel.coordinateSystem;
  67400. hasBrushExists |= coordSys.hasAxisBrushed();
  67401. linkOthers(seriesIndex) && coordSys.eachActiveState(
  67402. seriesModel.getData(),
  67403. function (activeState, dataIndex) {
  67404. activeState === 'active' && (selectedDataIndexForLink[dataIndex] = 1);
  67405. }
  67406. );
  67407. }
  67408. function stepAOthers(seriesModel, seriesIndex, rangeInfoList) {
  67409. var selectorsByBrushType = getSelectorsByBrushType(seriesModel);
  67410. if (!selectorsByBrushType || brushModelNotControll(brushModel, seriesIndex)) {
  67411. return;
  67412. }
  67413. each$1(areas, function (area) {
  67414. selectorsByBrushType[area.brushType]
  67415. && brushModel.brushTargetManager.controlSeries(area, seriesModel, ecModel)
  67416. && rangeInfoList.push(area);
  67417. hasBrushExists |= brushed(rangeInfoList);
  67418. });
  67419. if (linkOthers(seriesIndex) && brushed(rangeInfoList)) {
  67420. var data = seriesModel.getData();
  67421. data.each(function (dataIndex) {
  67422. if (checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex)) {
  67423. selectedDataIndexForLink[dataIndex] = 1;
  67424. }
  67425. });
  67426. }
  67427. }
  67428. // Step B
  67429. ecModel.eachSeries(function (seriesModel, seriesIndex) {
  67430. var seriesBrushSelected = {
  67431. seriesId: seriesModel.id,
  67432. seriesIndex: seriesIndex,
  67433. seriesName: seriesModel.name,
  67434. dataIndex: []
  67435. };
  67436. // Every series exists in event params, convenient
  67437. // for user to find series by seriesIndex.
  67438. thisBrushSelected.selected.push(seriesBrushSelected);
  67439. var selectorsByBrushType = getSelectorsByBrushType(seriesModel);
  67440. var rangeInfoList = rangeInfoBySeries[seriesIndex];
  67441. var data = seriesModel.getData();
  67442. var getValueState = linkOthers(seriesIndex)
  67443. ? function (dataIndex) {
  67444. return selectedDataIndexForLink[dataIndex]
  67445. ? (seriesBrushSelected.dataIndex.push(data.getRawIndex(dataIndex)), 'inBrush')
  67446. : 'outOfBrush';
  67447. }
  67448. : function (dataIndex) {
  67449. return checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex)
  67450. ? (seriesBrushSelected.dataIndex.push(data.getRawIndex(dataIndex)), 'inBrush')
  67451. : 'outOfBrush';
  67452. };
  67453. // If no supported brush or no brush, all visuals are in original state.
  67454. (linkOthers(seriesIndex) ? hasBrushExists : brushed(rangeInfoList))
  67455. && applyVisual(
  67456. STATE_LIST, visualMappings, data, getValueState
  67457. );
  67458. });
  67459. });
  67460. dispatchAction(api, throttleType, throttleDelay, brushSelected, payload);
  67461. });
  67462. function dispatchAction(api, throttleType, throttleDelay, brushSelected, payload) {
  67463. // This event will not be triggered when `setOpion`, otherwise dead lock may
  67464. // triggered when do `setOption` in event listener, which we do not find
  67465. // satisfactory way to solve yet. Some considered resolutions:
  67466. // (a) Diff with prevoius selected data ant only trigger event when changed.
  67467. // But store previous data and diff precisely (i.e., not only by dataIndex, but
  67468. // also detect value changes in selected data) might bring complexity or fragility.
  67469. // (b) Use spectial param like `silent` to suppress event triggering.
  67470. // But such kind of volatile param may be weird in `setOption`.
  67471. if (!payload) {
  67472. return;
  67473. }
  67474. var zr = api.getZr();
  67475. if (zr[DISPATCH_FLAG]) {
  67476. return;
  67477. }
  67478. if (!zr[DISPATCH_METHOD]) {
  67479. zr[DISPATCH_METHOD] = doDispatch;
  67480. }
  67481. var fn = createOrUpdate(zr, DISPATCH_METHOD, throttleDelay, throttleType);
  67482. fn(api, brushSelected);
  67483. }
  67484. function doDispatch(api, brushSelected) {
  67485. if (!api.isDisposed()) {
  67486. var zr = api.getZr();
  67487. zr[DISPATCH_FLAG] = true;
  67488. api.dispatchAction({
  67489. type: 'brushSelect',
  67490. batch: brushSelected
  67491. });
  67492. zr[DISPATCH_FLAG] = false;
  67493. }
  67494. }
  67495. function checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex) {
  67496. for (var i = 0, len = rangeInfoList.length; i < len; i++) {
  67497. var area = rangeInfoList[i];
  67498. if (selectorsByBrushType[area.brushType](
  67499. dataIndex, data, area.selectors, area
  67500. )) {
  67501. return true;
  67502. }
  67503. }
  67504. }
  67505. function getSelectorsByBrushType(seriesModel) {
  67506. var brushSelector = seriesModel.brushSelector;
  67507. if (isString(brushSelector)) {
  67508. var sels = [];
  67509. each$1(selector, function (selectorsByElementType, brushType) {
  67510. sels[brushType] = function (dataIndex, data, selectors, area) {
  67511. var itemLayout = data.getItemLayout(dataIndex);
  67512. return selectorsByElementType[brushSelector](itemLayout, selectors, area);
  67513. };
  67514. });
  67515. return sels;
  67516. }
  67517. else if (isFunction$1(brushSelector)) {
  67518. var bSelector = {};
  67519. each$1(selector, function (sel, brushType) {
  67520. bSelector[brushType] = brushSelector;
  67521. });
  67522. return bSelector;
  67523. }
  67524. return brushSelector;
  67525. }
  67526. function brushModelNotControll(brushModel, seriesIndex) {
  67527. var seriesIndices = brushModel.option.seriesIndex;
  67528. return seriesIndices != null
  67529. && seriesIndices !== 'all'
  67530. && (
  67531. isArray(seriesIndices)
  67532. ? indexOf(seriesIndices, seriesIndex) < 0
  67533. : seriesIndex !== seriesIndices
  67534. );
  67535. }
  67536. function bindSelector(area) {
  67537. var selectors = area.selectors = {};
  67538. each$1(selector[area.brushType], function (selFn, elType) {
  67539. // Do not use function binding or curry for performance.
  67540. selectors[elType] = function (itemLayout) {
  67541. return selFn(itemLayout, selectors, area);
  67542. };
  67543. });
  67544. return area;
  67545. }
  67546. var boundingRectBuilders = {
  67547. lineX: noop,
  67548. lineY: noop,
  67549. rect: function (area) {
  67550. return getBoundingRectFromMinMax(area.range);
  67551. },
  67552. polygon: function (area) {
  67553. var minMax;
  67554. var range = area.range;
  67555. for (var i = 0, len = range.length; i < len; i++) {
  67556. minMax = minMax || [[Infinity, -Infinity], [Infinity, -Infinity]];
  67557. var rg = range[i];
  67558. rg[0] < minMax[0][0] && (minMax[0][0] = rg[0]);
  67559. rg[0] > minMax[0][1] && (minMax[0][1] = rg[0]);
  67560. rg[1] < minMax[1][0] && (minMax[1][0] = rg[1]);
  67561. rg[1] > minMax[1][1] && (minMax[1][1] = rg[1]);
  67562. }
  67563. return minMax && getBoundingRectFromMinMax(minMax);
  67564. }
  67565. };
  67566. function getBoundingRectFromMinMax(minMax) {
  67567. return new BoundingRect(
  67568. minMax[0][0],
  67569. minMax[1][0],
  67570. minMax[0][1] - minMax[0][0],
  67571. minMax[1][1] - minMax[1][0]
  67572. );
  67573. }
  67574. /*
  67575. * Licensed to the Apache Software Foundation (ASF) under one
  67576. * or more contributor license agreements. See the NOTICE file
  67577. * distributed with this work for additional information
  67578. * regarding copyright ownership. The ASF licenses this file
  67579. * to you under the Apache License, Version 2.0 (the
  67580. * "License"); you may not use this file except in compliance
  67581. * with the License. You may obtain a copy of the License at
  67582. *
  67583. * http://www.apache.org/licenses/LICENSE-2.0
  67584. *
  67585. * Unless required by applicable law or agreed to in writing,
  67586. * software distributed under the License is distributed on an
  67587. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67588. * KIND, either express or implied. See the License for the
  67589. * specific language governing permissions and limitations
  67590. * under the License.
  67591. */
  67592. var DEFAULT_OUT_OF_BRUSH_COLOR = ['#ddd'];
  67593. var BrushModel = extendComponentModel({
  67594. type: 'brush',
  67595. dependencies: ['geo', 'grid', 'xAxis', 'yAxis', 'parallel', 'series'],
  67596. /**
  67597. * @protected
  67598. */
  67599. defaultOption: {
  67600. // inBrush: null,
  67601. // outOfBrush: null,
  67602. toolbox: null, // Default value see preprocessor.
  67603. brushLink: null, // Series indices array, broadcast using dataIndex.
  67604. // or 'all', which means all series. 'none' or null means no series.
  67605. seriesIndex: 'all', // seriesIndex array, specify series controlled by this brush component.
  67606. geoIndex: null, //
  67607. xAxisIndex: null,
  67608. yAxisIndex: null,
  67609. brushType: 'rect', // Default brushType, see BrushController.
  67610. brushMode: 'single', // Default brushMode, 'single' or 'multiple'
  67611. transformable: true, // Default transformable.
  67612. brushStyle: { // Default brushStyle
  67613. borderWidth: 1,
  67614. color: 'rgba(120,140,180,0.3)',
  67615. borderColor: 'rgba(120,140,180,0.8)'
  67616. },
  67617. throttleType: 'fixRate', // Throttle in brushSelected event. 'fixRate' or 'debounce'.
  67618. // If null, no throttle. Valid only in the first brush component
  67619. throttleDelay: 0, // Unit: ms, 0 means every event will be triggered.
  67620. // FIXME
  67621. // 试验效果
  67622. removeOnClick: true,
  67623. z: 10000
  67624. },
  67625. /**
  67626. * @readOnly
  67627. * @type {Array.<Object>}
  67628. */
  67629. areas: [],
  67630. /**
  67631. * Current activated brush type.
  67632. * If null, brush is inactived.
  67633. * see module:echarts/component/helper/BrushController
  67634. * @readOnly
  67635. * @type {string}
  67636. */
  67637. brushType: null,
  67638. /**
  67639. * Current brush opt.
  67640. * see module:echarts/component/helper/BrushController
  67641. * @readOnly
  67642. * @type {Object}
  67643. */
  67644. brushOption: {},
  67645. /**
  67646. * @readOnly
  67647. * @type {Array.<Object>}
  67648. */
  67649. coordInfoList: [],
  67650. optionUpdated: function (newOption, isInit) {
  67651. var thisOption = this.option;
  67652. !isInit && replaceVisualOption(
  67653. thisOption, newOption, ['inBrush', 'outOfBrush']
  67654. );
  67655. var inBrush = thisOption.inBrush = thisOption.inBrush || {};
  67656. // Always give default visual, consider setOption at the second time.
  67657. thisOption.outOfBrush = thisOption.outOfBrush || {color: DEFAULT_OUT_OF_BRUSH_COLOR};
  67658. if (!inBrush.hasOwnProperty('liftZ')) {
  67659. // Bigger than the highlight z lift, otherwise it will
  67660. // be effected by the highlight z when brush.
  67661. inBrush.liftZ = 5;
  67662. }
  67663. },
  67664. /**
  67665. * If ranges is null/undefined, range state remain.
  67666. *
  67667. * @param {Array.<Object>} [ranges]
  67668. */
  67669. setAreas: function (areas) {
  67670. if (__DEV__) {
  67671. assert$1(isArray(areas));
  67672. each$1(areas, function (area) {
  67673. assert$1(area.brushType, 'Illegal areas');
  67674. });
  67675. }
  67676. // If ranges is null/undefined, range state remain.
  67677. // This helps user to dispatchAction({type: 'brush'}) with no areas
  67678. // set but just want to get the current brush select info from a `brush` event.
  67679. if (!areas) {
  67680. return;
  67681. }
  67682. this.areas = map(areas, function (area) {
  67683. return generateBrushOption(this.option, area);
  67684. }, this);
  67685. },
  67686. /**
  67687. * see module:echarts/component/helper/BrushController
  67688. * @param {Object} brushOption
  67689. */
  67690. setBrushOption: function (brushOption) {
  67691. this.brushOption = generateBrushOption(this.option, brushOption);
  67692. this.brushType = this.brushOption.brushType;
  67693. }
  67694. });
  67695. function generateBrushOption(option, brushOption) {
  67696. return merge(
  67697. {
  67698. brushType: option.brushType,
  67699. brushMode: option.brushMode,
  67700. transformable: option.transformable,
  67701. brushStyle: new Model(option.brushStyle).getItemStyle(),
  67702. removeOnClick: option.removeOnClick,
  67703. z: option.z
  67704. },
  67705. brushOption,
  67706. true
  67707. );
  67708. }
  67709. /*
  67710. * Licensed to the Apache Software Foundation (ASF) under one
  67711. * or more contributor license agreements. See the NOTICE file
  67712. * distributed with this work for additional information
  67713. * regarding copyright ownership. The ASF licenses this file
  67714. * to you under the Apache License, Version 2.0 (the
  67715. * "License"); you may not use this file except in compliance
  67716. * with the License. You may obtain a copy of the License at
  67717. *
  67718. * http://www.apache.org/licenses/LICENSE-2.0
  67719. *
  67720. * Unless required by applicable law or agreed to in writing,
  67721. * software distributed under the License is distributed on an
  67722. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67723. * KIND, either express or implied. See the License for the
  67724. * specific language governing permissions and limitations
  67725. * under the License.
  67726. */
  67727. extendComponentView({
  67728. type: 'brush',
  67729. init: function (ecModel, api) {
  67730. /**
  67731. * @readOnly
  67732. * @type {module:echarts/model/Global}
  67733. */
  67734. this.ecModel = ecModel;
  67735. /**
  67736. * @readOnly
  67737. * @type {module:echarts/ExtensionAPI}
  67738. */
  67739. this.api = api;
  67740. /**
  67741. * @readOnly
  67742. * @type {module:echarts/component/brush/BrushModel}
  67743. */
  67744. this.model;
  67745. /**
  67746. * @private
  67747. * @type {module:echarts/component/helper/BrushController}
  67748. */
  67749. (this._brushController = new BrushController(api.getZr()))
  67750. .on('brush', bind(this._onBrush, this))
  67751. .mount();
  67752. },
  67753. /**
  67754. * @override
  67755. */
  67756. render: function (brushModel) {
  67757. this.model = brushModel;
  67758. return updateController.apply(this, arguments);
  67759. },
  67760. /**
  67761. * @override
  67762. */
  67763. updateTransform: updateController,
  67764. /**
  67765. * @override
  67766. */
  67767. updateView: updateController,
  67768. // /**
  67769. // * @override
  67770. // */
  67771. // updateLayout: updateController,
  67772. // /**
  67773. // * @override
  67774. // */
  67775. // updateVisual: updateController,
  67776. /**
  67777. * @override
  67778. */
  67779. dispose: function () {
  67780. this._brushController.dispose();
  67781. },
  67782. /**
  67783. * @private
  67784. */
  67785. _onBrush: function (areas, opt) {
  67786. var modelId = this.model.id;
  67787. this.model.brushTargetManager.setOutputRanges(areas, this.ecModel);
  67788. // Action is not dispatched on drag end, because the drag end
  67789. // emits the same params with the last drag move event, and
  67790. // may have some delay when using touch pad, which makes
  67791. // animation not smooth (when using debounce).
  67792. (!opt.isEnd || opt.removeOnClick) && this.api.dispatchAction({
  67793. type: 'brush',
  67794. brushId: modelId,
  67795. areas: clone(areas),
  67796. $from: modelId
  67797. });
  67798. }
  67799. });
  67800. function updateController(brushModel, ecModel, api, payload) {
  67801. // Do not update controller when drawing.
  67802. (!payload || payload.$from !== brushModel.id) && this._brushController
  67803. .setPanels(brushModel.brushTargetManager.makePanelOpts(api))
  67804. .enableBrush(brushModel.brushOption)
  67805. .updateCovers(brushModel.areas.slice());
  67806. }
  67807. /*
  67808. * Licensed to the Apache Software Foundation (ASF) under one
  67809. * or more contributor license agreements. See the NOTICE file
  67810. * distributed with this work for additional information
  67811. * regarding copyright ownership. The ASF licenses this file
  67812. * to you under the Apache License, Version 2.0 (the
  67813. * "License"); you may not use this file except in compliance
  67814. * with the License. You may obtain a copy of the License at
  67815. *
  67816. * http://www.apache.org/licenses/LICENSE-2.0
  67817. *
  67818. * Unless required by applicable law or agreed to in writing,
  67819. * software distributed under the License is distributed on an
  67820. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67821. * KIND, either express or implied. See the License for the
  67822. * specific language governing permissions and limitations
  67823. * under the License.
  67824. */
  67825. /**
  67826. * payload: {
  67827. * brushIndex: number, or,
  67828. * brushId: string, or,
  67829. * brushName: string,
  67830. * globalRanges: Array
  67831. * }
  67832. */
  67833. registerAction(
  67834. {type: 'brush', event: 'brush' /*, update: 'updateView' */},
  67835. function (payload, ecModel) {
  67836. ecModel.eachComponent({mainType: 'brush', query: payload}, function (brushModel) {
  67837. brushModel.setAreas(payload.areas);
  67838. });
  67839. }
  67840. );
  67841. /**
  67842. * payload: {
  67843. * brushComponents: [
  67844. * {
  67845. * brushId,
  67846. * brushIndex,
  67847. * brushName,
  67848. * series: [
  67849. * {
  67850. * seriesId,
  67851. * seriesIndex,
  67852. * seriesName,
  67853. * rawIndices: [21, 34, ...]
  67854. * },
  67855. * ...
  67856. * ]
  67857. * },
  67858. * ...
  67859. * ]
  67860. * }
  67861. */
  67862. registerAction(
  67863. {type: 'brushSelect', event: 'brushSelected', update: 'none'},
  67864. function () {}
  67865. );
  67866. /*
  67867. * Licensed to the Apache Software Foundation (ASF) under one
  67868. * or more contributor license agreements. See the NOTICE file
  67869. * distributed with this work for additional information
  67870. * regarding copyright ownership. The ASF licenses this file
  67871. * to you under the Apache License, Version 2.0 (the
  67872. * "License"); you may not use this file except in compliance
  67873. * with the License. You may obtain a copy of the License at
  67874. *
  67875. * http://www.apache.org/licenses/LICENSE-2.0
  67876. *
  67877. * Unless required by applicable law or agreed to in writing,
  67878. * software distributed under the License is distributed on an
  67879. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67880. * KIND, either express or implied. See the License for the
  67881. * specific language governing permissions and limitations
  67882. * under the License.
  67883. */
  67884. var features = {};
  67885. function register$1(name, ctor) {
  67886. features[name] = ctor;
  67887. }
  67888. function get$1(name) {
  67889. return features[name];
  67890. }
  67891. /*
  67892. * Licensed to the Apache Software Foundation (ASF) under one
  67893. * or more contributor license agreements. See the NOTICE file
  67894. * distributed with this work for additional information
  67895. * regarding copyright ownership. The ASF licenses this file
  67896. * to you under the Apache License, Version 2.0 (the
  67897. * "License"); you may not use this file except in compliance
  67898. * with the License. You may obtain a copy of the License at
  67899. *
  67900. * http://www.apache.org/licenses/LICENSE-2.0
  67901. *
  67902. * Unless required by applicable law or agreed to in writing,
  67903. * software distributed under the License is distributed on an
  67904. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67905. * KIND, either express or implied. See the License for the
  67906. * specific language governing permissions and limitations
  67907. * under the License.
  67908. */
  67909. var brushLang = lang.toolbox.brush;
  67910. function Brush(model, ecModel, api) {
  67911. this.model = model;
  67912. this.ecModel = ecModel;
  67913. this.api = api;
  67914. /**
  67915. * @private
  67916. * @type {string}
  67917. */
  67918. this._brushType;
  67919. /**
  67920. * @private
  67921. * @type {string}
  67922. */
  67923. this._brushMode;
  67924. }
  67925. Brush.defaultOption = {
  67926. show: true,
  67927. type: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'],
  67928. icon: {
  67929. /* eslint-disable */
  67930. rect: 'M7.3,34.7 M0.4,10V-0.2h9.8 M89.6,10V-0.2h-9.8 M0.4,60v10.2h9.8 M89.6,60v10.2h-9.8 M12.3,22.4V10.5h13.1 M33.6,10.5h7.8 M49.1,10.5h7.8 M77.5,22.4V10.5h-13 M12.3,31.1v8.2 M77.7,31.1v8.2 M12.3,47.6v11.9h13.1 M33.6,59.5h7.6 M49.1,59.5 h7.7 M77.5,47.6v11.9h-13', // jshint ignore:line
  67931. polygon: 'M55.2,34.9c1.7,0,3.1,1.4,3.1,3.1s-1.4,3.1-3.1,3.1 s-3.1-1.4-3.1-3.1S53.5,34.9,55.2,34.9z M50.4,51c1.7,0,3.1,1.4,3.1,3.1c0,1.7-1.4,3.1-3.1,3.1c-1.7,0-3.1-1.4-3.1-3.1 C47.3,52.4,48.7,51,50.4,51z M55.6,37.1l1.5-7.8 M60.1,13.5l1.6-8.7l-7.8,4 M59,19l-1,5.3 M24,16.1l6.4,4.9l6.4-3.3 M48.5,11.6 l-5.9,3.1 M19.1,12.8L9.7,5.1l1.1,7.7 M13.4,29.8l1,7.3l6.6,1.6 M11.6,18.4l1,6.1 M32.8,41.9 M26.6,40.4 M27.3,40.2l6.1,1.6 M49.9,52.1l-5.6-7.6l-4.9-1.2', // jshint ignore:line
  67932. lineX: 'M15.2,30 M19.7,15.6V1.9H29 M34.8,1.9H40.4 M55.3,15.6V1.9H45.9 M19.7,44.4V58.1H29 M34.8,58.1H40.4 M55.3,44.4 V58.1H45.9 M12.5,20.3l-9.4,9.6l9.6,9.8 M3.1,29.9h16.5 M62.5,20.3l9.4,9.6L62.3,39.7 M71.9,29.9H55.4', // jshint ignore:line
  67933. lineY: 'M38.8,7.7 M52.7,12h13.2v9 M65.9,26.6V32 M52.7,46.3h13.2v-9 M24.9,12H11.8v9 M11.8,26.6V32 M24.9,46.3H11.8v-9 M48.2,5.1l-9.3-9l-9.4,9.2 M38.9-3.9V12 M48.2,53.3l-9.3,9l-9.4-9.2 M38.9,62.3V46.4', // jshint ignore:line
  67934. keep: 'M4,10.5V1h10.3 M20.7,1h6.1 M33,1h6.1 M55.4,10.5V1H45.2 M4,17.3v6.6 M55.6,17.3v6.6 M4,30.5V40h10.3 M20.7,40 h6.1 M33,40h6.1 M55.4,30.5V40H45.2 M21,18.9h62.9v48.6H21V18.9z', // jshint ignore:line
  67935. clear: 'M22,14.7l30.9,31 M52.9,14.7L22,45.7 M4.7,16.8V4.2h13.1 M26,4.2h7.8 M41.6,4.2h7.8 M70.3,16.8V4.2H57.2 M4.7,25.9v8.6 M70.3,25.9v8.6 M4.7,43.2v12.6h13.1 M26,55.8h7.8 M41.6,55.8h7.8 M70.3,43.2v12.6H57.2' // jshint ignore:line
  67936. /* eslint-enable */
  67937. },
  67938. // `rect`, `polygon`, `lineX`, `lineY`, `keep`, `clear`
  67939. title: clone(brushLang.title)
  67940. };
  67941. var proto$3 = Brush.prototype;
  67942. // proto.updateLayout = function (featureModel, ecModel, api) {
  67943. /* eslint-disable */
  67944. proto$3.render =
  67945. /* eslint-enable */
  67946. proto$3.updateView = function (featureModel, ecModel, api) {
  67947. var brushType;
  67948. var brushMode;
  67949. var isBrushed;
  67950. ecModel.eachComponent({mainType: 'brush'}, function (brushModel) {
  67951. brushType = brushModel.brushType;
  67952. brushMode = brushModel.brushOption.brushMode || 'single';
  67953. isBrushed |= brushModel.areas.length;
  67954. });
  67955. this._brushType = brushType;
  67956. this._brushMode = brushMode;
  67957. each$1(featureModel.get('type', true), function (type) {
  67958. featureModel.setIconStatus(
  67959. type,
  67960. (
  67961. type === 'keep'
  67962. ? brushMode === 'multiple'
  67963. : type === 'clear'
  67964. ? isBrushed
  67965. : type === brushType
  67966. ) ? 'emphasis' : 'normal'
  67967. );
  67968. });
  67969. };
  67970. proto$3.getIcons = function () {
  67971. var model = this.model;
  67972. var availableIcons = model.get('icon', true);
  67973. var icons = {};
  67974. each$1(model.get('type', true), function (type) {
  67975. if (availableIcons[type]) {
  67976. icons[type] = availableIcons[type];
  67977. }
  67978. });
  67979. return icons;
  67980. };
  67981. proto$3.onclick = function (ecModel, api, type) {
  67982. var brushType = this._brushType;
  67983. var brushMode = this._brushMode;
  67984. if (type === 'clear') {
  67985. // Trigger parallel action firstly
  67986. api.dispatchAction({
  67987. type: 'axisAreaSelect',
  67988. intervals: []
  67989. });
  67990. api.dispatchAction({
  67991. type: 'brush',
  67992. command: 'clear',
  67993. // Clear all areas of all brush components.
  67994. areas: []
  67995. });
  67996. }
  67997. else {
  67998. api.dispatchAction({
  67999. type: 'takeGlobalCursor',
  68000. key: 'brush',
  68001. brushOption: {
  68002. brushType: type === 'keep'
  68003. ? brushType
  68004. : (brushType === type ? false : type),
  68005. brushMode: type === 'keep'
  68006. ? (brushMode === 'multiple' ? 'single' : 'multiple')
  68007. : brushMode
  68008. }
  68009. });
  68010. }
  68011. };
  68012. register$1('brush', Brush);
  68013. /*
  68014. * Licensed to the Apache Software Foundation (ASF) under one
  68015. * or more contributor license agreements. See the NOTICE file
  68016. * distributed with this work for additional information
  68017. * regarding copyright ownership. The ASF licenses this file
  68018. * to you under the Apache License, Version 2.0 (the
  68019. * "License"); you may not use this file except in compliance
  68020. * with the License. You may obtain a copy of the License at
  68021. *
  68022. * http://www.apache.org/licenses/LICENSE-2.0
  68023. *
  68024. * Unless required by applicable law or agreed to in writing,
  68025. * software distributed under the License is distributed on an
  68026. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68027. * KIND, either express or implied. See the License for the
  68028. * specific language governing permissions and limitations
  68029. * under the License.
  68030. */
  68031. /**
  68032. * Brush component entry
  68033. */
  68034. registerPreprocessor(preprocessor$1);
  68035. /*
  68036. * Licensed to the Apache Software Foundation (ASF) under one
  68037. * or more contributor license agreements. See the NOTICE file
  68038. * distributed with this work for additional information
  68039. * regarding copyright ownership. The ASF licenses this file
  68040. * to you under the Apache License, Version 2.0 (the
  68041. * "License"); you may not use this file except in compliance
  68042. * with the License. You may obtain a copy of the License at
  68043. *
  68044. * http://www.apache.org/licenses/LICENSE-2.0
  68045. *
  68046. * Unless required by applicable law or agreed to in writing,
  68047. * software distributed under the License is distributed on an
  68048. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68049. * KIND, either express or implied. See the License for the
  68050. * specific language governing permissions and limitations
  68051. * under the License.
  68052. */
  68053. // (24*60*60*1000)
  68054. var PROXIMATE_ONE_DAY = 86400000;
  68055. /**
  68056. * Calendar
  68057. *
  68058. * @constructor
  68059. *
  68060. * @param {Object} calendarModel calendarModel
  68061. * @param {Object} ecModel ecModel
  68062. * @param {Object} api api
  68063. */
  68064. function Calendar(calendarModel, ecModel, api) {
  68065. this._model = calendarModel;
  68066. }
  68067. Calendar.prototype = {
  68068. constructor: Calendar,
  68069. type: 'calendar',
  68070. dimensions: ['time', 'value'],
  68071. // Required in createListFromData
  68072. getDimensionsInfo: function () {
  68073. return [{name: 'time', type: 'time'}, 'value'];
  68074. },
  68075. getRangeInfo: function () {
  68076. return this._rangeInfo;
  68077. },
  68078. getModel: function () {
  68079. return this._model;
  68080. },
  68081. getRect: function () {
  68082. return this._rect;
  68083. },
  68084. getCellWidth: function () {
  68085. return this._sw;
  68086. },
  68087. getCellHeight: function () {
  68088. return this._sh;
  68089. },
  68090. getOrient: function () {
  68091. return this._orient;
  68092. },
  68093. /**
  68094. * getFirstDayOfWeek
  68095. *
  68096. * @example
  68097. * 0 : start at Sunday
  68098. * 1 : start at Monday
  68099. *
  68100. * @return {number}
  68101. */
  68102. getFirstDayOfWeek: function () {
  68103. return this._firstDayOfWeek;
  68104. },
  68105. /**
  68106. * get date info
  68107. *
  68108. * @param {string|number} date date
  68109. * @return {Object}
  68110. * {
  68111. * y: string, local full year, eg., '1940',
  68112. * m: string, local month, from '01' ot '12',
  68113. * d: string, local date, from '01' to '31' (if exists),
  68114. * day: It is not date.getDay(). It is the location of the cell in a week, from 0 to 6,
  68115. * time: timestamp,
  68116. * formatedDate: string, yyyy-MM-dd,
  68117. * date: original date object.
  68118. * }
  68119. */
  68120. getDateInfo: function (date) {
  68121. date = parseDate(date);
  68122. var y = date.getFullYear();
  68123. var m = date.getMonth() + 1;
  68124. m = m < 10 ? '0' + m : m;
  68125. var d = date.getDate();
  68126. d = d < 10 ? '0' + d : d;
  68127. var day = date.getDay();
  68128. day = Math.abs((day + 7 - this.getFirstDayOfWeek()) % 7);
  68129. return {
  68130. y: y,
  68131. m: m,
  68132. d: d,
  68133. day: day,
  68134. time: date.getTime(),
  68135. formatedDate: y + '-' + m + '-' + d,
  68136. date: date
  68137. };
  68138. },
  68139. getNextNDay: function (date, n) {
  68140. n = n || 0;
  68141. if (n === 0) {
  68142. return this.getDateInfo(date);
  68143. }
  68144. date = new Date(this.getDateInfo(date).time);
  68145. date.setDate(date.getDate() + n);
  68146. return this.getDateInfo(date);
  68147. },
  68148. update: function (ecModel, api) {
  68149. this._firstDayOfWeek = +this._model.getModel('dayLabel').get('firstDay');
  68150. this._orient = this._model.get('orient');
  68151. this._lineWidth = this._model.getModel('itemStyle').getItemStyle().lineWidth || 0;
  68152. this._rangeInfo = this._getRangeInfo(this._initRangeOption());
  68153. var weeks = this._rangeInfo.weeks || 1;
  68154. var whNames = ['width', 'height'];
  68155. var cellSize = this._model.get('cellSize').slice();
  68156. var layoutParams = this._model.getBoxLayoutParams();
  68157. var cellNumbers = this._orient === 'horizontal' ? [weeks, 7] : [7, weeks];
  68158. each$1([0, 1], function (idx) {
  68159. if (cellSizeSpecified(cellSize, idx)) {
  68160. layoutParams[whNames[idx]] = cellSize[idx] * cellNumbers[idx];
  68161. }
  68162. });
  68163. var whGlobal = {
  68164. width: api.getWidth(),
  68165. height: api.getHeight()
  68166. };
  68167. var calendarRect = this._rect = getLayoutRect(layoutParams, whGlobal);
  68168. each$1([0, 1], function (idx) {
  68169. if (!cellSizeSpecified(cellSize, idx)) {
  68170. cellSize[idx] = calendarRect[whNames[idx]] / cellNumbers[idx];
  68171. }
  68172. });
  68173. function cellSizeSpecified(cellSize, idx) {
  68174. return cellSize[idx] != null && cellSize[idx] !== 'auto';
  68175. }
  68176. this._sw = cellSize[0];
  68177. this._sh = cellSize[1];
  68178. },
  68179. /**
  68180. * Convert a time data(time, value) item to (x, y) point.
  68181. *
  68182. * @override
  68183. * @param {Array|number} data data
  68184. * @param {boolean} [clamp=true] out of range
  68185. * @return {Array} point
  68186. */
  68187. dataToPoint: function (data, clamp) {
  68188. isArray(data) && (data = data[0]);
  68189. clamp == null && (clamp = true);
  68190. var dayInfo = this.getDateInfo(data);
  68191. var range = this._rangeInfo;
  68192. var date = dayInfo.formatedDate;
  68193. // if not in range return [NaN, NaN]
  68194. if (clamp && !(
  68195. dayInfo.time >= range.start.time
  68196. && dayInfo.time < range.end.time + PROXIMATE_ONE_DAY
  68197. )) {
  68198. return [NaN, NaN];
  68199. }
  68200. var week = dayInfo.day;
  68201. var nthWeek = this._getRangeInfo([range.start.time, date]).nthWeek;
  68202. if (this._orient === 'vertical') {
  68203. return [
  68204. this._rect.x + week * this._sw + this._sw / 2,
  68205. this._rect.y + nthWeek * this._sh + this._sh / 2
  68206. ];
  68207. }
  68208. return [
  68209. this._rect.x + nthWeek * this._sw + this._sw / 2,
  68210. this._rect.y + week * this._sh + this._sh / 2
  68211. ];
  68212. },
  68213. /**
  68214. * Convert a (x, y) point to time data
  68215. *
  68216. * @override
  68217. * @param {string} point point
  68218. * @return {string} data
  68219. */
  68220. pointToData: function (point) {
  68221. var date = this.pointToDate(point);
  68222. return date && date.time;
  68223. },
  68224. /**
  68225. * Convert a time date item to (x, y) four point.
  68226. *
  68227. * @param {Array} data date[0] is date
  68228. * @param {boolean} [clamp=true] out of range
  68229. * @return {Object} point
  68230. */
  68231. dataToRect: function (data, clamp) {
  68232. var point = this.dataToPoint(data, clamp);
  68233. return {
  68234. contentShape: {
  68235. x: point[0] - (this._sw - this._lineWidth) / 2,
  68236. y: point[1] - (this._sh - this._lineWidth) / 2,
  68237. width: this._sw - this._lineWidth,
  68238. height: this._sh - this._lineWidth
  68239. },
  68240. center: point,
  68241. tl: [
  68242. point[0] - this._sw / 2,
  68243. point[1] - this._sh / 2
  68244. ],
  68245. tr: [
  68246. point[0] + this._sw / 2,
  68247. point[1] - this._sh / 2
  68248. ],
  68249. br: [
  68250. point[0] + this._sw / 2,
  68251. point[1] + this._sh / 2
  68252. ],
  68253. bl: [
  68254. point[0] - this._sw / 2,
  68255. point[1] + this._sh / 2
  68256. ]
  68257. };
  68258. },
  68259. /**
  68260. * Convert a (x, y) point to time date
  68261. *
  68262. * @param {Array} point point
  68263. * @return {Object} date
  68264. */
  68265. pointToDate: function (point) {
  68266. var nthX = Math.floor((point[0] - this._rect.x) / this._sw) + 1;
  68267. var nthY = Math.floor((point[1] - this._rect.y) / this._sh) + 1;
  68268. var range = this._rangeInfo.range;
  68269. if (this._orient === 'vertical') {
  68270. return this._getDateByWeeksAndDay(nthY, nthX - 1, range);
  68271. }
  68272. return this._getDateByWeeksAndDay(nthX, nthY - 1, range);
  68273. },
  68274. /**
  68275. * @inheritDoc
  68276. */
  68277. convertToPixel: curry(doConvert$2, 'dataToPoint'),
  68278. /**
  68279. * @inheritDoc
  68280. */
  68281. convertFromPixel: curry(doConvert$2, 'pointToData'),
  68282. /**
  68283. * initRange
  68284. *
  68285. * @private
  68286. * @return {Array} [start, end]
  68287. */
  68288. _initRangeOption: function () {
  68289. var range = this._model.get('range');
  68290. var rg = range;
  68291. if (isArray(rg) && rg.length === 1) {
  68292. rg = rg[0];
  68293. }
  68294. if (/^\d{4}$/.test(rg)) {
  68295. range = [rg + '-01-01', rg + '-12-31'];
  68296. }
  68297. if (/^\d{4}[\/|-]\d{1,2}$/.test(rg)) {
  68298. var start = this.getDateInfo(rg);
  68299. var firstDay = start.date;
  68300. firstDay.setMonth(firstDay.getMonth() + 1);
  68301. var end = this.getNextNDay(firstDay, -1);
  68302. range = [start.formatedDate, end.formatedDate];
  68303. }
  68304. if (/^\d{4}[\/|-]\d{1,2}[\/|-]\d{1,2}$/.test(rg)) {
  68305. range = [rg, rg];
  68306. }
  68307. var tmp = this._getRangeInfo(range);
  68308. if (tmp.start.time > tmp.end.time) {
  68309. range.reverse();
  68310. }
  68311. return range;
  68312. },
  68313. /**
  68314. * range info
  68315. *
  68316. * @private
  68317. * @param {Array} range range ['2017-01-01', '2017-07-08']
  68318. * If range[0] > range[1], they will not be reversed.
  68319. * @return {Object} obj
  68320. */
  68321. _getRangeInfo: function (range) {
  68322. range = [
  68323. this.getDateInfo(range[0]),
  68324. this.getDateInfo(range[1])
  68325. ];
  68326. var reversed;
  68327. if (range[0].time > range[1].time) {
  68328. reversed = true;
  68329. range.reverse();
  68330. }
  68331. var allDay = Math.floor(range[1].time / PROXIMATE_ONE_DAY)
  68332. - Math.floor(range[0].time / PROXIMATE_ONE_DAY) + 1;
  68333. // Consider case:
  68334. // Firstly set system timezone as "Time Zone: America/Toronto",
  68335. // ```
  68336. // var first = new Date(1478412000000 - 3600 * 1000 * 2.5);
  68337. // var second = new Date(1478412000000);
  68338. // var allDays = Math.floor(second / ONE_DAY) - Math.floor(first / ONE_DAY) + 1;
  68339. // ```
  68340. // will get wrong result because of DST. So we should fix it.
  68341. var date = new Date(range[0].time);
  68342. var startDateNum = date.getDate();
  68343. var endDateNum = range[1].date.getDate();
  68344. date.setDate(startDateNum + allDay - 1);
  68345. // The bias can not over a month, so just compare date.
  68346. if (date.getDate() !== endDateNum) {
  68347. var sign = date.getTime() - range[1].time > 0 ? 1 : -1;
  68348. while (date.getDate() !== endDateNum && (date.getTime() - range[1].time) * sign > 0) {
  68349. allDay -= sign;
  68350. date.setDate(startDateNum + allDay - 1);
  68351. }
  68352. }
  68353. var weeks = Math.floor((allDay + range[0].day + 6) / 7);
  68354. var nthWeek = reversed ? -weeks + 1 : weeks - 1;
  68355. reversed && range.reverse();
  68356. return {
  68357. range: [range[0].formatedDate, range[1].formatedDate],
  68358. start: range[0],
  68359. end: range[1],
  68360. allDay: allDay,
  68361. weeks: weeks,
  68362. // From 0.
  68363. nthWeek: nthWeek,
  68364. fweek: range[0].day,
  68365. lweek: range[1].day
  68366. };
  68367. },
  68368. /**
  68369. * get date by nthWeeks and week day in range
  68370. *
  68371. * @private
  68372. * @param {number} nthWeek the week
  68373. * @param {number} day the week day
  68374. * @param {Array} range [d1, d2]
  68375. * @return {Object}
  68376. */
  68377. _getDateByWeeksAndDay: function (nthWeek, day, range) {
  68378. var rangeInfo = this._getRangeInfo(range);
  68379. if (nthWeek > rangeInfo.weeks
  68380. || (nthWeek === 0 && day < rangeInfo.fweek)
  68381. || (nthWeek === rangeInfo.weeks && day > rangeInfo.lweek)
  68382. ) {
  68383. return false;
  68384. }
  68385. var nthDay = (nthWeek - 1) * 7 - rangeInfo.fweek + day;
  68386. var date = new Date(rangeInfo.start.time);
  68387. date.setDate(rangeInfo.start.d + nthDay);
  68388. return this.getDateInfo(date);
  68389. }
  68390. };
  68391. Calendar.dimensions = Calendar.prototype.dimensions;
  68392. Calendar.getDimensionsInfo = Calendar.prototype.getDimensionsInfo;
  68393. Calendar.create = function (ecModel, api) {
  68394. var calendarList = [];
  68395. ecModel.eachComponent('calendar', function (calendarModel) {
  68396. var calendar = new Calendar(calendarModel, ecModel, api);
  68397. calendarList.push(calendar);
  68398. calendarModel.coordinateSystem = calendar;
  68399. });
  68400. ecModel.eachSeries(function (calendarSeries) {
  68401. if (calendarSeries.get('coordinateSystem') === 'calendar') {
  68402. // Inject coordinate system
  68403. calendarSeries.coordinateSystem = calendarList[calendarSeries.get('calendarIndex') || 0];
  68404. }
  68405. });
  68406. return calendarList;
  68407. };
  68408. function doConvert$2(methodName, ecModel, finder, value) {
  68409. var calendarModel = finder.calendarModel;
  68410. var seriesModel = finder.seriesModel;
  68411. var coordSys = calendarModel
  68412. ? calendarModel.coordinateSystem
  68413. : seriesModel
  68414. ? seriesModel.coordinateSystem
  68415. : null;
  68416. return coordSys === this ? coordSys[methodName](value) : null;
  68417. }
  68418. CoordinateSystemManager.register('calendar', Calendar);
  68419. /*
  68420. * Licensed to the Apache Software Foundation (ASF) under one
  68421. * or more contributor license agreements. See the NOTICE file
  68422. * distributed with this work for additional information
  68423. * regarding copyright ownership. The ASF licenses this file
  68424. * to you under the Apache License, Version 2.0 (the
  68425. * "License"); you may not use this file except in compliance
  68426. * with the License. You may obtain a copy of the License at
  68427. *
  68428. * http://www.apache.org/licenses/LICENSE-2.0
  68429. *
  68430. * Unless required by applicable law or agreed to in writing,
  68431. * software distributed under the License is distributed on an
  68432. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68433. * KIND, either express or implied. See the License for the
  68434. * specific language governing permissions and limitations
  68435. * under the License.
  68436. */
  68437. var CalendarModel = ComponentModel.extend({
  68438. type: 'calendar',
  68439. /**
  68440. * @type {module:echarts/coord/calendar/Calendar}
  68441. */
  68442. coordinateSystem: null,
  68443. defaultOption: {
  68444. zlevel: 0,
  68445. z: 2,
  68446. left: 80,
  68447. top: 60,
  68448. cellSize: 20,
  68449. // horizontal vertical
  68450. orient: 'horizontal',
  68451. // month separate line style
  68452. splitLine: {
  68453. show: true,
  68454. lineStyle: {
  68455. color: '#000',
  68456. width: 1,
  68457. type: 'solid'
  68458. }
  68459. },
  68460. // rect style temporarily unused emphasis
  68461. itemStyle: {
  68462. color: '#fff',
  68463. borderWidth: 1,
  68464. borderColor: '#ccc'
  68465. },
  68466. // week text style
  68467. dayLabel: {
  68468. show: true,
  68469. // a week first day
  68470. firstDay: 0,
  68471. // start end
  68472. position: 'start',
  68473. margin: '50%', // 50% of cellSize
  68474. nameMap: 'en',
  68475. color: '#000'
  68476. },
  68477. // month text style
  68478. monthLabel: {
  68479. show: true,
  68480. // start end
  68481. position: 'start',
  68482. margin: 5,
  68483. // center or left
  68484. align: 'center',
  68485. // cn en []
  68486. nameMap: 'en',
  68487. formatter: null,
  68488. color: '#000'
  68489. },
  68490. // year text style
  68491. yearLabel: {
  68492. show: true,
  68493. // top bottom left right
  68494. position: null,
  68495. margin: 30,
  68496. formatter: null,
  68497. color: '#ccc',
  68498. fontFamily: 'sans-serif',
  68499. fontWeight: 'bolder',
  68500. fontSize: 20
  68501. }
  68502. },
  68503. /**
  68504. * @override
  68505. */
  68506. init: function (option, parentModel, ecModel, extraOpt) {
  68507. var inputPositionParams = getLayoutParams(option);
  68508. CalendarModel.superApply(this, 'init', arguments);
  68509. mergeAndNormalizeLayoutParams$1(option, inputPositionParams);
  68510. },
  68511. /**
  68512. * @override
  68513. */
  68514. mergeOption: function (option, extraOpt) {
  68515. CalendarModel.superApply(this, 'mergeOption', arguments);
  68516. mergeAndNormalizeLayoutParams$1(this.option, option);
  68517. }
  68518. });
  68519. function mergeAndNormalizeLayoutParams$1(target, raw) {
  68520. // Normalize cellSize
  68521. var cellSize = target.cellSize;
  68522. if (!isArray(cellSize)) {
  68523. cellSize = target.cellSize = [cellSize, cellSize];
  68524. }
  68525. else if (cellSize.length === 1) {
  68526. cellSize[1] = cellSize[0];
  68527. }
  68528. var ignoreSize = map([0, 1], function (hvIdx) {
  68529. // If user have set `width` or both `left` and `right`, cellSize
  68530. // will be automatically set to 'auto', otherwise the default
  68531. // setting of cellSize will make `width` setting not work.
  68532. if (sizeCalculable(raw, hvIdx)) {
  68533. cellSize[hvIdx] = 'auto';
  68534. }
  68535. return cellSize[hvIdx] != null && cellSize[hvIdx] !== 'auto';
  68536. });
  68537. mergeLayoutParam(target, raw, {
  68538. type: 'box', ignoreSize: ignoreSize
  68539. });
  68540. }
  68541. /*
  68542. * Licensed to the Apache Software Foundation (ASF) under one
  68543. * or more contributor license agreements. See the NOTICE file
  68544. * distributed with this work for additional information
  68545. * regarding copyright ownership. The ASF licenses this file
  68546. * to you under the Apache License, Version 2.0 (the
  68547. * "License"); you may not use this file except in compliance
  68548. * with the License. You may obtain a copy of the License at
  68549. *
  68550. * http://www.apache.org/licenses/LICENSE-2.0
  68551. *
  68552. * Unless required by applicable law or agreed to in writing,
  68553. * software distributed under the License is distributed on an
  68554. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68555. * KIND, either express or implied. See the License for the
  68556. * specific language governing permissions and limitations
  68557. * under the License.
  68558. */
  68559. var MONTH_TEXT = {
  68560. EN: [
  68561. 'Jan', 'Feb', 'Mar',
  68562. 'Apr', 'May', 'Jun',
  68563. 'Jul', 'Aug', 'Sep',
  68564. 'Oct', 'Nov', 'Dec'
  68565. ],
  68566. CN: [
  68567. '一月', '二月', '三月',
  68568. '四月', '五月', '六月',
  68569. '七月', '八月', '九月',
  68570. '十月', '十一月', '十二月'
  68571. ]
  68572. };
  68573. var WEEK_TEXT = {
  68574. EN: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
  68575. CN: ['日', '一', '二', '三', '四', '五', '六']
  68576. };
  68577. extendComponentView({
  68578. type: 'calendar',
  68579. /**
  68580. * top/left line points
  68581. * @private
  68582. */
  68583. _tlpoints: null,
  68584. /**
  68585. * bottom/right line points
  68586. * @private
  68587. */
  68588. _blpoints: null,
  68589. /**
  68590. * first day of month
  68591. * @private
  68592. */
  68593. _firstDayOfMonth: null,
  68594. /**
  68595. * first day point of month
  68596. * @private
  68597. */
  68598. _firstDayPoints: null,
  68599. render: function (calendarModel, ecModel, api) {
  68600. var group = this.group;
  68601. group.removeAll();
  68602. var coordSys = calendarModel.coordinateSystem;
  68603. // range info
  68604. var rangeData = coordSys.getRangeInfo();
  68605. var orient = coordSys.getOrient();
  68606. this._renderDayRect(calendarModel, rangeData, group);
  68607. // _renderLines must be called prior to following function
  68608. this._renderLines(calendarModel, rangeData, orient, group);
  68609. this._renderYearText(calendarModel, rangeData, orient, group);
  68610. this._renderMonthText(calendarModel, orient, group);
  68611. this._renderWeekText(calendarModel, rangeData, orient, group);
  68612. },
  68613. // render day rect
  68614. _renderDayRect: function (calendarModel, rangeData, group) {
  68615. var coordSys = calendarModel.coordinateSystem;
  68616. var itemRectStyleModel = calendarModel.getModel('itemStyle').getItemStyle();
  68617. var sw = coordSys.getCellWidth();
  68618. var sh = coordSys.getCellHeight();
  68619. for (var i = rangeData.start.time;
  68620. i <= rangeData.end.time;
  68621. i = coordSys.getNextNDay(i, 1).time
  68622. ) {
  68623. var point = coordSys.dataToRect([i], false).tl;
  68624. // every rect
  68625. var rect = new Rect({
  68626. shape: {
  68627. x: point[0],
  68628. y: point[1],
  68629. width: sw,
  68630. height: sh
  68631. },
  68632. cursor: 'default',
  68633. style: itemRectStyleModel
  68634. });
  68635. group.add(rect);
  68636. }
  68637. },
  68638. // render separate line
  68639. _renderLines: function (calendarModel, rangeData, orient, group) {
  68640. var self = this;
  68641. var coordSys = calendarModel.coordinateSystem;
  68642. var lineStyleModel = calendarModel.getModel('splitLine.lineStyle').getLineStyle();
  68643. var show = calendarModel.get('splitLine.show');
  68644. var lineWidth = lineStyleModel.lineWidth;
  68645. this._tlpoints = [];
  68646. this._blpoints = [];
  68647. this._firstDayOfMonth = [];
  68648. this._firstDayPoints = [];
  68649. var firstDay = rangeData.start;
  68650. for (var i = 0; firstDay.time <= rangeData.end.time; i++) {
  68651. addPoints(firstDay.formatedDate);
  68652. if (i === 0) {
  68653. firstDay = coordSys.getDateInfo(rangeData.start.y + '-' + rangeData.start.m);
  68654. }
  68655. var date = firstDay.date;
  68656. date.setMonth(date.getMonth() + 1);
  68657. firstDay = coordSys.getDateInfo(date);
  68658. }
  68659. addPoints(coordSys.getNextNDay(rangeData.end.time, 1).formatedDate);
  68660. function addPoints(date) {
  68661. self._firstDayOfMonth.push(coordSys.getDateInfo(date));
  68662. self._firstDayPoints.push(coordSys.dataToRect([date], false).tl);
  68663. var points = self._getLinePointsOfOneWeek(calendarModel, date, orient);
  68664. self._tlpoints.push(points[0]);
  68665. self._blpoints.push(points[points.length - 1]);
  68666. show && self._drawSplitline(points, lineStyleModel, group);
  68667. }
  68668. // render top/left line
  68669. show && this._drawSplitline(self._getEdgesPoints(self._tlpoints, lineWidth, orient), lineStyleModel, group);
  68670. // render bottom/right line
  68671. show && this._drawSplitline(self._getEdgesPoints(self._blpoints, lineWidth, orient), lineStyleModel, group);
  68672. },
  68673. // get points at both ends
  68674. _getEdgesPoints: function (points, lineWidth, orient) {
  68675. var rs = [points[0].slice(), points[points.length - 1].slice()];
  68676. var idx = orient === 'horizontal' ? 0 : 1;
  68677. // both ends of the line are extend half lineWidth
  68678. rs[0][idx] = rs[0][idx] - lineWidth / 2;
  68679. rs[1][idx] = rs[1][idx] + lineWidth / 2;
  68680. return rs;
  68681. },
  68682. // render split line
  68683. _drawSplitline: function (points, lineStyleModel, group) {
  68684. var poyline = new Polyline({
  68685. z2: 20,
  68686. shape: {
  68687. points: points
  68688. },
  68689. style: lineStyleModel
  68690. });
  68691. group.add(poyline);
  68692. },
  68693. // render month line of one week points
  68694. _getLinePointsOfOneWeek: function (calendarModel, date, orient) {
  68695. var coordSys = calendarModel.coordinateSystem;
  68696. date = coordSys.getDateInfo(date);
  68697. var points = [];
  68698. for (var i = 0; i < 7; i++) {
  68699. var tmpD = coordSys.getNextNDay(date.time, i);
  68700. var point = coordSys.dataToRect([tmpD.time], false);
  68701. points[2 * tmpD.day] = point.tl;
  68702. points[2 * tmpD.day + 1] = point[orient === 'horizontal' ? 'bl' : 'tr'];
  68703. }
  68704. return points;
  68705. },
  68706. _formatterLabel: function (formatter, params) {
  68707. if (typeof formatter === 'string' && formatter) {
  68708. return formatTplSimple(formatter, params);
  68709. }
  68710. if (typeof formatter === 'function') {
  68711. return formatter(params);
  68712. }
  68713. return params.nameMap;
  68714. },
  68715. _yearTextPositionControl: function (textEl, point, orient, position, margin) {
  68716. point = point.slice();
  68717. var aligns = ['center', 'bottom'];
  68718. if (position === 'bottom') {
  68719. point[1] += margin;
  68720. aligns = ['center', 'top'];
  68721. }
  68722. else if (position === 'left') {
  68723. point[0] -= margin;
  68724. }
  68725. else if (position === 'right') {
  68726. point[0] += margin;
  68727. aligns = ['center', 'top'];
  68728. }
  68729. else { // top
  68730. point[1] -= margin;
  68731. }
  68732. var rotate = 0;
  68733. if (position === 'left' || position === 'right') {
  68734. rotate = Math.PI / 2;
  68735. }
  68736. return {
  68737. rotation: rotate,
  68738. position: point,
  68739. style: {
  68740. textAlign: aligns[0],
  68741. textVerticalAlign: aligns[1]
  68742. }
  68743. };
  68744. },
  68745. // render year
  68746. _renderYearText: function (calendarModel, rangeData, orient, group) {
  68747. var yearLabel = calendarModel.getModel('yearLabel');
  68748. if (!yearLabel.get('show')) {
  68749. return;
  68750. }
  68751. var margin = yearLabel.get('margin');
  68752. var pos = yearLabel.get('position');
  68753. if (!pos) {
  68754. pos = orient !== 'horizontal' ? 'top' : 'left';
  68755. }
  68756. var points = [this._tlpoints[this._tlpoints.length - 1], this._blpoints[0]];
  68757. var xc = (points[0][0] + points[1][0]) / 2;
  68758. var yc = (points[0][1] + points[1][1]) / 2;
  68759. var idx = orient === 'horizontal' ? 0 : 1;
  68760. var posPoints = {
  68761. top: [xc, points[idx][1]],
  68762. bottom: [xc, points[1 - idx][1]],
  68763. left: [points[1 - idx][0], yc],
  68764. right: [points[idx][0], yc]
  68765. };
  68766. var name = rangeData.start.y;
  68767. if (+rangeData.end.y > +rangeData.start.y) {
  68768. name = name + '-' + rangeData.end.y;
  68769. }
  68770. var formatter = yearLabel.get('formatter');
  68771. var params = {
  68772. start: rangeData.start.y,
  68773. end: rangeData.end.y,
  68774. nameMap: name
  68775. };
  68776. var content = this._formatterLabel(formatter, params);
  68777. var yearText = new Text({z2: 30});
  68778. setTextStyle(yearText.style, yearLabel, {text: content}),
  68779. yearText.attr(this._yearTextPositionControl(yearText, posPoints[pos], orient, pos, margin));
  68780. group.add(yearText);
  68781. },
  68782. _monthTextPositionControl: function (point, isCenter, orient, position, margin) {
  68783. var align = 'left';
  68784. var vAlign = 'top';
  68785. var x = point[0];
  68786. var y = point[1];
  68787. if (orient === 'horizontal') {
  68788. y = y + margin;
  68789. if (isCenter) {
  68790. align = 'center';
  68791. }
  68792. if (position === 'start') {
  68793. vAlign = 'bottom';
  68794. }
  68795. }
  68796. else {
  68797. x = x + margin;
  68798. if (isCenter) {
  68799. vAlign = 'middle';
  68800. }
  68801. if (position === 'start') {
  68802. align = 'right';
  68803. }
  68804. }
  68805. return {
  68806. x: x,
  68807. y: y,
  68808. textAlign: align,
  68809. textVerticalAlign: vAlign
  68810. };
  68811. },
  68812. // render month and year text
  68813. _renderMonthText: function (calendarModel, orient, group) {
  68814. var monthLabel = calendarModel.getModel('monthLabel');
  68815. if (!monthLabel.get('show')) {
  68816. return;
  68817. }
  68818. var nameMap = monthLabel.get('nameMap');
  68819. var margin = monthLabel.get('margin');
  68820. var pos = monthLabel.get('position');
  68821. var align = monthLabel.get('align');
  68822. var termPoints = [this._tlpoints, this._blpoints];
  68823. if (isString(nameMap)) {
  68824. nameMap = MONTH_TEXT[nameMap.toUpperCase()] || [];
  68825. }
  68826. var idx = pos === 'start' ? 0 : 1;
  68827. var axis = orient === 'horizontal' ? 0 : 1;
  68828. margin = pos === 'start' ? -margin : margin;
  68829. var isCenter = (align === 'center');
  68830. for (var i = 0; i < termPoints[idx].length - 1; i++) {
  68831. var tmp = termPoints[idx][i].slice();
  68832. var firstDay = this._firstDayOfMonth[i];
  68833. if (isCenter) {
  68834. var firstDayPoints = this._firstDayPoints[i];
  68835. tmp[axis] = (firstDayPoints[axis] + termPoints[0][i + 1][axis]) / 2;
  68836. }
  68837. var formatter = monthLabel.get('formatter');
  68838. var name = nameMap[+firstDay.m - 1];
  68839. var params = {
  68840. yyyy: firstDay.y,
  68841. yy: (firstDay.y + '').slice(2),
  68842. MM: firstDay.m,
  68843. M: +firstDay.m,
  68844. nameMap: name
  68845. };
  68846. var content = this._formatterLabel(formatter, params);
  68847. var monthText = new Text({z2: 30});
  68848. extend(
  68849. setTextStyle(monthText.style, monthLabel, {text: content}),
  68850. this._monthTextPositionControl(tmp, isCenter, orient, pos, margin)
  68851. );
  68852. group.add(monthText);
  68853. }
  68854. },
  68855. _weekTextPositionControl: function (point, orient, position, margin, cellSize) {
  68856. var align = 'center';
  68857. var vAlign = 'middle';
  68858. var x = point[0];
  68859. var y = point[1];
  68860. var isStart = position === 'start';
  68861. if (orient === 'horizontal') {
  68862. x = x + margin + (isStart ? 1 : -1) * cellSize[0] / 2;
  68863. align = isStart ? 'right' : 'left';
  68864. }
  68865. else {
  68866. y = y + margin + (isStart ? 1 : -1) * cellSize[1] / 2;
  68867. vAlign = isStart ? 'bottom' : 'top';
  68868. }
  68869. return {
  68870. x: x,
  68871. y: y,
  68872. textAlign: align,
  68873. textVerticalAlign: vAlign
  68874. };
  68875. },
  68876. // render weeks
  68877. _renderWeekText: function (calendarModel, rangeData, orient, group) {
  68878. var dayLabel = calendarModel.getModel('dayLabel');
  68879. if (!dayLabel.get('show')) {
  68880. return;
  68881. }
  68882. var coordSys = calendarModel.coordinateSystem;
  68883. var pos = dayLabel.get('position');
  68884. var nameMap = dayLabel.get('nameMap');
  68885. var margin = dayLabel.get('margin');
  68886. var firstDayOfWeek = coordSys.getFirstDayOfWeek();
  68887. if (isString(nameMap)) {
  68888. nameMap = WEEK_TEXT[nameMap.toUpperCase()] || [];
  68889. }
  68890. var start = coordSys.getNextNDay(
  68891. rangeData.end.time, (7 - rangeData.lweek)
  68892. ).time;
  68893. var cellSize = [coordSys.getCellWidth(), coordSys.getCellHeight()];
  68894. margin = parsePercent$1(margin, cellSize[orient === 'horizontal' ? 0 : 1]);
  68895. if (pos === 'start') {
  68896. start = coordSys.getNextNDay(
  68897. rangeData.start.time, -(7 + rangeData.fweek)
  68898. ).time;
  68899. margin = -margin;
  68900. }
  68901. for (var i = 0; i < 7; i++) {
  68902. var tmpD = coordSys.getNextNDay(start, i);
  68903. var point = coordSys.dataToRect([tmpD.time], false).center;
  68904. var day = i;
  68905. day = Math.abs((i + firstDayOfWeek) % 7);
  68906. var weekText = new Text({z2: 30});
  68907. extend(
  68908. setTextStyle(weekText.style, dayLabel, {text: nameMap[day]}),
  68909. this._weekTextPositionControl(point, orient, pos, margin, cellSize)
  68910. );
  68911. group.add(weekText);
  68912. }
  68913. }
  68914. });
  68915. /*
  68916. * Licensed to the Apache Software Foundation (ASF) under one
  68917. * or more contributor license agreements. See the NOTICE file
  68918. * distributed with this work for additional information
  68919. * regarding copyright ownership. The ASF licenses this file
  68920. * to you under the Apache License, Version 2.0 (the
  68921. * "License"); you may not use this file except in compliance
  68922. * with the License. You may obtain a copy of the License at
  68923. *
  68924. * http://www.apache.org/licenses/LICENSE-2.0
  68925. *
  68926. * Unless required by applicable law or agreed to in writing,
  68927. * software distributed under the License is distributed on an
  68928. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68929. * KIND, either express or implied. See the License for the
  68930. * specific language governing permissions and limitations
  68931. * under the License.
  68932. */
  68933. /**
  68934. * @file calendar.js
  68935. * @author dxh
  68936. */
  68937. /*
  68938. * Licensed to the Apache Software Foundation (ASF) under one
  68939. * or more contributor license agreements. See the NOTICE file
  68940. * distributed with this work for additional information
  68941. * regarding copyright ownership. The ASF licenses this file
  68942. * to you under the Apache License, Version 2.0 (the
  68943. * "License"); you may not use this file except in compliance
  68944. * with the License. You may obtain a copy of the License at
  68945. *
  68946. * http://www.apache.org/licenses/LICENSE-2.0
  68947. *
  68948. * Unless required by applicable law or agreed to in writing,
  68949. * software distributed under the License is distributed on an
  68950. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68951. * KIND, either express or implied. See the License for the
  68952. * specific language governing permissions and limitations
  68953. * under the License.
  68954. */
  68955. // Model
  68956. extendComponentModel({
  68957. type: 'title',
  68958. layoutMode: {type: 'box', ignoreSize: true},
  68959. defaultOption: {
  68960. // 一级层叠
  68961. zlevel: 0,
  68962. // 二级层叠
  68963. z: 6,
  68964. show: true,
  68965. text: '',
  68966. // 超链接跳转
  68967. // link: null,
  68968. // 仅支持self | blank
  68969. target: 'blank',
  68970. subtext: '',
  68971. // 超链接跳转
  68972. // sublink: null,
  68973. // 仅支持self | blank
  68974. subtarget: 'blank',
  68975. // 'center' ¦ 'left' ¦ 'right'
  68976. // ¦ {number}(x坐标,单位px)
  68977. left: 0,
  68978. // 'top' ¦ 'bottom' ¦ 'center'
  68979. // ¦ {number}(y坐标,单位px)
  68980. top: 0,
  68981. // 水平对齐
  68982. // 'auto' | 'left' | 'right' | 'center'
  68983. // 默认根据 left 的位置判断是左对齐还是右对齐
  68984. // textAlign: null
  68985. //
  68986. // 垂直对齐
  68987. // 'auto' | 'top' | 'bottom' | 'middle'
  68988. // 默认根据 top 位置判断是上对齐还是下对齐
  68989. // textBaseline: null
  68990. backgroundColor: 'rgba(0,0,0,0)',
  68991. // 标题边框颜色
  68992. borderColor: '#ccc',
  68993. // 标题边框线宽,单位px,默认为0(无边框)
  68994. borderWidth: 0,
  68995. // 标题内边距,单位px,默认各方向内边距为5,
  68996. // 接受数组分别设定上右下左边距,同css
  68997. padding: 5,
  68998. // 主副标题纵向间隔,单位px,默认为10,
  68999. itemGap: 10,
  69000. textStyle: {
  69001. fontSize: 18,
  69002. fontWeight: 'bolder',
  69003. color: '#333'
  69004. },
  69005. subtextStyle: {
  69006. color: '#aaa'
  69007. }
  69008. }
  69009. });
  69010. // View
  69011. extendComponentView({
  69012. type: 'title',
  69013. render: function (titleModel, ecModel, api) {
  69014. this.group.removeAll();
  69015. if (!titleModel.get('show')) {
  69016. return;
  69017. }
  69018. var group = this.group;
  69019. var textStyleModel = titleModel.getModel('textStyle');
  69020. var subtextStyleModel = titleModel.getModel('subtextStyle');
  69021. var textAlign = titleModel.get('textAlign');
  69022. var textBaseline = titleModel.get('textBaseline');
  69023. var textEl = new Text({
  69024. style: setTextStyle({}, textStyleModel, {
  69025. text: titleModel.get('text'),
  69026. textFill: textStyleModel.getTextColor()
  69027. }, {disableBox: true}),
  69028. z2: 10
  69029. });
  69030. var textRect = textEl.getBoundingRect();
  69031. var subText = titleModel.get('subtext');
  69032. var subTextEl = new Text({
  69033. style: setTextStyle({}, subtextStyleModel, {
  69034. text: subText,
  69035. textFill: subtextStyleModel.getTextColor(),
  69036. y: textRect.height + titleModel.get('itemGap'),
  69037. textVerticalAlign: 'top'
  69038. }, {disableBox: true}),
  69039. z2: 10
  69040. });
  69041. var link = titleModel.get('link');
  69042. var sublink = titleModel.get('sublink');
  69043. var triggerEvent = titleModel.get('triggerEvent', true);
  69044. textEl.silent = !link && !triggerEvent;
  69045. subTextEl.silent = !sublink && !triggerEvent;
  69046. if (link) {
  69047. textEl.on('click', function () {
  69048. window.open(link, '_' + titleModel.get('target'));
  69049. });
  69050. }
  69051. if (sublink) {
  69052. subTextEl.on('click', function () {
  69053. window.open(sublink, '_' + titleModel.get('subtarget'));
  69054. });
  69055. }
  69056. textEl.eventData = subTextEl.eventData = triggerEvent
  69057. ? {
  69058. componentType: 'title',
  69059. componentIndex: titleModel.componentIndex
  69060. }
  69061. : null;
  69062. group.add(textEl);
  69063. subText && group.add(subTextEl);
  69064. // If no subText, but add subTextEl, there will be an empty line.
  69065. var groupRect = group.getBoundingRect();
  69066. var layoutOption = titleModel.getBoxLayoutParams();
  69067. layoutOption.width = groupRect.width;
  69068. layoutOption.height = groupRect.height;
  69069. var layoutRect = getLayoutRect(
  69070. layoutOption, {
  69071. width: api.getWidth(),
  69072. height: api.getHeight()
  69073. }, titleModel.get('padding')
  69074. );
  69075. // Adjust text align based on position
  69076. if (!textAlign) {
  69077. // Align left if title is on the left. center and right is same
  69078. textAlign = titleModel.get('left') || titleModel.get('right');
  69079. if (textAlign === 'middle') {
  69080. textAlign = 'center';
  69081. }
  69082. // Adjust layout by text align
  69083. if (textAlign === 'right') {
  69084. layoutRect.x += layoutRect.width;
  69085. }
  69086. else if (textAlign === 'center') {
  69087. layoutRect.x += layoutRect.width / 2;
  69088. }
  69089. }
  69090. if (!textBaseline) {
  69091. textBaseline = titleModel.get('top') || titleModel.get('bottom');
  69092. if (textBaseline === 'center') {
  69093. textBaseline = 'middle';
  69094. }
  69095. if (textBaseline === 'bottom') {
  69096. layoutRect.y += layoutRect.height;
  69097. }
  69098. else if (textBaseline === 'middle') {
  69099. layoutRect.y += layoutRect.height / 2;
  69100. }
  69101. textBaseline = textBaseline || 'top';
  69102. }
  69103. group.attr('position', [layoutRect.x, layoutRect.y]);
  69104. var alignStyle = {
  69105. textAlign: textAlign,
  69106. textVerticalAlign: textBaseline
  69107. };
  69108. textEl.setStyle(alignStyle);
  69109. subTextEl.setStyle(alignStyle);
  69110. // Render background
  69111. // Get groupRect again because textAlign has been changed
  69112. groupRect = group.getBoundingRect();
  69113. var padding = layoutRect.margin;
  69114. var style = titleModel.getItemStyle(['color', 'opacity']);
  69115. style.fill = titleModel.get('backgroundColor');
  69116. var rect = new Rect({
  69117. shape: {
  69118. x: groupRect.x - padding[3],
  69119. y: groupRect.y - padding[0],
  69120. width: groupRect.width + padding[1] + padding[3],
  69121. height: groupRect.height + padding[0] + padding[2],
  69122. r: titleModel.get('borderRadius')
  69123. },
  69124. style: style,
  69125. silent: true
  69126. });
  69127. subPixelOptimizeRect(rect);
  69128. group.add(rect);
  69129. }
  69130. });
  69131. /*
  69132. * Licensed to the Apache Software Foundation (ASF) under one
  69133. * or more contributor license agreements. See the NOTICE file
  69134. * distributed with this work for additional information
  69135. * regarding copyright ownership. The ASF licenses this file
  69136. * to you under the Apache License, Version 2.0 (the
  69137. * "License"); you may not use this file except in compliance
  69138. * with the License. You may obtain a copy of the License at
  69139. *
  69140. * http://www.apache.org/licenses/LICENSE-2.0
  69141. *
  69142. * Unless required by applicable law or agreed to in writing,
  69143. * software distributed under the License is distributed on an
  69144. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  69145. * KIND, either express or implied. See the License for the
  69146. * specific language governing permissions and limitations
  69147. * under the License.
  69148. */
  69149. ComponentModel.registerSubTypeDefaulter('dataZoom', function () {
  69150. // Default 'slider' when no type specified.
  69151. return 'slider';
  69152. });
  69153. /*
  69154. * Licensed to the Apache Software Foundation (ASF) under one
  69155. * or more contributor license agreements. See the NOTICE file
  69156. * distributed with this work for additional information
  69157. * regarding copyright ownership. The ASF licenses this file
  69158. * to you under the Apache License, Version 2.0 (the
  69159. * "License"); you may not use this file except in compliance
  69160. * with the License. You may obtain a copy of the License at
  69161. *
  69162. * http://www.apache.org/licenses/LICENSE-2.0
  69163. *
  69164. * Unless required by applicable law or agreed to in writing,
  69165. * software distributed under the License is distributed on an
  69166. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  69167. * KIND, either express or implied. See the License for the
  69168. * specific language governing permissions and limitations
  69169. * under the License.
  69170. */
  69171. var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle', 'single'];
  69172. // Supported coords.
  69173. var COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  69174. /**
  69175. * @param {string} coordType
  69176. * @return {boolean}
  69177. */
  69178. function isCoordSupported(coordType) {
  69179. return indexOf(COORDS, coordType) >= 0;
  69180. }
  69181. /**
  69182. * Create "each" method to iterate names.
  69183. *
  69184. * @pubilc
  69185. * @param {Array.<string>} names
  69186. * @param {Array.<string>=} attrs
  69187. * @return {Function}
  69188. */
  69189. function createNameEach(names, attrs) {
  69190. names = names.slice();
  69191. var capitalNames = map(names, capitalFirst);
  69192. attrs = (attrs || []).slice();
  69193. var capitalAttrs = map(attrs, capitalFirst);
  69194. return function (callback, context) {
  69195. each$1(names, function (name, index) {
  69196. var nameObj = {name: name, capital: capitalNames[index]};
  69197. for (var j = 0; j < attrs.length; j++) {
  69198. nameObj[attrs[j]] = name + capitalAttrs[j];
  69199. }
  69200. callback.call(context, nameObj);
  69201. });
  69202. };
  69203. }
  69204. /**
  69205. * Iterate each dimension name.
  69206. *
  69207. * @public
  69208. * @param {Function} callback The parameter is like:
  69209. * {
  69210. * name: 'angle',
  69211. * capital: 'Angle',
  69212. * axis: 'angleAxis',
  69213. * axisIndex: 'angleAixs',
  69214. * index: 'angleIndex'
  69215. * }
  69216. * @param {Object} context
  69217. */
  69218. var eachAxisDim$1 = createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index', 'id']);
  69219. /**
  69220. * If tow dataZoomModels has the same axis controlled, we say that they are 'linked'.
  69221. * dataZoomModels and 'links' make up one or more graphics.
  69222. * This function finds the graphic where the source dataZoomModel is in.
  69223. *
  69224. * @public
  69225. * @param {Function} forEachNode Node iterator.
  69226. * @param {Function} forEachEdgeType edgeType iterator
  69227. * @param {Function} edgeIdGetter Giving node and edgeType, return an array of edge id.
  69228. * @return {Function} Input: sourceNode, Output: Like {nodes: [], dims: {}}
  69229. */
  69230. function createLinkedNodesFinder(forEachNode, forEachEdgeType, edgeIdGetter) {
  69231. return function (sourceNode) {
  69232. var result = {
  69233. nodes: [],
  69234. records: {} // key: edgeType.name, value: Object (key: edge id, value: boolean).
  69235. };
  69236. forEachEdgeType(function (edgeType) {
  69237. result.records[edgeType.name] = {};
  69238. });
  69239. if (!sourceNode) {
  69240. return result;
  69241. }
  69242. absorb(sourceNode, result);
  69243. var existsLink;
  69244. do {
  69245. existsLink = false;
  69246. forEachNode(processSingleNode);
  69247. }
  69248. while (existsLink);
  69249. function processSingleNode(node) {
  69250. if (!isNodeAbsorded(node, result) && isLinked(node, result)) {
  69251. absorb(node, result);
  69252. existsLink = true;
  69253. }
  69254. }
  69255. return result;
  69256. };
  69257. function isNodeAbsorded(node, result) {
  69258. return indexOf(result.nodes, node) >= 0;
  69259. }
  69260. function isLinked(node, result) {
  69261. var hasLink = false;
  69262. forEachEdgeType(function (edgeType) {
  69263. each$1(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  69264. result.records[edgeType.name][edgeId] && (hasLink = true);
  69265. });
  69266. });
  69267. return hasLink;
  69268. }
  69269. function absorb(node, result) {
  69270. result.nodes.push(node);
  69271. forEachEdgeType(function (edgeType) {
  69272. each$1(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  69273. result.records[edgeType.name][edgeId] = true;
  69274. });
  69275. });
  69276. }
  69277. }
  69278. /*
  69279. * Licensed to the Apache Software Foundation (ASF) under one
  69280. * or more contributor license agreements. See the NOTICE file
  69281. * distributed with this work for additional information
  69282. * regarding copyright ownership. The ASF licenses this file
  69283. * to you under the Apache License, Version 2.0 (the
  69284. * "License"); you may not use this file except in compliance
  69285. * with the License. You may obtain a copy of the License at
  69286. *
  69287. * http://www.apache.org/licenses/LICENSE-2.0
  69288. *
  69289. * Unless required by applicable law or agreed to in writing,
  69290. * software distributed under the License is distributed on an
  69291. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  69292. * KIND, either express or implied. See the License for the
  69293. * specific language governing permissions and limitations
  69294. * under the License.
  69295. */
  69296. var each$22 = each$1;
  69297. var asc$1 = asc;
  69298. /**
  69299. * Operate single axis.
  69300. * One axis can only operated by one axis operator.
  69301. * Different dataZoomModels may be defined to operate the same axis.
  69302. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  69303. * So dataZoomModels share one axisProxy in that case.
  69304. *
  69305. * @class
  69306. */
  69307. var AxisProxy = function (dimName, axisIndex, dataZoomModel, ecModel) {
  69308. /**
  69309. * @private
  69310. * @type {string}
  69311. */
  69312. this._dimName = dimName;
  69313. /**
  69314. * @private
  69315. */
  69316. this._axisIndex = axisIndex;
  69317. /**
  69318. * @private
  69319. * @type {Array.<number>}
  69320. */
  69321. this._valueWindow;
  69322. /**
  69323. * @private
  69324. * @type {Array.<number>}
  69325. */
  69326. this._percentWindow;
  69327. /**
  69328. * @private
  69329. * @type {Array.<number>}
  69330. */
  69331. this._dataExtent;
  69332. /**
  69333. * {minSpan, maxSpan, minValueSpan, maxValueSpan}
  69334. * @private
  69335. * @type {Object}
  69336. */
  69337. this._minMaxSpan;
  69338. /**
  69339. * @readOnly
  69340. * @type {module: echarts/model/Global}
  69341. */
  69342. this.ecModel = ecModel;
  69343. /**
  69344. * @private
  69345. * @type {module: echarts/component/dataZoom/DataZoomModel}
  69346. */
  69347. this._dataZoomModel = dataZoomModel;
  69348. // /**
  69349. // * @readOnly
  69350. // * @private
  69351. // */
  69352. // this.hasSeriesStacked;
  69353. };
  69354. AxisProxy.prototype = {
  69355. constructor: AxisProxy,
  69356. /**
  69357. * Whether the axisProxy is hosted by dataZoomModel.
  69358. *
  69359. * @public
  69360. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  69361. * @return {boolean}
  69362. */
  69363. hostedBy: function (dataZoomModel) {
  69364. return this._dataZoomModel === dataZoomModel;
  69365. },
  69366. /**
  69367. * @return {Array.<number>} Value can only be NaN or finite value.
  69368. */
  69369. getDataValueWindow: function () {
  69370. return this._valueWindow.slice();
  69371. },
  69372. /**
  69373. * @return {Array.<number>}
  69374. */
  69375. getDataPercentWindow: function () {
  69376. return this._percentWindow.slice();
  69377. },
  69378. /**
  69379. * @public
  69380. * @param {number} axisIndex
  69381. * @return {Array} seriesModels
  69382. */
  69383. getTargetSeriesModels: function () {
  69384. var seriesModels = [];
  69385. var ecModel = this.ecModel;
  69386. ecModel.eachSeries(function (seriesModel) {
  69387. if (isCoordSupported(seriesModel.get('coordinateSystem'))) {
  69388. var dimName = this._dimName;
  69389. var axisModel = ecModel.queryComponents({
  69390. mainType: dimName + 'Axis',
  69391. index: seriesModel.get(dimName + 'AxisIndex'),
  69392. id: seriesModel.get(dimName + 'AxisId')
  69393. })[0];
  69394. if (this._axisIndex === (axisModel && axisModel.componentIndex)) {
  69395. seriesModels.push(seriesModel);
  69396. }
  69397. }
  69398. }, this);
  69399. return seriesModels;
  69400. },
  69401. getAxisModel: function () {
  69402. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  69403. },
  69404. getOtherAxisModel: function () {
  69405. var axisDim = this._dimName;
  69406. var ecModel = this.ecModel;
  69407. var axisModel = this.getAxisModel();
  69408. var isCartesian = axisDim === 'x' || axisDim === 'y';
  69409. var otherAxisDim;
  69410. var coordSysIndexName;
  69411. if (isCartesian) {
  69412. coordSysIndexName = 'gridIndex';
  69413. otherAxisDim = axisDim === 'x' ? 'y' : 'x';
  69414. }
  69415. else {
  69416. coordSysIndexName = 'polarIndex';
  69417. otherAxisDim = axisDim === 'angle' ? 'radius' : 'angle';
  69418. }
  69419. var foundOtherAxisModel;
  69420. ecModel.eachComponent(otherAxisDim + 'Axis', function (otherAxisModel) {
  69421. if ((otherAxisModel.get(coordSysIndexName) || 0)
  69422. === (axisModel.get(coordSysIndexName) || 0)
  69423. ) {
  69424. foundOtherAxisModel = otherAxisModel;
  69425. }
  69426. });
  69427. return foundOtherAxisModel;
  69428. },
  69429. getMinMaxSpan: function () {
  69430. return clone(this._minMaxSpan);
  69431. },
  69432. /**
  69433. * Only calculate by given range and this._dataExtent, do not change anything.
  69434. *
  69435. * @param {Object} opt
  69436. * @param {number} [opt.start]
  69437. * @param {number} [opt.end]
  69438. * @param {number} [opt.startValue]
  69439. * @param {number} [opt.endValue]
  69440. */
  69441. calculateDataWindow: function (opt) {
  69442. var dataExtent = this._dataExtent;
  69443. var axisModel = this.getAxisModel();
  69444. var scale = axisModel.axis.scale;
  69445. var rangePropMode = this._dataZoomModel.getRangePropMode();
  69446. var percentExtent = [0, 100];
  69447. var percentWindow = [
  69448. opt.start,
  69449. opt.end
  69450. ];
  69451. var valueWindow = [];
  69452. each$22(['startValue', 'endValue'], function (prop) {
  69453. valueWindow.push(opt[prop] != null ? scale.parse(opt[prop]) : null);
  69454. });
  69455. // Normalize bound.
  69456. each$22([0, 1], function (idx) {
  69457. var boundValue = valueWindow[idx];
  69458. var boundPercent = percentWindow[idx];
  69459. // Notice: dataZoom is based either on `percentProp` ('start', 'end') or
  69460. // on `valueProp` ('startValue', 'endValue'). The former one is suitable
  69461. // for cases that a dataZoom component controls multiple axes with different
  69462. // unit or extent, and the latter one is suitable for accurate zoom by pixel
  69463. // (e.g., in dataZoomSelect). `valueProp` can be calculated from `percentProp`,
  69464. // but it is awkward that `percentProp` can not be obtained from `valueProp`
  69465. // accurately (because all of values that are overflow the `dataExtent` will
  69466. // be calculated to percent '100%'). So we have to use
  69467. // `dataZoom.getRangePropMode()` to mark which prop is used.
  69468. // `rangePropMode` is updated only when setOption or dispatchAction, otherwise
  69469. // it remains its original value.
  69470. if (rangePropMode[idx] === 'percent') {
  69471. if (boundPercent == null) {
  69472. boundPercent = percentExtent[idx];
  69473. }
  69474. // Use scale.parse to math round for category or time axis.
  69475. boundValue = scale.parse(linearMap(
  69476. boundPercent, percentExtent, dataExtent, true
  69477. ));
  69478. }
  69479. else {
  69480. // Calculating `percent` from `value` may be not accurate, because
  69481. // This calculation can not be inversed, because all of values that
  69482. // are overflow the `dataExtent` will be calculated to percent '100%'
  69483. boundPercent = linearMap(
  69484. boundValue, dataExtent, percentExtent, true
  69485. );
  69486. }
  69487. // valueWindow[idx] = round(boundValue);
  69488. // percentWindow[idx] = round(boundPercent);
  69489. valueWindow[idx] = boundValue;
  69490. percentWindow[idx] = boundPercent;
  69491. });
  69492. return {
  69493. valueWindow: asc$1(valueWindow),
  69494. percentWindow: asc$1(percentWindow)
  69495. };
  69496. },
  69497. /**
  69498. * Notice: reset should not be called before series.restoreData() called,
  69499. * so it is recommanded to be called in "process stage" but not "model init
  69500. * stage".
  69501. *
  69502. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  69503. */
  69504. reset: function (dataZoomModel) {
  69505. if (dataZoomModel !== this._dataZoomModel) {
  69506. return;
  69507. }
  69508. var targetSeries = this.getTargetSeriesModels();
  69509. // Culculate data window and data extent, and record them.
  69510. this._dataExtent = calculateDataExtent(this, this._dimName, targetSeries);
  69511. // this.hasSeriesStacked = false;
  69512. // each(targetSeries, function (series) {
  69513. // var data = series.getData();
  69514. // var dataDim = data.mapDimension(this._dimName);
  69515. // var stackedDimension = data.getCalculationInfo('stackedDimension');
  69516. // if (stackedDimension && stackedDimension === dataDim) {
  69517. // this.hasSeriesStacked = true;
  69518. // }
  69519. // }, this);
  69520. var dataWindow = this.calculateDataWindow(dataZoomModel.option);
  69521. this._valueWindow = dataWindow.valueWindow;
  69522. this._percentWindow = dataWindow.percentWindow;
  69523. setMinMaxSpan(this);
  69524. // Update axis setting then.
  69525. setAxisModel(this);
  69526. },
  69527. /**
  69528. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  69529. */
  69530. restore: function (dataZoomModel) {
  69531. if (dataZoomModel !== this._dataZoomModel) {
  69532. return;
  69533. }
  69534. this._valueWindow = this._percentWindow = null;
  69535. setAxisModel(this, true);
  69536. },
  69537. /**
  69538. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  69539. */
  69540. filterData: function (dataZoomModel, api) {
  69541. if (dataZoomModel !== this._dataZoomModel) {
  69542. return;
  69543. }
  69544. var axisDim = this._dimName;
  69545. var seriesModels = this.getTargetSeriesModels();
  69546. var filterMode = dataZoomModel.get('filterMode');
  69547. var valueWindow = this._valueWindow;
  69548. if (filterMode === 'none') {
  69549. return;
  69550. }
  69551. // FIXME
  69552. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  69553. // with NaN data, NaN will be filtered and stack will be wrong.
  69554. // So we need to force the mode to be set empty.
  69555. // In fect, it is not a big deal that do not support filterMode-'filter'
  69556. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  69557. // selection" some day, which might need "adapt to data extent on the
  69558. // otherAxis", which is disabled by filterMode-'empty'.
  69559. // But currently, stack has been fixed to based on value but not index,
  69560. // so this is not an issue any more.
  69561. // var otherAxisModel = this.getOtherAxisModel();
  69562. // if (dataZoomModel.get('$fromToolbox')
  69563. // && otherAxisModel
  69564. // && otherAxisModel.hasSeriesStacked
  69565. // ) {
  69566. // filterMode = 'empty';
  69567. // }
  69568. // TODO
  69569. // filterMode 'weakFilter' and 'empty' is not optimized for huge data yet.
  69570. each$22(seriesModels, function (seriesModel) {
  69571. var seriesData = seriesModel.getData();
  69572. var dataDims = seriesData.mapDimension(axisDim, true);
  69573. if (!dataDims.length) {
  69574. return;
  69575. }
  69576. if (filterMode === 'weakFilter') {
  69577. seriesData.filterSelf(function (dataIndex) {
  69578. var leftOut;
  69579. var rightOut;
  69580. var hasValue;
  69581. for (var i = 0; i < dataDims.length; i++) {
  69582. var value = seriesData.get(dataDims[i], dataIndex);
  69583. var thisHasValue = !isNaN(value);
  69584. var thisLeftOut = value < valueWindow[0];
  69585. var thisRightOut = value > valueWindow[1];
  69586. if (thisHasValue && !thisLeftOut && !thisRightOut) {
  69587. return true;
  69588. }
  69589. thisHasValue && (hasValue = true);
  69590. thisLeftOut && (leftOut = true);
  69591. thisRightOut && (rightOut = true);
  69592. }
  69593. // If both left out and right out, do not filter.
  69594. return hasValue && leftOut && rightOut;
  69595. });
  69596. }
  69597. else {
  69598. each$22(dataDims, function (dim) {
  69599. if (filterMode === 'empty') {
  69600. seriesModel.setData(
  69601. seriesData.map(dim, function (value) {
  69602. return !isInWindow(value) ? NaN : value;
  69603. })
  69604. );
  69605. }
  69606. else {
  69607. var range = {};
  69608. range[dim] = valueWindow;
  69609. // console.time('select');
  69610. seriesData.selectRange(range);
  69611. // console.timeEnd('select');
  69612. }
  69613. });
  69614. }
  69615. each$22(dataDims, function (dim) {
  69616. seriesData.setApproximateExtent(valueWindow, dim);
  69617. });
  69618. });
  69619. function isInWindow(value) {
  69620. return value >= valueWindow[0] && value <= valueWindow[1];
  69621. }
  69622. }
  69623. };
  69624. function calculateDataExtent(axisProxy, axisDim, seriesModels) {
  69625. var dataExtent = [Infinity, -Infinity];
  69626. each$22(seriesModels, function (seriesModel) {
  69627. var seriesData = seriesModel.getData();
  69628. if (seriesData) {
  69629. each$22(seriesData.mapDimension(axisDim, true), function (dim) {
  69630. var seriesExtent = seriesData.getApproximateExtent(dim);
  69631. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  69632. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  69633. });
  69634. }
  69635. });
  69636. if (dataExtent[1] < dataExtent[0]) {
  69637. dataExtent = [NaN, NaN];
  69638. }
  69639. // It is important to get "consistent" extent when more then one axes is
  69640. // controlled by a `dataZoom`, otherwise those axes will not be synchronized
  69641. // when zooming. But it is difficult to know what is "consistent", considering
  69642. // axes have different type or even different meanings (For example, two
  69643. // time axes are used to compare data of the same date in different years).
  69644. // So basically dataZoom just obtains extent by series.data (in category axis
  69645. // extent can be obtained from axis.data).
  69646. // Nevertheless, user can set min/max/scale on axes to make extent of axes
  69647. // consistent.
  69648. fixExtentByAxis(axisProxy, dataExtent);
  69649. return dataExtent;
  69650. }
  69651. function fixExtentByAxis(axisProxy, dataExtent) {
  69652. var axisModel = axisProxy.getAxisModel();
  69653. var min = axisModel.getMin(true);
  69654. // For category axis, if min/max/scale are not set, extent is determined
  69655. // by axis.data by default.
  69656. var isCategoryAxis = axisModel.get('type') === 'category';
  69657. var axisDataLen = isCategoryAxis && axisModel.getCategories().length;
  69658. if (min != null && min !== 'dataMin' && typeof min !== 'function') {
  69659. dataExtent[0] = min;
  69660. }
  69661. else if (isCategoryAxis) {
  69662. dataExtent[0] = axisDataLen > 0 ? 0 : NaN;
  69663. }
  69664. var max = axisModel.getMax(true);
  69665. if (max != null && max !== 'dataMax' && typeof max !== 'function') {
  69666. dataExtent[1] = max;
  69667. }
  69668. else if (isCategoryAxis) {
  69669. dataExtent[1] = axisDataLen > 0 ? axisDataLen - 1 : NaN;
  69670. }
  69671. if (!axisModel.get('scale', true)) {
  69672. dataExtent[0] > 0 && (dataExtent[0] = 0);
  69673. dataExtent[1] < 0 && (dataExtent[1] = 0);
  69674. }
  69675. // For value axis, if min/max/scale are not set, we just use the extent obtained
  69676. // by series data, which may be a little different from the extent calculated by
  69677. // `axisHelper.getScaleExtent`. But the different just affects the experience a
  69678. // little when zooming. So it will not be fixed until some users require it strongly.
  69679. return dataExtent;
  69680. }
  69681. function setAxisModel(axisProxy, isRestore) {
  69682. var axisModel = axisProxy.getAxisModel();
  69683. var percentWindow = axisProxy._percentWindow;
  69684. var valueWindow = axisProxy._valueWindow;
  69685. if (!percentWindow) {
  69686. return;
  69687. }
  69688. // [0, 500]: arbitrary value, guess axis extent.
  69689. var precision = getPixelPrecision(valueWindow, [0, 500]);
  69690. precision = Math.min(precision, 20);
  69691. // isRestore or isFull
  69692. var useOrigin = isRestore || (percentWindow[0] === 0 && percentWindow[1] === 100);
  69693. axisModel.setRange(
  69694. useOrigin ? null : +valueWindow[0].toFixed(precision),
  69695. useOrigin ? null : +valueWindow[1].toFixed(precision)
  69696. );
  69697. }
  69698. function setMinMaxSpan(axisProxy) {
  69699. var minMaxSpan = axisProxy._minMaxSpan = {};
  69700. var dataZoomModel = axisProxy._dataZoomModel;
  69701. each$22(['min', 'max'], function (minMax) {
  69702. minMaxSpan[minMax + 'Span'] = dataZoomModel.get(minMax + 'Span');
  69703. // minValueSpan and maxValueSpan has higher priority than minSpan and maxSpan
  69704. var valueSpan = dataZoomModel.get(minMax + 'ValueSpan');
  69705. if (valueSpan != null) {
  69706. minMaxSpan[minMax + 'ValueSpan'] = valueSpan;
  69707. valueSpan = axisProxy.getAxisModel().axis.scale.parse(valueSpan);
  69708. if (valueSpan != null) {
  69709. var dataExtent = axisProxy._dataExtent;
  69710. minMaxSpan[minMax + 'Span'] = linearMap(
  69711. dataExtent[0] + valueSpan, dataExtent, [0, 100], true
  69712. );
  69713. }
  69714. }
  69715. });
  69716. }
  69717. /*
  69718. * Licensed to the Apache Software Foundation (ASF) under one
  69719. * or more contributor license agreements. See the NOTICE file
  69720. * distributed with this work for additional information
  69721. * regarding copyright ownership. The ASF licenses this file
  69722. * to you under the Apache License, Version 2.0 (the
  69723. * "License"); you may not use this file except in compliance
  69724. * with the License. You may obtain a copy of the License at
  69725. *
  69726. * http://www.apache.org/licenses/LICENSE-2.0
  69727. *
  69728. * Unless required by applicable law or agreed to in writing,
  69729. * software distributed under the License is distributed on an
  69730. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  69731. * KIND, either express or implied. See the License for the
  69732. * specific language governing permissions and limitations
  69733. * under the License.
  69734. */
  69735. var each$21 = each$1;
  69736. var eachAxisDim = eachAxisDim$1;
  69737. var DataZoomModel = extendComponentModel({
  69738. type: 'dataZoom',
  69739. dependencies: [
  69740. 'xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series'
  69741. ],
  69742. /**
  69743. * @protected
  69744. */
  69745. defaultOption: {
  69746. zlevel: 0,
  69747. z: 4, // Higher than normal component (z: 2).
  69748. orient: null, // Default auto by axisIndex. Possible value: 'horizontal', 'vertical'.
  69749. xAxisIndex: null, // Default the first horizontal category axis.
  69750. yAxisIndex: null, // Default the first vertical category axis.
  69751. filterMode: 'filter', // Possible values: 'filter' or 'empty' or 'weakFilter'.
  69752. // 'filter': data items which are out of window will be removed. This option is
  69753. // applicable when filtering outliers. For each data item, it will be
  69754. // filtered if one of the relevant dimensions is out of the window.
  69755. // 'weakFilter': data items which are out of window will be removed. This option
  69756. // is applicable when filtering outliers. For each data item, it will be
  69757. // filtered only if all of the relevant dimensions are out of the same
  69758. // side of the window.
  69759. // 'empty': data items which are out of window will be set to empty.
  69760. // This option is applicable when user should not neglect
  69761. // that there are some data items out of window.
  69762. // 'none': Do not filter.
  69763. // Taking line chart as an example, line will be broken in
  69764. // the filtered points when filterModel is set to 'empty', but
  69765. // be connected when set to 'filter'.
  69766. throttle: null, // Dispatch action by the fixed rate, avoid frequency.
  69767. // default 100. Do not throttle when use null/undefined.
  69768. // If animation === true and animationDurationUpdate > 0,
  69769. // default value is 100, otherwise 20.
  69770. start: 0, // Start percent. 0 ~ 100
  69771. end: 100, // End percent. 0 ~ 100
  69772. startValue: null, // Start value. If startValue specified, start is ignored.
  69773. endValue: null, // End value. If endValue specified, end is ignored.
  69774. minSpan: null, // 0 ~ 100
  69775. maxSpan: null, // 0 ~ 100
  69776. minValueSpan: null, // The range of dataZoom can not be smaller than that.
  69777. maxValueSpan: null, // The range of dataZoom can not be larger than that.
  69778. rangeMode: null // Array, can be 'value' or 'percent'.
  69779. },
  69780. /**
  69781. * @override
  69782. */
  69783. init: function (option, parentModel, ecModel) {
  69784. /**
  69785. * key like x_0, y_1
  69786. * @private
  69787. * @type {Object}
  69788. */
  69789. this._dataIntervalByAxis = {};
  69790. /**
  69791. * @private
  69792. */
  69793. this._dataInfo = {};
  69794. /**
  69795. * key like x_0, y_1
  69796. * @private
  69797. */
  69798. this._axisProxies = {};
  69799. /**
  69800. * @readOnly
  69801. */
  69802. this.textStyleModel;
  69803. /**
  69804. * @private
  69805. */
  69806. this._autoThrottle = true;
  69807. /**
  69808. * 'percent' or 'value'
  69809. * @private
  69810. */
  69811. this._rangePropMode = ['percent', 'percent'];
  69812. var rawOption = retrieveRaw(option);
  69813. this.mergeDefaultAndTheme(option, ecModel);
  69814. this.doInit(rawOption);
  69815. },
  69816. /**
  69817. * @override
  69818. */
  69819. mergeOption: function (newOption) {
  69820. var rawOption = retrieveRaw(newOption);
  69821. //FIX #2591
  69822. merge(this.option, newOption, true);
  69823. this.doInit(rawOption);
  69824. },
  69825. /**
  69826. * @protected
  69827. */
  69828. doInit: function (rawOption) {
  69829. var thisOption = this.option;
  69830. // Disable realtime view update if canvas is not supported.
  69831. if (!env$1.canvasSupported) {
  69832. thisOption.realtime = false;
  69833. }
  69834. this._setDefaultThrottle(rawOption);
  69835. updateRangeUse(this, rawOption);
  69836. each$21([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  69837. // start/end has higher priority over startValue/endValue if they
  69838. // both set, but we should make chart.setOption({endValue: 1000})
  69839. // effective, rather than chart.setOption({endValue: 1000, end: null}).
  69840. if (this._rangePropMode[index] === 'value') {
  69841. thisOption[names[0]] = null;
  69842. }
  69843. // Otherwise do nothing and use the merge result.
  69844. }, this);
  69845. this.textStyleModel = this.getModel('textStyle');
  69846. this._resetTarget();
  69847. this._giveAxisProxies();
  69848. },
  69849. /**
  69850. * @private
  69851. */
  69852. _giveAxisProxies: function () {
  69853. var axisProxies = this._axisProxies;
  69854. this.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel, ecModel) {
  69855. var axisModel = this.dependentModels[dimNames.axis][axisIndex];
  69856. // If exists, share axisProxy with other dataZoomModels.
  69857. var axisProxy = axisModel.__dzAxisProxy || (
  69858. // Use the first dataZoomModel as the main model of axisProxy.
  69859. axisModel.__dzAxisProxy = new AxisProxy(
  69860. dimNames.name, axisIndex, this, ecModel
  69861. )
  69862. );
  69863. // FIXME
  69864. // dispose __dzAxisProxy
  69865. axisProxies[dimNames.name + '_' + axisIndex] = axisProxy;
  69866. }, this);
  69867. },
  69868. /**
  69869. * @private
  69870. */
  69871. _resetTarget: function () {
  69872. var thisOption = this.option;
  69873. var autoMode = this._judgeAutoMode();
  69874. eachAxisDim(function (dimNames) {
  69875. var axisIndexName = dimNames.axisIndex;
  69876. thisOption[axisIndexName] = normalizeToArray(
  69877. thisOption[axisIndexName]
  69878. );
  69879. }, this);
  69880. if (autoMode === 'axisIndex') {
  69881. this._autoSetAxisIndex();
  69882. }
  69883. else if (autoMode === 'orient') {
  69884. this._autoSetOrient();
  69885. }
  69886. },
  69887. /**
  69888. * @private
  69889. */
  69890. _judgeAutoMode: function () {
  69891. // Auto set only works for setOption at the first time.
  69892. // The following is user's reponsibility. So using merged
  69893. // option is OK.
  69894. var thisOption = this.option;
  69895. var hasIndexSpecified = false;
  69896. eachAxisDim(function (dimNames) {
  69897. // When user set axisIndex as a empty array, we think that user specify axisIndex
  69898. // but do not want use auto mode. Because empty array may be encountered when
  69899. // some error occured.
  69900. if (thisOption[dimNames.axisIndex] != null) {
  69901. hasIndexSpecified = true;
  69902. }
  69903. }, this);
  69904. var orient = thisOption.orient;
  69905. if (orient == null && hasIndexSpecified) {
  69906. return 'orient';
  69907. }
  69908. else if (!hasIndexSpecified) {
  69909. if (orient == null) {
  69910. thisOption.orient = 'horizontal';
  69911. }
  69912. return 'axisIndex';
  69913. }
  69914. },
  69915. /**
  69916. * @private
  69917. */
  69918. _autoSetAxisIndex: function () {
  69919. var autoAxisIndex = true;
  69920. var orient = this.get('orient', true);
  69921. var thisOption = this.option;
  69922. var dependentModels = this.dependentModels;
  69923. if (autoAxisIndex) {
  69924. // Find axis that parallel to dataZoom as default.
  69925. var dimName = orient === 'vertical' ? 'y' : 'x';
  69926. if (dependentModels[dimName + 'Axis'].length) {
  69927. thisOption[dimName + 'AxisIndex'] = [0];
  69928. autoAxisIndex = false;
  69929. }
  69930. else {
  69931. each$21(dependentModels.singleAxis, function (singleAxisModel) {
  69932. if (autoAxisIndex && singleAxisModel.get('orient', true) === orient) {
  69933. thisOption.singleAxisIndex = [singleAxisModel.componentIndex];
  69934. autoAxisIndex = false;
  69935. }
  69936. });
  69937. }
  69938. }
  69939. if (autoAxisIndex) {
  69940. // Find the first category axis as default. (consider polar)
  69941. eachAxisDim(function (dimNames) {
  69942. if (!autoAxisIndex) {
  69943. return;
  69944. }
  69945. var axisIndices = [];
  69946. var axisModels = this.dependentModels[dimNames.axis];
  69947. if (axisModels.length && !axisIndices.length) {
  69948. for (var i = 0, len = axisModels.length; i < len; i++) {
  69949. if (axisModels[i].get('type') === 'category') {
  69950. axisIndices.push(i);
  69951. }
  69952. }
  69953. }
  69954. thisOption[dimNames.axisIndex] = axisIndices;
  69955. if (axisIndices.length) {
  69956. autoAxisIndex = false;
  69957. }
  69958. }, this);
  69959. }
  69960. if (autoAxisIndex) {
  69961. // FIXME
  69962. // 这里是兼容ec2的写法(没指定xAxisIndex和yAxisIndex时把scatter和双数值轴折柱纳入dataZoom控制),
  69963. // 但是实际是否需要Grid.js#getScaleByOption来判断(考虑time,log等axis type)?
  69964. // If both dataZoom.xAxisIndex and dataZoom.yAxisIndex is not specified,
  69965. // dataZoom component auto adopts series that reference to
  69966. // both xAxis and yAxis which type is 'value'.
  69967. this.ecModel.eachSeries(function (seriesModel) {
  69968. if (this._isSeriesHasAllAxesTypeOf(seriesModel, 'value')) {
  69969. eachAxisDim(function (dimNames) {
  69970. var axisIndices = thisOption[dimNames.axisIndex];
  69971. var axisIndex = seriesModel.get(dimNames.axisIndex);
  69972. var axisId = seriesModel.get(dimNames.axisId);
  69973. var axisModel = seriesModel.ecModel.queryComponents({
  69974. mainType: dimNames.axis,
  69975. index: axisIndex,
  69976. id: axisId
  69977. })[0];
  69978. if (__DEV__) {
  69979. if (!axisModel) {
  69980. throw new Error(
  69981. dimNames.axis + ' "' + retrieve(
  69982. axisIndex,
  69983. axisId,
  69984. 0
  69985. ) + '" not found'
  69986. );
  69987. }
  69988. }
  69989. axisIndex = axisModel.componentIndex;
  69990. if (indexOf(axisIndices, axisIndex) < 0) {
  69991. axisIndices.push(axisIndex);
  69992. }
  69993. });
  69994. }
  69995. }, this);
  69996. }
  69997. },
  69998. /**
  69999. * @private
  70000. */
  70001. _autoSetOrient: function () {
  70002. var dim;
  70003. // Find the first axis
  70004. this.eachTargetAxis(function (dimNames) {
  70005. !dim && (dim = dimNames.name);
  70006. }, this);
  70007. this.option.orient = dim === 'y' ? 'vertical' : 'horizontal';
  70008. },
  70009. /**
  70010. * @private
  70011. */
  70012. _isSeriesHasAllAxesTypeOf: function (seriesModel, axisType) {
  70013. // FIXME
  70014. // 需要series的xAxisIndex和yAxisIndex都首先自动设置上。
  70015. // 例如series.type === scatter时。
  70016. var is = true;
  70017. eachAxisDim(function (dimNames) {
  70018. var seriesAxisIndex = seriesModel.get(dimNames.axisIndex);
  70019. var axisModel = this.dependentModels[dimNames.axis][seriesAxisIndex];
  70020. if (!axisModel || axisModel.get('type') !== axisType) {
  70021. is = false;
  70022. }
  70023. }, this);
  70024. return is;
  70025. },
  70026. /**
  70027. * @private
  70028. */
  70029. _setDefaultThrottle: function (rawOption) {
  70030. // When first time user set throttle, auto throttle ends.
  70031. if (rawOption.hasOwnProperty('throttle')) {
  70032. this._autoThrottle = false;
  70033. }
  70034. if (this._autoThrottle) {
  70035. var globalOption = this.ecModel.option;
  70036. this.option.throttle
  70037. = (globalOption.animation && globalOption.animationDurationUpdate > 0)
  70038. ? 100 : 20;
  70039. }
  70040. },
  70041. /**
  70042. * @public
  70043. */
  70044. getFirstTargetAxisModel: function () {
  70045. var firstAxisModel;
  70046. eachAxisDim(function (dimNames) {
  70047. if (firstAxisModel == null) {
  70048. var indices = this.get(dimNames.axisIndex);
  70049. if (indices.length) {
  70050. firstAxisModel = this.dependentModels[dimNames.axis][indices[0]];
  70051. }
  70052. }
  70053. }, this);
  70054. return firstAxisModel;
  70055. },
  70056. /**
  70057. * @public
  70058. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  70059. */
  70060. eachTargetAxis: function (callback, context) {
  70061. var ecModel = this.ecModel;
  70062. eachAxisDim(function (dimNames) {
  70063. each$21(
  70064. this.get(dimNames.axisIndex),
  70065. function (axisIndex) {
  70066. callback.call(context, dimNames, axisIndex, this, ecModel);
  70067. },
  70068. this
  70069. );
  70070. }, this);
  70071. },
  70072. /**
  70073. * @param {string} dimName
  70074. * @param {number} axisIndex
  70075. * @return {module:echarts/component/dataZoom/AxisProxy} If not found, return null/undefined.
  70076. */
  70077. getAxisProxy: function (dimName, axisIndex) {
  70078. return this._axisProxies[dimName + '_' + axisIndex];
  70079. },
  70080. /**
  70081. * @param {string} dimName
  70082. * @param {number} axisIndex
  70083. * @return {module:echarts/model/Model} If not found, return null/undefined.
  70084. */
  70085. getAxisModel: function (dimName, axisIndex) {
  70086. var axisProxy = this.getAxisProxy(dimName, axisIndex);
  70087. return axisProxy && axisProxy.getAxisModel();
  70088. },
  70089. /**
  70090. * If not specified, set to undefined.
  70091. *
  70092. * @public
  70093. * @param {Object} opt
  70094. * @param {number} [opt.start]
  70095. * @param {number} [opt.end]
  70096. * @param {number} [opt.startValue]
  70097. * @param {number} [opt.endValue]
  70098. * @param {boolean} [ignoreUpdateRangeUsg=false]
  70099. */
  70100. setRawRange: function (opt, ignoreUpdateRangeUsg) {
  70101. var option = this.option;
  70102. each$21([['start', 'startValue'], ['end', 'endValue']], function (names) {
  70103. // If only one of 'start' and 'startValue' is not null/undefined, the other
  70104. // should be cleared, which enable clear the option.
  70105. // If both of them are not set, keep option with the original value, which
  70106. // enable use only set start but not set end when calling `dispatchAction`.
  70107. // The same as 'end' and 'endValue'.
  70108. if (opt[names[0]] != null || opt[names[1]] != null) {
  70109. option[names[0]] = opt[names[0]];
  70110. option[names[1]] = opt[names[1]];
  70111. }
  70112. }, this);
  70113. !ignoreUpdateRangeUsg && updateRangeUse(this, opt);
  70114. },
  70115. /**
  70116. * @public
  70117. * @return {Array.<number>} [startPercent, endPercent]
  70118. */
  70119. getPercentRange: function () {
  70120. var axisProxy = this.findRepresentativeAxisProxy();
  70121. if (axisProxy) {
  70122. return axisProxy.getDataPercentWindow();
  70123. }
  70124. },
  70125. /**
  70126. * @public
  70127. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  70128. *
  70129. * @param {string} [axisDimName]
  70130. * @param {number} [axisIndex]
  70131. * @return {Array.<number>} [startValue, endValue] value can only be '-' or finite number.
  70132. */
  70133. getValueRange: function (axisDimName, axisIndex) {
  70134. if (axisDimName == null && axisIndex == null) {
  70135. var axisProxy = this.findRepresentativeAxisProxy();
  70136. if (axisProxy) {
  70137. return axisProxy.getDataValueWindow();
  70138. }
  70139. }
  70140. else {
  70141. return this.getAxisProxy(axisDimName, axisIndex).getDataValueWindow();
  70142. }
  70143. },
  70144. /**
  70145. * @public
  70146. * @param {module:echarts/model/Model} [axisModel] If axisModel given, find axisProxy
  70147. * corresponding to the axisModel
  70148. * @return {module:echarts/component/dataZoom/AxisProxy}
  70149. */
  70150. findRepresentativeAxisProxy: function (axisModel) {
  70151. if (axisModel) {
  70152. return axisModel.__dzAxisProxy;
  70153. }
  70154. // Find the first hosted axisProxy
  70155. var axisProxies = this._axisProxies;
  70156. for (var key in axisProxies) {
  70157. if (axisProxies.hasOwnProperty(key) && axisProxies[key].hostedBy(this)) {
  70158. return axisProxies[key];
  70159. }
  70160. }
  70161. // If no hosted axis find not hosted axisProxy.
  70162. // Consider this case: dataZoomModel1 and dataZoomModel2 control the same axis,
  70163. // and the option.start or option.end settings are different. The percentRange
  70164. // should follow axisProxy.
  70165. // (We encounter this problem in toolbox data zoom.)
  70166. for (var key in axisProxies) {
  70167. if (axisProxies.hasOwnProperty(key) && !axisProxies[key].hostedBy(this)) {
  70168. return axisProxies[key];
  70169. }
  70170. }
  70171. },
  70172. /**
  70173. * @return {Array.<string>}
  70174. */
  70175. getRangePropMode: function () {
  70176. return this._rangePropMode.slice();
  70177. }
  70178. });
  70179. function retrieveRaw(option) {
  70180. var ret = {};
  70181. each$21(
  70182. ['start', 'end', 'startValue', 'endValue', 'throttle'],
  70183. function (name) {
  70184. option.hasOwnProperty(name) && (ret[name] = option[name]);
  70185. }
  70186. );
  70187. return ret;
  70188. }
  70189. function updateRangeUse(dataZoomModel, rawOption) {
  70190. var rangePropMode = dataZoomModel._rangePropMode;
  70191. var rangeModeInOption = dataZoomModel.get('rangeMode');
  70192. each$21([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  70193. var percentSpecified = rawOption[names[0]] != null;
  70194. var valueSpecified = rawOption[names[1]] != null;
  70195. if (percentSpecified && !valueSpecified) {
  70196. rangePropMode[index] = 'percent';
  70197. }
  70198. else if (!percentSpecified && valueSpecified) {
  70199. rangePropMode[index] = 'value';
  70200. }
  70201. else if (rangeModeInOption) {
  70202. rangePropMode[index] = rangeModeInOption[index];
  70203. }
  70204. else if (percentSpecified) { // percentSpecified && valueSpecified
  70205. rangePropMode[index] = 'percent';
  70206. }
  70207. // else remain its original setting.
  70208. });
  70209. }
  70210. /*
  70211. * Licensed to the Apache Software Foundation (ASF) under one
  70212. * or more contributor license agreements. See the NOTICE file
  70213. * distributed with this work for additional information
  70214. * regarding copyright ownership. The ASF licenses this file
  70215. * to you under the Apache License, Version 2.0 (the
  70216. * "License"); you may not use this file except in compliance
  70217. * with the License. You may obtain a copy of the License at
  70218. *
  70219. * http://www.apache.org/licenses/LICENSE-2.0
  70220. *
  70221. * Unless required by applicable law or agreed to in writing,
  70222. * software distributed under the License is distributed on an
  70223. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70224. * KIND, either express or implied. See the License for the
  70225. * specific language governing permissions and limitations
  70226. * under the License.
  70227. */
  70228. var DataZoomView = Component.extend({
  70229. type: 'dataZoom',
  70230. render: function (dataZoomModel, ecModel, api, payload) {
  70231. this.dataZoomModel = dataZoomModel;
  70232. this.ecModel = ecModel;
  70233. this.api = api;
  70234. },
  70235. /**
  70236. * Find the first target coordinate system.
  70237. *
  70238. * @protected
  70239. * @return {Object} {
  70240. * grid: [
  70241. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  70242. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  70243. * ...
  70244. * ], // cartesians must not be null/undefined.
  70245. * polar: [
  70246. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  70247. * ...
  70248. * ], // polars must not be null/undefined.
  70249. * singleAxis: [
  70250. * {model: coord0, axisModels: [], coordIndex: 0}
  70251. * ]
  70252. */
  70253. getTargetCoordInfo: function () {
  70254. var dataZoomModel = this.dataZoomModel;
  70255. var ecModel = this.ecModel;
  70256. var coordSysLists = {};
  70257. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  70258. var axisModel = ecModel.getComponent(dimNames.axis, axisIndex);
  70259. if (axisModel) {
  70260. var coordModel = axisModel.getCoordSysModel();
  70261. coordModel && save(
  70262. coordModel,
  70263. axisModel,
  70264. coordSysLists[coordModel.mainType] || (coordSysLists[coordModel.mainType] = []),
  70265. coordModel.componentIndex
  70266. );
  70267. }
  70268. }, this);
  70269. function save(coordModel, axisModel, store, coordIndex) {
  70270. var item;
  70271. for (var i = 0; i < store.length; i++) {
  70272. if (store[i].model === coordModel) {
  70273. item = store[i];
  70274. break;
  70275. }
  70276. }
  70277. if (!item) {
  70278. store.push(item = {
  70279. model: coordModel, axisModels: [], coordIndex: coordIndex
  70280. });
  70281. }
  70282. item.axisModels.push(axisModel);
  70283. }
  70284. return coordSysLists;
  70285. }
  70286. });
  70287. /*
  70288. * Licensed to the Apache Software Foundation (ASF) under one
  70289. * or more contributor license agreements. See the NOTICE file
  70290. * distributed with this work for additional information
  70291. * regarding copyright ownership. The ASF licenses this file
  70292. * to you under the Apache License, Version 2.0 (the
  70293. * "License"); you may not use this file except in compliance
  70294. * with the License. You may obtain a copy of the License at
  70295. *
  70296. * http://www.apache.org/licenses/LICENSE-2.0
  70297. *
  70298. * Unless required by applicable law or agreed to in writing,
  70299. * software distributed under the License is distributed on an
  70300. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70301. * KIND, either express or implied. See the License for the
  70302. * specific language governing permissions and limitations
  70303. * under the License.
  70304. */
  70305. var SliderZoomModel = DataZoomModel.extend({
  70306. type: 'dataZoom.slider',
  70307. layoutMode: 'box',
  70308. /**
  70309. * @protected
  70310. */
  70311. defaultOption: {
  70312. show: true,
  70313. // ph => placeholder. Using placehoder here because
  70314. // deault value can only be drived in view stage.
  70315. right: 'ph', // Default align to grid rect.
  70316. top: 'ph', // Default align to grid rect.
  70317. width: 'ph', // Default align to grid rect.
  70318. height: 'ph', // Default align to grid rect.
  70319. left: null, // Default align to grid rect.
  70320. bottom: null, // Default align to grid rect.
  70321. backgroundColor: 'rgba(47,69,84,0)', // Background of slider zoom component.
  70322. // dataBackgroundColor: '#ddd', // Background coor of data shadow and border of box,
  70323. // highest priority, remain for compatibility of
  70324. // previous version, but not recommended any more.
  70325. dataBackground: {
  70326. lineStyle: {
  70327. color: '#2f4554',
  70328. width: 0.5,
  70329. opacity: 0.3
  70330. },
  70331. areaStyle: {
  70332. color: 'rgba(47,69,84,0.3)',
  70333. opacity: 0.3
  70334. }
  70335. },
  70336. borderColor: '#ddd', // border color of the box. For compatibility,
  70337. // if dataBackgroundColor is set, borderColor
  70338. // is ignored.
  70339. fillerColor: 'rgba(167,183,204,0.4)', // Color of selected area.
  70340. // handleColor: 'rgba(89,170,216,0.95)', // Color of handle.
  70341. // 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',
  70342. /* eslint-disable */
  70343. 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',
  70344. /* eslint-enable */
  70345. // Percent of the slider height
  70346. handleSize: '100%',
  70347. handleStyle: {
  70348. color: '#a7b7cc'
  70349. },
  70350. labelPrecision: null,
  70351. labelFormatter: null,
  70352. showDetail: true,
  70353. showDataShadow: 'auto', // Default auto decision.
  70354. realtime: true,
  70355. zoomLock: false, // Whether disable zoom.
  70356. textStyle: {
  70357. color: '#333'
  70358. }
  70359. }
  70360. });
  70361. /*
  70362. * Licensed to the Apache Software Foundation (ASF) under one
  70363. * or more contributor license agreements. See the NOTICE file
  70364. * distributed with this work for additional information
  70365. * regarding copyright ownership. The ASF licenses this file
  70366. * to you under the Apache License, Version 2.0 (the
  70367. * "License"); you may not use this file except in compliance
  70368. * with the License. You may obtain a copy of the License at
  70369. *
  70370. * http://www.apache.org/licenses/LICENSE-2.0
  70371. *
  70372. * Unless required by applicable law or agreed to in writing,
  70373. * software distributed under the License is distributed on an
  70374. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70375. * KIND, either express or implied. See the License for the
  70376. * specific language governing permissions and limitations
  70377. * under the License.
  70378. */
  70379. var Rect$2 = Rect;
  70380. var linearMap$1 = linearMap;
  70381. var asc$2 = asc;
  70382. var bind$4 = bind;
  70383. var each$23 = each$1;
  70384. // Constants
  70385. var DEFAULT_LOCATION_EDGE_GAP = 7;
  70386. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  70387. var DEFAULT_FILLER_SIZE = 30;
  70388. var HORIZONTAL = 'horizontal';
  70389. var VERTICAL = 'vertical';
  70390. var LABEL_GAP = 5;
  70391. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  70392. var SliderZoomView = DataZoomView.extend({
  70393. type: 'dataZoom.slider',
  70394. init: function (ecModel, api) {
  70395. /**
  70396. * @private
  70397. * @type {Object}
  70398. */
  70399. this._displayables = {};
  70400. /**
  70401. * @private
  70402. * @type {string}
  70403. */
  70404. this._orient;
  70405. /**
  70406. * [0, 100]
  70407. * @private
  70408. */
  70409. this._range;
  70410. /**
  70411. * [coord of the first handle, coord of the second handle]
  70412. * @private
  70413. */
  70414. this._handleEnds;
  70415. /**
  70416. * [length, thick]
  70417. * @private
  70418. * @type {Array.<number>}
  70419. */
  70420. this._size;
  70421. /**
  70422. * @private
  70423. * @type {number}
  70424. */
  70425. this._handleWidth;
  70426. /**
  70427. * @private
  70428. * @type {number}
  70429. */
  70430. this._handleHeight;
  70431. /**
  70432. * @private
  70433. */
  70434. this._location;
  70435. /**
  70436. * @private
  70437. */
  70438. this._dragging;
  70439. /**
  70440. * @private
  70441. */
  70442. this._dataShadowInfo;
  70443. this.api = api;
  70444. },
  70445. /**
  70446. * @override
  70447. */
  70448. render: function (dataZoomModel, ecModel, api, payload) {
  70449. SliderZoomView.superApply(this, 'render', arguments);
  70450. createOrUpdate(
  70451. this,
  70452. '_dispatchZoomAction',
  70453. this.dataZoomModel.get('throttle'),
  70454. 'fixRate'
  70455. );
  70456. this._orient = dataZoomModel.get('orient');
  70457. if (this.dataZoomModel.get('show') === false) {
  70458. this.group.removeAll();
  70459. return;
  70460. }
  70461. // Notice: this._resetInterval() should not be executed when payload.type
  70462. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  70463. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  70464. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  70465. this._buildView();
  70466. }
  70467. this._updateView();
  70468. },
  70469. /**
  70470. * @override
  70471. */
  70472. remove: function () {
  70473. SliderZoomView.superApply(this, 'remove', arguments);
  70474. clear(this, '_dispatchZoomAction');
  70475. },
  70476. /**
  70477. * @override
  70478. */
  70479. dispose: function () {
  70480. SliderZoomView.superApply(this, 'dispose', arguments);
  70481. clear(this, '_dispatchZoomAction');
  70482. },
  70483. _buildView: function () {
  70484. var thisGroup = this.group;
  70485. thisGroup.removeAll();
  70486. this._resetLocation();
  70487. this._resetInterval();
  70488. var barGroup = this._displayables.barGroup = new Group();
  70489. this._renderBackground();
  70490. this._renderHandle();
  70491. this._renderDataShadow();
  70492. thisGroup.add(barGroup);
  70493. this._positionGroup();
  70494. },
  70495. /**
  70496. * @private
  70497. */
  70498. _resetLocation: function () {
  70499. var dataZoomModel = this.dataZoomModel;
  70500. var api = this.api;
  70501. // If some of x/y/width/height are not specified,
  70502. // auto-adapt according to target grid.
  70503. var coordRect = this._findCoordRect();
  70504. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  70505. // Default align by coordinate system rect.
  70506. var positionInfo = this._orient === HORIZONTAL
  70507. ? {
  70508. // Why using 'right', because right should be used in vertical,
  70509. // and it is better to be consistent for dealing with position param merge.
  70510. right: ecSize.width - coordRect.x - coordRect.width,
  70511. top: (ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP),
  70512. width: coordRect.width,
  70513. height: DEFAULT_FILLER_SIZE
  70514. }
  70515. : { // vertical
  70516. right: DEFAULT_LOCATION_EDGE_GAP,
  70517. top: coordRect.y,
  70518. width: DEFAULT_FILLER_SIZE,
  70519. height: coordRect.height
  70520. };
  70521. // Do not write back to option and replace value 'ph', because
  70522. // the 'ph' value should be recalculated when resize.
  70523. var layoutParams = getLayoutParams(dataZoomModel.option);
  70524. // Replace the placeholder value.
  70525. each$1(['right', 'top', 'width', 'height'], function (name) {
  70526. if (layoutParams[name] === 'ph') {
  70527. layoutParams[name] = positionInfo[name];
  70528. }
  70529. });
  70530. var layoutRect = getLayoutRect(
  70531. layoutParams,
  70532. ecSize,
  70533. dataZoomModel.padding
  70534. );
  70535. this._location = {x: layoutRect.x, y: layoutRect.y};
  70536. this._size = [layoutRect.width, layoutRect.height];
  70537. this._orient === VERTICAL && this._size.reverse();
  70538. },
  70539. /**
  70540. * @private
  70541. */
  70542. _positionGroup: function () {
  70543. var thisGroup = this.group;
  70544. var location = this._location;
  70545. var orient = this._orient;
  70546. // Just use the first axis to determine mapping.
  70547. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  70548. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  70549. var barGroup = this._displayables.barGroup;
  70550. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse;
  70551. // Transform barGroup.
  70552. barGroup.attr(
  70553. (orient === HORIZONTAL && !inverse)
  70554. ? {scale: otherAxisInverse ? [1, 1] : [1, -1]}
  70555. : (orient === HORIZONTAL && inverse)
  70556. ? {scale: otherAxisInverse ? [-1, 1] : [-1, -1]}
  70557. : (orient === VERTICAL && !inverse)
  70558. ? {scale: otherAxisInverse ? [1, -1] : [1, 1], rotation: Math.PI / 2}
  70559. // Dont use Math.PI, considering shadow direction.
  70560. : {scale: otherAxisInverse ? [-1, -1] : [-1, 1], rotation: Math.PI / 2}
  70561. );
  70562. // Position barGroup
  70563. var rect = thisGroup.getBoundingRect([barGroup]);
  70564. thisGroup.attr('position', [location.x - rect.x, location.y - rect.y]);
  70565. },
  70566. /**
  70567. * @private
  70568. */
  70569. _getViewExtent: function () {
  70570. return [0, this._size[0]];
  70571. },
  70572. _renderBackground: function () {
  70573. var dataZoomModel = this.dataZoomModel;
  70574. var size = this._size;
  70575. var barGroup = this._displayables.barGroup;
  70576. barGroup.add(new Rect$2({
  70577. silent: true,
  70578. shape: {
  70579. x: 0, y: 0, width: size[0], height: size[1]
  70580. },
  70581. style: {
  70582. fill: dataZoomModel.get('backgroundColor')
  70583. },
  70584. z2: -40
  70585. }));
  70586. // Click panel, over shadow, below handles.
  70587. barGroup.add(new Rect$2({
  70588. shape: {
  70589. x: 0, y: 0, width: size[0], height: size[1]
  70590. },
  70591. style: {
  70592. fill: 'transparent'
  70593. },
  70594. z2: 0,
  70595. onclick: bind(this._onClickPanelClick, this)
  70596. }));
  70597. },
  70598. _renderDataShadow: function () {
  70599. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  70600. if (!info) {
  70601. return;
  70602. }
  70603. var size = this._size;
  70604. var seriesModel = info.series;
  70605. var data = seriesModel.getRawData();
  70606. var otherDim = seriesModel.getShadowDim
  70607. ? seriesModel.getShadowDim() // @see candlestick
  70608. : info.otherDim;
  70609. if (otherDim == null) {
  70610. return;
  70611. }
  70612. var otherDataExtent = data.getDataExtent(otherDim);
  70613. // Nice extent.
  70614. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  70615. otherDataExtent = [
  70616. otherDataExtent[0] - otherOffset,
  70617. otherDataExtent[1] + otherOffset
  70618. ];
  70619. var otherShadowExtent = [0, size[1]];
  70620. var thisShadowExtent = [0, size[0]];
  70621. var areaPoints = [[size[0], 0], [0, 0]];
  70622. var linePoints = [];
  70623. var step = thisShadowExtent[1] / (data.count() - 1);
  70624. var thisCoord = 0;
  70625. // Optimize for large data shadow
  70626. var stride = Math.round(data.count() / size[0]);
  70627. var lastIsEmpty;
  70628. data.each([otherDim], function (value, index) {
  70629. if (stride > 0 && (index % stride)) {
  70630. thisCoord += step;
  70631. return;
  70632. }
  70633. // FIXME
  70634. // Should consider axis.min/axis.max when drawing dataShadow.
  70635. // FIXME
  70636. // 应该使用统一的空判断?还是在list里进行空判断?
  70637. var isEmpty = value == null || isNaN(value) || value === '';
  70638. // See #4235.
  70639. var otherCoord = isEmpty
  70640. ? 0 : linearMap$1(value, otherDataExtent, otherShadowExtent, true);
  70641. // Attempt to draw data shadow precisely when there are empty value.
  70642. if (isEmpty && !lastIsEmpty && index) {
  70643. areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
  70644. linePoints.push([linePoints[linePoints.length - 1][0], 0]);
  70645. }
  70646. else if (!isEmpty && lastIsEmpty) {
  70647. areaPoints.push([thisCoord, 0]);
  70648. linePoints.push([thisCoord, 0]);
  70649. }
  70650. areaPoints.push([thisCoord, otherCoord]);
  70651. linePoints.push([thisCoord, otherCoord]);
  70652. thisCoord += step;
  70653. lastIsEmpty = isEmpty;
  70654. });
  70655. var dataZoomModel = this.dataZoomModel;
  70656. // var dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  70657. this._displayables.barGroup.add(new Polygon({
  70658. shape: {points: areaPoints},
  70659. style: defaults(
  70660. {fill: dataZoomModel.get('dataBackgroundColor')},
  70661. dataZoomModel.getModel('dataBackground.areaStyle').getAreaStyle()
  70662. ),
  70663. silent: true,
  70664. z2: -20
  70665. }));
  70666. this._displayables.barGroup.add(new Polyline({
  70667. shape: {points: linePoints},
  70668. style: dataZoomModel.getModel('dataBackground.lineStyle').getLineStyle(),
  70669. silent: true,
  70670. z2: -19
  70671. }));
  70672. },
  70673. _prepareDataShadowInfo: function () {
  70674. var dataZoomModel = this.dataZoomModel;
  70675. var showDataShadow = dataZoomModel.get('showDataShadow');
  70676. if (showDataShadow === false) {
  70677. return;
  70678. }
  70679. // Find a representative series.
  70680. var result;
  70681. var ecModel = this.ecModel;
  70682. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  70683. var seriesModels = dataZoomModel
  70684. .getAxisProxy(dimNames.name, axisIndex)
  70685. .getTargetSeriesModels();
  70686. each$1(seriesModels, function (seriesModel) {
  70687. if (result) {
  70688. return;
  70689. }
  70690. if (showDataShadow !== true && indexOf(
  70691. SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')
  70692. ) < 0
  70693. ) {
  70694. return;
  70695. }
  70696. var thisAxis = ecModel.getComponent(dimNames.axis, axisIndex).axis;
  70697. var otherDim = getOtherDim(dimNames.name);
  70698. var otherAxisInverse;
  70699. var coordSys = seriesModel.coordinateSystem;
  70700. if (otherDim != null && coordSys.getOtherAxis) {
  70701. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  70702. }
  70703. otherDim = seriesModel.getData().mapDimension(otherDim);
  70704. result = {
  70705. thisAxis: thisAxis,
  70706. series: seriesModel,
  70707. thisDim: dimNames.name,
  70708. otherDim: otherDim,
  70709. otherAxisInverse: otherAxisInverse
  70710. };
  70711. }, this);
  70712. }, this);
  70713. return result;
  70714. },
  70715. _renderHandle: function () {
  70716. var displaybles = this._displayables;
  70717. var handles = displaybles.handles = [];
  70718. var handleLabels = displaybles.handleLabels = [];
  70719. var barGroup = this._displayables.barGroup;
  70720. var size = this._size;
  70721. var dataZoomModel = this.dataZoomModel;
  70722. barGroup.add(displaybles.filler = new Rect$2({
  70723. draggable: true,
  70724. cursor: getCursor(this._orient),
  70725. drift: bind$4(this._onDragMove, this, 'all'),
  70726. onmousemove: function (e) {
  70727. // Fot mobile devicem, prevent screen slider on the button.
  70728. stop(e.event);
  70729. },
  70730. ondragstart: bind$4(this._showDataInfo, this, true),
  70731. ondragend: bind$4(this._onDragEnd, this),
  70732. onmouseover: bind$4(this._showDataInfo, this, true),
  70733. onmouseout: bind$4(this._showDataInfo, this, false),
  70734. style: {
  70735. fill: dataZoomModel.get('fillerColor'),
  70736. textPosition: 'inside'
  70737. }
  70738. }));
  70739. // Frame border.
  70740. barGroup.add(new Rect$2(subPixelOptimizeRect({
  70741. silent: true,
  70742. shape: {
  70743. x: 0,
  70744. y: 0,
  70745. width: size[0],
  70746. height: size[1]
  70747. },
  70748. style: {
  70749. stroke: dataZoomModel.get('dataBackgroundColor')
  70750. || dataZoomModel.get('borderColor'),
  70751. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  70752. fill: 'rgba(0,0,0,0)'
  70753. }
  70754. })));
  70755. each$23([0, 1], function (handleIndex) {
  70756. var path = createIcon(
  70757. dataZoomModel.get('handleIcon'),
  70758. {
  70759. cursor: getCursor(this._orient),
  70760. draggable: true,
  70761. drift: bind$4(this._onDragMove, this, handleIndex),
  70762. onmousemove: function (e) {
  70763. // Fot mobile devicem, prevent screen slider on the button.
  70764. stop(e.event);
  70765. },
  70766. ondragend: bind$4(this._onDragEnd, this),
  70767. onmouseover: bind$4(this._showDataInfo, this, true),
  70768. onmouseout: bind$4(this._showDataInfo, this, false)
  70769. },
  70770. {x: -1, y: 0, width: 2, height: 2}
  70771. );
  70772. var bRect = path.getBoundingRect();
  70773. this._handleHeight = parsePercent$1(dataZoomModel.get('handleSize'), this._size[1]);
  70774. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  70775. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  70776. var handleColor = dataZoomModel.get('handleColor');
  70777. // Compatitable with previous version
  70778. if (handleColor != null) {
  70779. path.style.fill = handleColor;
  70780. }
  70781. barGroup.add(handles[handleIndex] = path);
  70782. var textStyleModel = dataZoomModel.textStyleModel;
  70783. this.group.add(
  70784. handleLabels[handleIndex] = new Text({
  70785. silent: true,
  70786. invisible: true,
  70787. style: {
  70788. x: 0, y: 0, text: '',
  70789. textVerticalAlign: 'middle',
  70790. textAlign: 'center',
  70791. textFill: textStyleModel.getTextColor(),
  70792. textFont: textStyleModel.getFont()
  70793. },
  70794. z2: 10
  70795. }));
  70796. }, this);
  70797. },
  70798. /**
  70799. * @private
  70800. */
  70801. _resetInterval: function () {
  70802. var range = this._range = this.dataZoomModel.getPercentRange();
  70803. var viewExtent = this._getViewExtent();
  70804. this._handleEnds = [
  70805. linearMap$1(range[0], [0, 100], viewExtent, true),
  70806. linearMap$1(range[1], [0, 100], viewExtent, true)
  70807. ];
  70808. },
  70809. /**
  70810. * @private
  70811. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  70812. * @param {number} delta
  70813. * @return {boolean} changed
  70814. */
  70815. _updateInterval: function (handleIndex, delta) {
  70816. var dataZoomModel = this.dataZoomModel;
  70817. var handleEnds = this._handleEnds;
  70818. var viewExtend = this._getViewExtent();
  70819. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  70820. var percentExtent = [0, 100];
  70821. sliderMove(
  70822. delta,
  70823. handleEnds,
  70824. viewExtend,
  70825. dataZoomModel.get('zoomLock') ? 'all' : handleIndex,
  70826. minMaxSpan.minSpan != null
  70827. ? linearMap$1(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null,
  70828. minMaxSpan.maxSpan != null
  70829. ? linearMap$1(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null
  70830. );
  70831. var lastRange = this._range;
  70832. var range = this._range = asc$2([
  70833. linearMap$1(handleEnds[0], viewExtend, percentExtent, true),
  70834. linearMap$1(handleEnds[1], viewExtend, percentExtent, true)
  70835. ]);
  70836. return !lastRange || lastRange[0] !== range[0] || lastRange[1] !== range[1];
  70837. },
  70838. /**
  70839. * @private
  70840. */
  70841. _updateView: function (nonRealtime) {
  70842. var displaybles = this._displayables;
  70843. var handleEnds = this._handleEnds;
  70844. var handleInterval = asc$2(handleEnds.slice());
  70845. var size = this._size;
  70846. each$23([0, 1], function (handleIndex) {
  70847. // Handles
  70848. var handle = displaybles.handles[handleIndex];
  70849. var handleHeight = this._handleHeight;
  70850. handle.attr({
  70851. scale: [handleHeight / 2, handleHeight / 2],
  70852. position: [handleEnds[handleIndex], size[1] / 2 - handleHeight / 2]
  70853. });
  70854. }, this);
  70855. // Filler
  70856. displaybles.filler.setShape({
  70857. x: handleInterval[0],
  70858. y: 0,
  70859. width: handleInterval[1] - handleInterval[0],
  70860. height: size[1]
  70861. });
  70862. this._updateDataInfo(nonRealtime);
  70863. },
  70864. /**
  70865. * @private
  70866. */
  70867. _updateDataInfo: function (nonRealtime) {
  70868. var dataZoomModel = this.dataZoomModel;
  70869. var displaybles = this._displayables;
  70870. var handleLabels = displaybles.handleLabels;
  70871. var orient = this._orient;
  70872. var labelTexts = ['', ''];
  70873. // FIXME
  70874. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  70875. if (dataZoomModel.get('showDetail')) {
  70876. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  70877. if (axisProxy) {
  70878. var axis = axisProxy.getAxisModel().axis;
  70879. var range = this._range;
  70880. var dataInterval = nonRealtime
  70881. // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  70882. ? axisProxy.calculateDataWindow({
  70883. start: range[0], end: range[1]
  70884. }).valueWindow
  70885. : axisProxy.getDataValueWindow();
  70886. labelTexts = [
  70887. this._formatLabel(dataInterval[0], axis),
  70888. this._formatLabel(dataInterval[1], axis)
  70889. ];
  70890. }
  70891. }
  70892. var orderedHandleEnds = asc$2(this._handleEnds.slice());
  70893. setLabel.call(this, 0);
  70894. setLabel.call(this, 1);
  70895. function setLabel(handleIndex) {
  70896. // Label
  70897. // Text should not transform by barGroup.
  70898. // Ignore handlers transform
  70899. var barTransform = getTransform(
  70900. displaybles.handles[handleIndex].parent, this.group
  70901. );
  70902. var direction = transformDirection(
  70903. handleIndex === 0 ? 'right' : 'left', barTransform
  70904. );
  70905. var offset = this._handleWidth / 2 + LABEL_GAP;
  70906. var textPoint = applyTransform$1(
  70907. [
  70908. orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset),
  70909. this._size[1] / 2
  70910. ],
  70911. barTransform
  70912. );
  70913. handleLabels[handleIndex].setStyle({
  70914. x: textPoint[0],
  70915. y: textPoint[1],
  70916. textVerticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  70917. textAlign: orient === HORIZONTAL ? direction : 'center',
  70918. text: labelTexts[handleIndex]
  70919. });
  70920. }
  70921. },
  70922. /**
  70923. * @private
  70924. */
  70925. _formatLabel: function (value, axis) {
  70926. var dataZoomModel = this.dataZoomModel;
  70927. var labelFormatter = dataZoomModel.get('labelFormatter');
  70928. var labelPrecision = dataZoomModel.get('labelPrecision');
  70929. if (labelPrecision == null || labelPrecision === 'auto') {
  70930. labelPrecision = axis.getPixelPrecision();
  70931. }
  70932. var valueStr = (value == null || isNaN(value))
  70933. ? ''
  70934. // FIXME Glue code
  70935. : (axis.type === 'category' || axis.type === 'time')
  70936. ? axis.scale.getLabel(Math.round(value))
  70937. // param of toFixed should less then 20.
  70938. : value.toFixed(Math.min(labelPrecision, 20));
  70939. return isFunction$1(labelFormatter)
  70940. ? labelFormatter(value, valueStr)
  70941. : isString(labelFormatter)
  70942. ? labelFormatter.replace('{value}', valueStr)
  70943. : valueStr;
  70944. },
  70945. /**
  70946. * @private
  70947. * @param {boolean} showOrHide true: show, false: hide
  70948. */
  70949. _showDataInfo: function (showOrHide) {
  70950. // Always show when drgging.
  70951. showOrHide = this._dragging || showOrHide;
  70952. var handleLabels = this._displayables.handleLabels;
  70953. handleLabels[0].attr('invisible', !showOrHide);
  70954. handleLabels[1].attr('invisible', !showOrHide);
  70955. },
  70956. _onDragMove: function (handleIndex, dx, dy) {
  70957. this._dragging = true;
  70958. // Transform dx, dy to bar coordination.
  70959. var barTransform = this._displayables.barGroup.getLocalTransform();
  70960. var vertex = applyTransform$1([dx, dy], barTransform, true);
  70961. var changed = this._updateInterval(handleIndex, vertex[0]);
  70962. var realtime = this.dataZoomModel.get('realtime');
  70963. this._updateView(!realtime);
  70964. // Avoid dispatch dataZoom repeatly but range not changed,
  70965. // which cause bad visual effect when progressive enabled.
  70966. changed && realtime && this._dispatchZoomAction();
  70967. },
  70968. _onDragEnd: function () {
  70969. this._dragging = false;
  70970. this._showDataInfo(false);
  70971. // While in realtime mode and stream mode, dispatch action when
  70972. // drag end will cause the whole view rerender, which is unnecessary.
  70973. var realtime = this.dataZoomModel.get('realtime');
  70974. !realtime && this._dispatchZoomAction();
  70975. },
  70976. _onClickPanelClick: function (e) {
  70977. var size = this._size;
  70978. var localPoint = this._displayables.barGroup.transformCoordToLocal(e.offsetX, e.offsetY);
  70979. if (localPoint[0] < 0 || localPoint[0] > size[0]
  70980. || localPoint[1] < 0 || localPoint[1] > size[1]
  70981. ) {
  70982. return;
  70983. }
  70984. var handleEnds = this._handleEnds;
  70985. var center = (handleEnds[0] + handleEnds[1]) / 2;
  70986. var changed = this._updateInterval('all', localPoint[0] - center);
  70987. this._updateView();
  70988. changed && this._dispatchZoomAction();
  70989. },
  70990. /**
  70991. * This action will be throttled.
  70992. * @private
  70993. */
  70994. _dispatchZoomAction: function () {
  70995. var range = this._range;
  70996. this.api.dispatchAction({
  70997. type: 'dataZoom',
  70998. from: this.uid,
  70999. dataZoomId: this.dataZoomModel.id,
  71000. start: range[0],
  71001. end: range[1]
  71002. });
  71003. },
  71004. /**
  71005. * @private
  71006. */
  71007. _findCoordRect: function () {
  71008. // Find the grid coresponding to the first axis referred by dataZoom.
  71009. var rect;
  71010. each$23(this.getTargetCoordInfo(), function (coordInfoList) {
  71011. if (!rect && coordInfoList.length) {
  71012. var coordSys = coordInfoList[0].model.coordinateSystem;
  71013. rect = coordSys.getRect && coordSys.getRect();
  71014. }
  71015. });
  71016. if (!rect) {
  71017. var width = this.api.getWidth();
  71018. var height = this.api.getHeight();
  71019. rect = {
  71020. x: width * 0.2,
  71021. y: height * 0.2,
  71022. width: width * 0.6,
  71023. height: height * 0.6
  71024. };
  71025. }
  71026. return rect;
  71027. }
  71028. });
  71029. function getOtherDim(thisDim) {
  71030. // FIXME
  71031. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  71032. var map$$1 = {x: 'y', y: 'x', radius: 'angle', angle: 'radius'};
  71033. return map$$1[thisDim];
  71034. }
  71035. function getCursor(orient) {
  71036. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  71037. }
  71038. /*
  71039. * Licensed to the Apache Software Foundation (ASF) under one
  71040. * or more contributor license agreements. See the NOTICE file
  71041. * distributed with this work for additional information
  71042. * regarding copyright ownership. The ASF licenses this file
  71043. * to you under the Apache License, Version 2.0 (the
  71044. * "License"); you may not use this file except in compliance
  71045. * with the License. You may obtain a copy of the License at
  71046. *
  71047. * http://www.apache.org/licenses/LICENSE-2.0
  71048. *
  71049. * Unless required by applicable law or agreed to in writing,
  71050. * software distributed under the License is distributed on an
  71051. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71052. * KIND, either express or implied. See the License for the
  71053. * specific language governing permissions and limitations
  71054. * under the License.
  71055. */
  71056. DataZoomModel.extend({
  71057. type: 'dataZoom.inside',
  71058. /**
  71059. * @protected
  71060. */
  71061. defaultOption: {
  71062. disabled: false, // Whether disable this inside zoom.
  71063. zoomLock: false, // Whether disable zoom but only pan.
  71064. zoomOnMouseWheel: true, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  71065. moveOnMouseMove: true, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  71066. moveOnMouseWheel: false, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  71067. preventDefaultMouseMove: true
  71068. }
  71069. });
  71070. /*
  71071. * Licensed to the Apache Software Foundation (ASF) under one
  71072. * or more contributor license agreements. See the NOTICE file
  71073. * distributed with this work for additional information
  71074. * regarding copyright ownership. The ASF licenses this file
  71075. * to you under the Apache License, Version 2.0 (the
  71076. * "License"); you may not use this file except in compliance
  71077. * with the License. You may obtain a copy of the License at
  71078. *
  71079. * http://www.apache.org/licenses/LICENSE-2.0
  71080. *
  71081. * Unless required by applicable law or agreed to in writing,
  71082. * software distributed under the License is distributed on an
  71083. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71084. * KIND, either express or implied. See the License for the
  71085. * specific language governing permissions and limitations
  71086. * under the License.
  71087. */
  71088. // Only create one roam controller for each coordinate system.
  71089. // one roam controller might be refered by two inside data zoom
  71090. // components (for example, one for x and one for y). When user
  71091. // pan or zoom, only dispatch one action for those data zoom
  71092. // components.
  71093. var ATTR$1 = '\0_ec_dataZoom_roams';
  71094. /**
  71095. * @public
  71096. * @param {module:echarts/ExtensionAPI} api
  71097. * @param {Object} dataZoomInfo
  71098. * @param {string} dataZoomInfo.coordId
  71099. * @param {Function} dataZoomInfo.containsPoint
  71100. * @param {Array.<string>} dataZoomInfo.allCoordIds
  71101. * @param {string} dataZoomInfo.dataZoomId
  71102. * @param {Object} dataZoomInfo.getRange
  71103. * @param {Function} dataZoomInfo.getRange.pan
  71104. * @param {Function} dataZoomInfo.getRange.zoom
  71105. * @param {Function} dataZoomInfo.getRange.scrollMove
  71106. * @param {boolean} dataZoomInfo.dataZoomModel
  71107. */
  71108. function register$2(api, dataZoomInfo) {
  71109. var store = giveStore(api);
  71110. var theDataZoomId = dataZoomInfo.dataZoomId;
  71111. var theCoordId = dataZoomInfo.coordId;
  71112. // Do clean when a dataZoom changes its target coordnate system.
  71113. // Avoid memory leak, dispose all not-used-registered.
  71114. each$1(store, function (record, coordId) {
  71115. var dataZoomInfos = record.dataZoomInfos;
  71116. if (dataZoomInfos[theDataZoomId]
  71117. && indexOf(dataZoomInfo.allCoordIds, theCoordId) < 0
  71118. ) {
  71119. delete dataZoomInfos[theDataZoomId];
  71120. record.count--;
  71121. }
  71122. });
  71123. cleanStore(store);
  71124. var record = store[theCoordId];
  71125. // Create if needed.
  71126. if (!record) {
  71127. record = store[theCoordId] = {
  71128. coordId: theCoordId,
  71129. dataZoomInfos: {},
  71130. count: 0
  71131. };
  71132. record.controller = createController(api, record);
  71133. record.dispatchAction = curry(dispatchAction$1, api);
  71134. }
  71135. // Update reference of dataZoom.
  71136. !(record.dataZoomInfos[theDataZoomId]) && record.count++;
  71137. record.dataZoomInfos[theDataZoomId] = dataZoomInfo;
  71138. var controllerParams = mergeControllerParams(record.dataZoomInfos);
  71139. record.controller.enable(controllerParams.controlType, controllerParams.opt);
  71140. // Consider resize, area should be always updated.
  71141. record.controller.setPointerChecker(dataZoomInfo.containsPoint);
  71142. // Update throttle.
  71143. createOrUpdate(
  71144. record,
  71145. 'dispatchAction',
  71146. dataZoomInfo.dataZoomModel.get('throttle', true),
  71147. 'fixRate'
  71148. );
  71149. }
  71150. /**
  71151. * @public
  71152. * @param {module:echarts/ExtensionAPI} api
  71153. * @param {string} dataZoomId
  71154. */
  71155. function unregister$1(api, dataZoomId) {
  71156. var store = giveStore(api);
  71157. each$1(store, function (record) {
  71158. record.controller.dispose();
  71159. var dataZoomInfos = record.dataZoomInfos;
  71160. if (dataZoomInfos[dataZoomId]) {
  71161. delete dataZoomInfos[dataZoomId];
  71162. record.count--;
  71163. }
  71164. });
  71165. cleanStore(store);
  71166. }
  71167. /**
  71168. * @public
  71169. */
  71170. function generateCoordId(coordModel) {
  71171. return coordModel.type + '\0_' + coordModel.id;
  71172. }
  71173. /**
  71174. * Key: coordId, value: {dataZoomInfos: [], count, controller}
  71175. * @type {Array.<Object>}
  71176. */
  71177. function giveStore(api) {
  71178. // Mount store on zrender instance, so that we do not
  71179. // need to worry about dispose.
  71180. var zr = api.getZr();
  71181. return zr[ATTR$1] || (zr[ATTR$1] = {});
  71182. }
  71183. function createController(api, newRecord) {
  71184. var controller = new RoamController(api.getZr());
  71185. each$1(['pan', 'zoom', 'scrollMove'], function (eventName) {
  71186. controller.on(eventName, function (event) {
  71187. var batch = [];
  71188. each$1(newRecord.dataZoomInfos, function (info) {
  71189. // Check whether the behaviors (zoomOnMouseWheel, moveOnMouseMove,
  71190. // moveOnMouseWheel, ...) enabled.
  71191. if (!event.isAvailableBehavior(info.dataZoomModel.option)) {
  71192. return;
  71193. }
  71194. var method = (info.getRange || {})[eventName];
  71195. var range = method && method(newRecord.controller, event);
  71196. !info.dataZoomModel.get('disabled', true) && range && batch.push({
  71197. dataZoomId: info.dataZoomId,
  71198. start: range[0],
  71199. end: range[1]
  71200. });
  71201. });
  71202. batch.length && newRecord.dispatchAction(batch);
  71203. });
  71204. });
  71205. return controller;
  71206. }
  71207. function cleanStore(store) {
  71208. each$1(store, function (record, coordId) {
  71209. if (!record.count) {
  71210. record.controller.dispose();
  71211. delete store[coordId];
  71212. }
  71213. });
  71214. }
  71215. /**
  71216. * This action will be throttled.
  71217. */
  71218. function dispatchAction$1(api, batch) {
  71219. api.dispatchAction({
  71220. type: 'dataZoom',
  71221. batch: batch
  71222. });
  71223. }
  71224. /**
  71225. * Merge roamController settings when multiple dataZooms share one roamController.
  71226. */
  71227. function mergeControllerParams(dataZoomInfos) {
  71228. var controlType;
  71229. // DO NOT use reserved word (true, false, undefined) as key literally. Even if encapsulated
  71230. // as string, it is probably revert to reserved word by compress tool. See #7411.
  71231. var prefix = 'type_';
  71232. var typePriority = {
  71233. 'type_true': 2,
  71234. 'type_move': 1,
  71235. 'type_false': 0,
  71236. 'type_undefined': -1
  71237. };
  71238. var preventDefaultMouseMove = true;
  71239. each$1(dataZoomInfos, function (dataZoomInfo) {
  71240. var dataZoomModel = dataZoomInfo.dataZoomModel;
  71241. var oneType = dataZoomModel.get('disabled', true)
  71242. ? false
  71243. : dataZoomModel.get('zoomLock', true)
  71244. ? 'move'
  71245. : true;
  71246. if (typePriority[prefix + oneType] > typePriority[prefix + controlType]) {
  71247. controlType = oneType;
  71248. }
  71249. // Prevent default move event by default. If one false, do not prevent. Otherwise
  71250. // users may be confused why it does not work when multiple insideZooms exist.
  71251. preventDefaultMouseMove &= dataZoomModel.get('preventDefaultMouseMove', true);
  71252. });
  71253. return {
  71254. controlType: controlType,
  71255. opt: {
  71256. // RoamController will enable all of these functionalities,
  71257. // and the final behavior is determined by its event listener
  71258. // provided by each inside zoom.
  71259. zoomOnMouseWheel: true,
  71260. moveOnMouseMove: true,
  71261. moveOnMouseWheel: true,
  71262. preventDefaultMouseMove: !!preventDefaultMouseMove
  71263. }
  71264. };
  71265. }
  71266. /*
  71267. * Licensed to the Apache Software Foundation (ASF) under one
  71268. * or more contributor license agreements. See the NOTICE file
  71269. * distributed with this work for additional information
  71270. * regarding copyright ownership. The ASF licenses this file
  71271. * to you under the Apache License, Version 2.0 (the
  71272. * "License"); you may not use this file except in compliance
  71273. * with the License. You may obtain a copy of the License at
  71274. *
  71275. * http://www.apache.org/licenses/LICENSE-2.0
  71276. *
  71277. * Unless required by applicable law or agreed to in writing,
  71278. * software distributed under the License is distributed on an
  71279. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71280. * KIND, either express or implied. See the License for the
  71281. * specific language governing permissions and limitations
  71282. * under the License.
  71283. */
  71284. var bind$5 = bind;
  71285. var InsideZoomView = DataZoomView.extend({
  71286. type: 'dataZoom.inside',
  71287. /**
  71288. * @override
  71289. */
  71290. init: function (ecModel, api) {
  71291. /**
  71292. * 'throttle' is used in this.dispatchAction, so we save range
  71293. * to avoid missing some 'pan' info.
  71294. * @private
  71295. * @type {Array.<number>}
  71296. */
  71297. this._range;
  71298. },
  71299. /**
  71300. * @override
  71301. */
  71302. render: function (dataZoomModel, ecModel, api, payload) {
  71303. InsideZoomView.superApply(this, 'render', arguments);
  71304. // Hance the `throttle` util ensures to preserve command order,
  71305. // here simply updating range all the time will not cause missing
  71306. // any of the the roam change.
  71307. this._range = dataZoomModel.getPercentRange();
  71308. // Reset controllers.
  71309. each$1(this.getTargetCoordInfo(), function (coordInfoList, coordSysName) {
  71310. var allCoordIds = map(coordInfoList, function (coordInfo) {
  71311. return generateCoordId(coordInfo.model);
  71312. });
  71313. each$1(coordInfoList, function (coordInfo) {
  71314. var coordModel = coordInfo.model;
  71315. var getRange = {};
  71316. each$1(['pan', 'zoom', 'scrollMove'], function (eventName) {
  71317. getRange[eventName] = bind$5(roamHandlers[eventName], this, coordInfo, coordSysName);
  71318. }, this);
  71319. register$2(
  71320. api,
  71321. {
  71322. coordId: generateCoordId(coordModel),
  71323. allCoordIds: allCoordIds,
  71324. containsPoint: function (e, x, y) {
  71325. return coordModel.coordinateSystem.containPoint([x, y]);
  71326. },
  71327. dataZoomId: dataZoomModel.id,
  71328. dataZoomModel: dataZoomModel,
  71329. getRange: getRange
  71330. }
  71331. );
  71332. }, this);
  71333. }, this);
  71334. },
  71335. /**
  71336. * @override
  71337. */
  71338. dispose: function () {
  71339. unregister$1(this.api, this.dataZoomModel.id);
  71340. InsideZoomView.superApply(this, 'dispose', arguments);
  71341. this._range = null;
  71342. }
  71343. });
  71344. var roamHandlers = {
  71345. /**
  71346. * @this {module:echarts/component/dataZoom/InsideZoomView}
  71347. */
  71348. zoom: function (coordInfo, coordSysName, controller, e) {
  71349. var lastRange = this._range;
  71350. var range = lastRange.slice();
  71351. // Calculate transform by the first axis.
  71352. var axisModel = coordInfo.axisModels[0];
  71353. if (!axisModel) {
  71354. return;
  71355. }
  71356. var directionInfo = getDirectionInfo[coordSysName](
  71357. null, [e.originX, e.originY], axisModel, controller, coordInfo
  71358. );
  71359. var percentPoint = (
  71360. directionInfo.signal > 0
  71361. ? (directionInfo.pixelStart + directionInfo.pixelLength - directionInfo.pixel)
  71362. : (directionInfo.pixel - directionInfo.pixelStart)
  71363. ) / directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  71364. var scale = Math.max(1 / e.scale, 0);
  71365. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  71366. range[1] = (range[1] - percentPoint) * scale + percentPoint;
  71367. // Restrict range.
  71368. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  71369. sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
  71370. this._range = range;
  71371. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  71372. return range;
  71373. }
  71374. },
  71375. /**
  71376. * @this {module:echarts/component/dataZoom/InsideZoomView}
  71377. */
  71378. pan: makeMover(function (range, axisModel, coordInfo, coordSysName, controller, e) {
  71379. var directionInfo = getDirectionInfo[coordSysName](
  71380. [e.oldX, e.oldY], [e.newX, e.newY], axisModel, controller, coordInfo
  71381. );
  71382. return directionInfo.signal
  71383. * (range[1] - range[0])
  71384. * directionInfo.pixel / directionInfo.pixelLength;
  71385. }),
  71386. /**
  71387. * @this {module:echarts/component/dataZoom/InsideZoomView}
  71388. */
  71389. scrollMove: makeMover(function (range, axisModel, coordInfo, coordSysName, controller, e) {
  71390. var directionInfo = getDirectionInfo[coordSysName](
  71391. [0, 0], [e.scrollDelta, e.scrollDelta], axisModel, controller, coordInfo
  71392. );
  71393. return directionInfo.signal * (range[1] - range[0]) * e.scrollDelta;
  71394. })
  71395. };
  71396. function makeMover(getPercentDelta) {
  71397. return function (coordInfo, coordSysName, controller, e) {
  71398. var lastRange = this._range;
  71399. var range = lastRange.slice();
  71400. // Calculate transform by the first axis.
  71401. var axisModel = coordInfo.axisModels[0];
  71402. if (!axisModel) {
  71403. return;
  71404. }
  71405. var percentDelta = getPercentDelta(
  71406. range, axisModel, coordInfo, coordSysName, controller, e
  71407. );
  71408. sliderMove(percentDelta, range, [0, 100], 'all');
  71409. this._range = range;
  71410. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  71411. return range;
  71412. }
  71413. };
  71414. }
  71415. var getDirectionInfo = {
  71416. grid: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  71417. var axis = axisModel.axis;
  71418. var ret = {};
  71419. var rect = coordInfo.model.coordinateSystem.getRect();
  71420. oldPoint = oldPoint || [0, 0];
  71421. if (axis.dim === 'x') {
  71422. ret.pixel = newPoint[0] - oldPoint[0];
  71423. ret.pixelLength = rect.width;
  71424. ret.pixelStart = rect.x;
  71425. ret.signal = axis.inverse ? 1 : -1;
  71426. }
  71427. else { // axis.dim === 'y'
  71428. ret.pixel = newPoint[1] - oldPoint[1];
  71429. ret.pixelLength = rect.height;
  71430. ret.pixelStart = rect.y;
  71431. ret.signal = axis.inverse ? -1 : 1;
  71432. }
  71433. return ret;
  71434. },
  71435. polar: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  71436. var axis = axisModel.axis;
  71437. var ret = {};
  71438. var polar = coordInfo.model.coordinateSystem;
  71439. var radiusExtent = polar.getRadiusAxis().getExtent();
  71440. var angleExtent = polar.getAngleAxis().getExtent();
  71441. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  71442. newPoint = polar.pointToCoord(newPoint);
  71443. if (axisModel.mainType === 'radiusAxis') {
  71444. ret.pixel = newPoint[0] - oldPoint[0];
  71445. // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  71446. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  71447. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  71448. ret.pixelStart = radiusExtent[0];
  71449. ret.signal = axis.inverse ? 1 : -1;
  71450. }
  71451. else { // 'angleAxis'
  71452. ret.pixel = newPoint[1] - oldPoint[1];
  71453. // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  71454. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  71455. ret.pixelLength = angleExtent[1] - angleExtent[0];
  71456. ret.pixelStart = angleExtent[0];
  71457. ret.signal = axis.inverse ? -1 : 1;
  71458. }
  71459. return ret;
  71460. },
  71461. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  71462. var axis = axisModel.axis;
  71463. var rect = coordInfo.model.coordinateSystem.getRect();
  71464. var ret = {};
  71465. oldPoint = oldPoint || [0, 0];
  71466. if (axis.orient === 'horizontal') {
  71467. ret.pixel = newPoint[0] - oldPoint[0];
  71468. ret.pixelLength = rect.width;
  71469. ret.pixelStart = rect.x;
  71470. ret.signal = axis.inverse ? 1 : -1;
  71471. }
  71472. else { // 'vertical'
  71473. ret.pixel = newPoint[1] - oldPoint[1];
  71474. ret.pixelLength = rect.height;
  71475. ret.pixelStart = rect.y;
  71476. ret.signal = axis.inverse ? -1 : 1;
  71477. }
  71478. return ret;
  71479. }
  71480. };
  71481. /*
  71482. * Licensed to the Apache Software Foundation (ASF) under one
  71483. * or more contributor license agreements. See the NOTICE file
  71484. * distributed with this work for additional information
  71485. * regarding copyright ownership. The ASF licenses this file
  71486. * to you under the Apache License, Version 2.0 (the
  71487. * "License"); you may not use this file except in compliance
  71488. * with the License. You may obtain a copy of the License at
  71489. *
  71490. * http://www.apache.org/licenses/LICENSE-2.0
  71491. *
  71492. * Unless required by applicable law or agreed to in writing,
  71493. * software distributed under the License is distributed on an
  71494. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71495. * KIND, either express or implied. See the License for the
  71496. * specific language governing permissions and limitations
  71497. * under the License.
  71498. */
  71499. registerProcessor({
  71500. // `dataZoomProcessor` will only be performed in needed series. Consider if
  71501. // there is a line series and a pie series, it is better not to update the
  71502. // line series if only pie series is needed to be updated.
  71503. getTargetSeries: function (ecModel) {
  71504. var seriesModelMap = createHashMap();
  71505. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  71506. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  71507. var axisProxy = dataZoomModel.getAxisProxy(dimNames.name, axisIndex);
  71508. each$1(axisProxy.getTargetSeriesModels(), function (seriesModel) {
  71509. seriesModelMap.set(seriesModel.uid, seriesModel);
  71510. });
  71511. });
  71512. });
  71513. return seriesModelMap;
  71514. },
  71515. modifyOutputEnd: true,
  71516. // Consider appendData, where filter should be performed. Because data process is
  71517. // in block mode currently, it is not need to worry about that the overallProgress
  71518. // execute every frame.
  71519. overallReset: function (ecModel, api) {
  71520. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  71521. // We calculate window and reset axis here but not in model
  71522. // init stage and not after action dispatch handler, because
  71523. // reset should be called after seriesData.restoreData.
  71524. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  71525. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel, api);
  71526. });
  71527. // Caution: data zoom filtering is order sensitive when using
  71528. // percent range and no min/max/scale set on axis.
  71529. // For example, we have dataZoom definition:
  71530. // [
  71531. // {xAxisIndex: 0, start: 30, end: 70},
  71532. // {yAxisIndex: 0, start: 20, end: 80}
  71533. // ]
  71534. // In this case, [20, 80] of y-dataZoom should be based on data
  71535. // that have filtered by x-dataZoom using range of [30, 70],
  71536. // but should not be based on full raw data. Thus sliding
  71537. // x-dataZoom will change both ranges of xAxis and yAxis,
  71538. // while sliding y-dataZoom will only change the range of yAxis.
  71539. // So we should filter x-axis after reset x-axis immediately,
  71540. // and then reset y-axis and filter y-axis.
  71541. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  71542. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel, api);
  71543. });
  71544. });
  71545. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  71546. // Fullfill all of the range props so that user
  71547. // is able to get them from chart.getOption().
  71548. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  71549. var percentRange = axisProxy.getDataPercentWindow();
  71550. var valueRange = axisProxy.getDataValueWindow();
  71551. dataZoomModel.setRawRange({
  71552. start: percentRange[0],
  71553. end: percentRange[1],
  71554. startValue: valueRange[0],
  71555. endValue: valueRange[1]
  71556. }, true);
  71557. });
  71558. }
  71559. });
  71560. /*
  71561. * Licensed to the Apache Software Foundation (ASF) under one
  71562. * or more contributor license agreements. See the NOTICE file
  71563. * distributed with this work for additional information
  71564. * regarding copyright ownership. The ASF licenses this file
  71565. * to you under the Apache License, Version 2.0 (the
  71566. * "License"); you may not use this file except in compliance
  71567. * with the License. You may obtain a copy of the License at
  71568. *
  71569. * http://www.apache.org/licenses/LICENSE-2.0
  71570. *
  71571. * Unless required by applicable law or agreed to in writing,
  71572. * software distributed under the License is distributed on an
  71573. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71574. * KIND, either express or implied. See the License for the
  71575. * specific language governing permissions and limitations
  71576. * under the License.
  71577. */
  71578. registerAction('dataZoom', function (payload, ecModel) {
  71579. var linkedNodesFinder = createLinkedNodesFinder(
  71580. bind(ecModel.eachComponent, ecModel, 'dataZoom'),
  71581. eachAxisDim$1,
  71582. function (model, dimNames) {
  71583. return model.get(dimNames.axisIndex);
  71584. }
  71585. );
  71586. var effectedModels = [];
  71587. ecModel.eachComponent(
  71588. {mainType: 'dataZoom', query: payload},
  71589. function (model, index) {
  71590. effectedModels.push.apply(
  71591. effectedModels, linkedNodesFinder(model).nodes
  71592. );
  71593. }
  71594. );
  71595. each$1(effectedModels, function (dataZoomModel, index) {
  71596. dataZoomModel.setRawRange({
  71597. start: payload.start,
  71598. end: payload.end,
  71599. startValue: payload.startValue,
  71600. endValue: payload.endValue
  71601. });
  71602. });
  71603. });
  71604. /*
  71605. * Licensed to the Apache Software Foundation (ASF) under one
  71606. * or more contributor license agreements. See the NOTICE file
  71607. * distributed with this work for additional information
  71608. * regarding copyright ownership. The ASF licenses this file
  71609. * to you under the Apache License, Version 2.0 (the
  71610. * "License"); you may not use this file except in compliance
  71611. * with the License. You may obtain a copy of the License at
  71612. *
  71613. * http://www.apache.org/licenses/LICENSE-2.0
  71614. *
  71615. * Unless required by applicable law or agreed to in writing,
  71616. * software distributed under the License is distributed on an
  71617. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71618. * KIND, either express or implied. See the License for the
  71619. * specific language governing permissions and limitations
  71620. * under the License.
  71621. */
  71622. /**
  71623. * DataZoom component entry
  71624. */
  71625. /*
  71626. * Licensed to the Apache Software Foundation (ASF) under one
  71627. * or more contributor license agreements. See the NOTICE file
  71628. * distributed with this work for additional information
  71629. * regarding copyright ownership. The ASF licenses this file
  71630. * to you under the Apache License, Version 2.0 (the
  71631. * "License"); you may not use this file except in compliance
  71632. * with the License. You may obtain a copy of the License at
  71633. *
  71634. * http://www.apache.org/licenses/LICENSE-2.0
  71635. *
  71636. * Unless required by applicable law or agreed to in writing,
  71637. * software distributed under the License is distributed on an
  71638. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71639. * KIND, either express or implied. See the License for the
  71640. * specific language governing permissions and limitations
  71641. * under the License.
  71642. */
  71643. var each$24 = each$1;
  71644. var preprocessor$2 = function (option) {
  71645. var visualMap = option && option.visualMap;
  71646. if (!isArray(visualMap)) {
  71647. visualMap = visualMap ? [visualMap] : [];
  71648. }
  71649. each$24(visualMap, function (opt) {
  71650. if (!opt) {
  71651. return;
  71652. }
  71653. // rename splitList to pieces
  71654. if (has$1(opt, 'splitList') && !has$1(opt, 'pieces')) {
  71655. opt.pieces = opt.splitList;
  71656. delete opt.splitList;
  71657. }
  71658. var pieces = opt.pieces;
  71659. if (pieces && isArray(pieces)) {
  71660. each$24(pieces, function (piece) {
  71661. if (isObject$1(piece)) {
  71662. if (has$1(piece, 'start') && !has$1(piece, 'min')) {
  71663. piece.min = piece.start;
  71664. }
  71665. if (has$1(piece, 'end') && !has$1(piece, 'max')) {
  71666. piece.max = piece.end;
  71667. }
  71668. }
  71669. });
  71670. }
  71671. });
  71672. };
  71673. function has$1(obj, name) {
  71674. return obj && obj.hasOwnProperty && obj.hasOwnProperty(name);
  71675. }
  71676. /*
  71677. * Licensed to the Apache Software Foundation (ASF) under one
  71678. * or more contributor license agreements. See the NOTICE file
  71679. * distributed with this work for additional information
  71680. * regarding copyright ownership. The ASF licenses this file
  71681. * to you under the Apache License, Version 2.0 (the
  71682. * "License"); you may not use this file except in compliance
  71683. * with the License. You may obtain a copy of the License at
  71684. *
  71685. * http://www.apache.org/licenses/LICENSE-2.0
  71686. *
  71687. * Unless required by applicable law or agreed to in writing,
  71688. * software distributed under the License is distributed on an
  71689. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71690. * KIND, either express or implied. See the License for the
  71691. * specific language governing permissions and limitations
  71692. * under the License.
  71693. */
  71694. ComponentModel.registerSubTypeDefaulter('visualMap', function (option) {
  71695. // Compatible with ec2, when splitNumber === 0, continuous visualMap will be used.
  71696. return (
  71697. !option.categories
  71698. && (
  71699. !(
  71700. option.pieces
  71701. ? option.pieces.length > 0
  71702. : option.splitNumber > 0
  71703. )
  71704. || option.calculable
  71705. )
  71706. )
  71707. ? 'continuous' : 'piecewise';
  71708. });
  71709. /*
  71710. * Licensed to the Apache Software Foundation (ASF) under one
  71711. * or more contributor license agreements. See the NOTICE file
  71712. * distributed with this work for additional information
  71713. * regarding copyright ownership. The ASF licenses this file
  71714. * to you under the Apache License, Version 2.0 (the
  71715. * "License"); you may not use this file except in compliance
  71716. * with the License. You may obtain a copy of the License at
  71717. *
  71718. * http://www.apache.org/licenses/LICENSE-2.0
  71719. *
  71720. * Unless required by applicable law or agreed to in writing,
  71721. * software distributed under the License is distributed on an
  71722. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71723. * KIND, either express or implied. See the License for the
  71724. * specific language governing permissions and limitations
  71725. * under the License.
  71726. */
  71727. var VISUAL_PRIORITY = PRIORITY.VISUAL.COMPONENT;
  71728. registerVisual(VISUAL_PRIORITY, {
  71729. createOnAllSeries: true,
  71730. reset: function (seriesModel, ecModel) {
  71731. var resetDefines = [];
  71732. ecModel.eachComponent('visualMap', function (visualMapModel) {
  71733. var pipelineContext = seriesModel.pipelineContext;
  71734. if (!visualMapModel.isTargetSeries(seriesModel)
  71735. || (pipelineContext && pipelineContext.large)
  71736. ) {
  71737. return;
  71738. }
  71739. resetDefines.push(incrementalApplyVisual(
  71740. visualMapModel.stateList,
  71741. visualMapModel.targetVisuals,
  71742. bind(visualMapModel.getValueState, visualMapModel),
  71743. visualMapModel.getDataDimension(seriesModel.getData())
  71744. ));
  71745. });
  71746. return resetDefines;
  71747. }
  71748. });
  71749. // Only support color.
  71750. registerVisual(VISUAL_PRIORITY, {
  71751. createOnAllSeries: true,
  71752. reset: function (seriesModel, ecModel) {
  71753. var data = seriesModel.getData();
  71754. var visualMetaList = [];
  71755. ecModel.eachComponent('visualMap', function (visualMapModel) {
  71756. if (visualMapModel.isTargetSeries(seriesModel)) {
  71757. var visualMeta = visualMapModel.getVisualMeta(
  71758. bind(getColorVisual, null, seriesModel, visualMapModel)
  71759. ) || {stops: [], outerColors: []};
  71760. var concreteDim = visualMapModel.getDataDimension(data);
  71761. var dimInfo = data.getDimensionInfo(concreteDim);
  71762. if (dimInfo != null) {
  71763. // visualMeta.dimension should be dimension index, but not concrete dimension.
  71764. visualMeta.dimension = dimInfo.index;
  71765. visualMetaList.push(visualMeta);
  71766. }
  71767. }
  71768. });
  71769. // console.log(JSON.stringify(visualMetaList.map(a => a.stops)));
  71770. seriesModel.getData().setVisual('visualMeta', visualMetaList);
  71771. }
  71772. });
  71773. // FIXME
  71774. // performance and export for heatmap?
  71775. // value can be Infinity or -Infinity
  71776. function getColorVisual(seriesModel, visualMapModel, value, valueState) {
  71777. var mappings = visualMapModel.targetVisuals[valueState];
  71778. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  71779. var resultVisual = {
  71780. color: seriesModel.getData().getVisual('color') // default color.
  71781. };
  71782. for (var i = 0, len = visualTypes.length; i < len; i++) {
  71783. var type = visualTypes[i];
  71784. var mapping = mappings[
  71785. type === 'opacity' ? '__alphaForOpacity' : type
  71786. ];
  71787. mapping && mapping.applyVisual(value, getVisual, setVisual);
  71788. }
  71789. return resultVisual.color;
  71790. function getVisual(key) {
  71791. return resultVisual[key];
  71792. }
  71793. function setVisual(key, value) {
  71794. resultVisual[key] = value;
  71795. }
  71796. }
  71797. /*
  71798. * Licensed to the Apache Software Foundation (ASF) under one
  71799. * or more contributor license agreements. See the NOTICE file
  71800. * distributed with this work for additional information
  71801. * regarding copyright ownership. The ASF licenses this file
  71802. * to you under the Apache License, Version 2.0 (the
  71803. * "License"); you may not use this file except in compliance
  71804. * with the License. You may obtain a copy of the License at
  71805. *
  71806. * http://www.apache.org/licenses/LICENSE-2.0
  71807. *
  71808. * Unless required by applicable law or agreed to in writing,
  71809. * software distributed under the License is distributed on an
  71810. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71811. * KIND, either express or implied. See the License for the
  71812. * specific language governing permissions and limitations
  71813. * under the License.
  71814. */
  71815. /**
  71816. * @file Visual mapping.
  71817. */
  71818. var visualDefault = {
  71819. /**
  71820. * @public
  71821. */
  71822. get: function (visualType, key, isCategory) {
  71823. var value = clone(
  71824. (defaultOption$3[visualType] || {})[key]
  71825. );
  71826. return isCategory
  71827. ? (isArray(value) ? value[value.length - 1] : value)
  71828. : value;
  71829. }
  71830. };
  71831. var defaultOption$3 = {
  71832. color: {
  71833. active: ['#006edd', '#e0ffff'],
  71834. inactive: ['rgba(0,0,0,0)']
  71835. },
  71836. colorHue: {
  71837. active: [0, 360],
  71838. inactive: [0, 0]
  71839. },
  71840. colorSaturation: {
  71841. active: [0.3, 1],
  71842. inactive: [0, 0]
  71843. },
  71844. colorLightness: {
  71845. active: [0.9, 0.5],
  71846. inactive: [0, 0]
  71847. },
  71848. colorAlpha: {
  71849. active: [0.3, 1],
  71850. inactive: [0, 0]
  71851. },
  71852. opacity: {
  71853. active: [0.3, 1],
  71854. inactive: [0, 0]
  71855. },
  71856. symbol: {
  71857. active: ['circle', 'roundRect', 'diamond'],
  71858. inactive: ['none']
  71859. },
  71860. symbolSize: {
  71861. active: [10, 50],
  71862. inactive: [0, 0]
  71863. }
  71864. };
  71865. /*
  71866. * Licensed to the Apache Software Foundation (ASF) under one
  71867. * or more contributor license agreements. See the NOTICE file
  71868. * distributed with this work for additional information
  71869. * regarding copyright ownership. The ASF licenses this file
  71870. * to you under the Apache License, Version 2.0 (the
  71871. * "License"); you may not use this file except in compliance
  71872. * with the License. You may obtain a copy of the License at
  71873. *
  71874. * http://www.apache.org/licenses/LICENSE-2.0
  71875. *
  71876. * Unless required by applicable law or agreed to in writing,
  71877. * software distributed under the License is distributed on an
  71878. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71879. * KIND, either express or implied. See the License for the
  71880. * specific language governing permissions and limitations
  71881. * under the License.
  71882. */
  71883. var mapVisual$2 = VisualMapping.mapVisual;
  71884. var eachVisual = VisualMapping.eachVisual;
  71885. var isArray$3 = isArray;
  71886. var each$25 = each$1;
  71887. var asc$3 = asc;
  71888. var linearMap$2 = linearMap;
  71889. var noop$2 = noop;
  71890. var VisualMapModel = extendComponentModel({
  71891. type: 'visualMap',
  71892. dependencies: ['series'],
  71893. /**
  71894. * @readOnly
  71895. * @type {Array.<string>}
  71896. */
  71897. stateList: ['inRange', 'outOfRange'],
  71898. /**
  71899. * @readOnly
  71900. * @type {Array.<string>}
  71901. */
  71902. replacableOptionKeys: [
  71903. 'inRange', 'outOfRange', 'target', 'controller', 'color'
  71904. ],
  71905. /**
  71906. * [lowerBound, upperBound]
  71907. *
  71908. * @readOnly
  71909. * @type {Array.<number>}
  71910. */
  71911. dataBound: [-Infinity, Infinity],
  71912. /**
  71913. * @readOnly
  71914. * @type {string|Object}
  71915. */
  71916. layoutMode: {type: 'box', ignoreSize: true},
  71917. /**
  71918. * @protected
  71919. */
  71920. defaultOption: {
  71921. show: true,
  71922. zlevel: 0,
  71923. z: 4,
  71924. seriesIndex: 'all', // 'all' or null/undefined: all series.
  71925. // A number or an array of number: the specified series.
  71926. // set min: 0, max: 200, only for campatible with ec2.
  71927. // In fact min max should not have default value.
  71928. min: 0, // min value, must specified if pieces is not specified.
  71929. max: 200, // max value, must specified if pieces is not specified.
  71930. dimension: null,
  71931. inRange: null, // 'color', 'colorHue', 'colorSaturation', 'colorLightness', 'colorAlpha',
  71932. // 'symbol', 'symbolSize'
  71933. outOfRange: null, // 'color', 'colorHue', 'colorSaturation',
  71934. // 'colorLightness', 'colorAlpha',
  71935. // 'symbol', 'symbolSize'
  71936. left: 0, // 'center' ¦ 'left' ¦ 'right' ¦ {number} (px)
  71937. right: null, // The same as left.
  71938. top: null, // 'top' ¦ 'bottom' ¦ 'center' ¦ {number} (px)
  71939. bottom: 0, // The same as top.
  71940. itemWidth: null,
  71941. itemHeight: null,
  71942. inverse: false,
  71943. orient: 'vertical', // 'horizontal' ¦ 'vertical'
  71944. backgroundColor: 'rgba(0,0,0,0)',
  71945. borderColor: '#ccc', // 值域边框颜色
  71946. contentColor: '#5793f3',
  71947. inactiveColor: '#aaa',
  71948. borderWidth: 0, // 值域边框线宽,单位px,默认为0(无边框)
  71949. padding: 5, // 值域内边距,单位px,默认各方向内边距为5,
  71950. // 接受数组分别设定上右下左边距,同css
  71951. textGap: 10, //
  71952. precision: 0, // 小数精度,默认为0,无小数点
  71953. color: null, //颜色(deprecated,兼容ec2,顺序同pieces,不同于inRange/outOfRange)
  71954. formatter: null,
  71955. text: null, // 文本,如['高', '低'],兼容ec2,text[0]对应高值,text[1]对应低值
  71956. textStyle: {
  71957. color: '#333' // 值域文字颜色
  71958. }
  71959. },
  71960. /**
  71961. * @protected
  71962. */
  71963. init: function (option, parentModel, ecModel) {
  71964. /**
  71965. * @private
  71966. * @type {Array.<number>}
  71967. */
  71968. this._dataExtent;
  71969. /**
  71970. * @readOnly
  71971. */
  71972. this.targetVisuals = {};
  71973. /**
  71974. * @readOnly
  71975. */
  71976. this.controllerVisuals = {};
  71977. /**
  71978. * @readOnly
  71979. */
  71980. this.textStyleModel;
  71981. /**
  71982. * [width, height]
  71983. * @readOnly
  71984. * @type {Array.<number>}
  71985. */
  71986. this.itemSize;
  71987. this.mergeDefaultAndTheme(option, ecModel);
  71988. },
  71989. /**
  71990. * @protected
  71991. */
  71992. optionUpdated: function (newOption, isInit) {
  71993. var thisOption = this.option;
  71994. // FIXME
  71995. // necessary?
  71996. // Disable realtime view update if canvas is not supported.
  71997. if (!env$1.canvasSupported) {
  71998. thisOption.realtime = false;
  71999. }
  72000. !isInit && replaceVisualOption(
  72001. thisOption, newOption, this.replacableOptionKeys
  72002. );
  72003. this.textStyleModel = this.getModel('textStyle');
  72004. this.resetItemSize();
  72005. this.completeVisualOption();
  72006. },
  72007. /**
  72008. * @protected
  72009. */
  72010. resetVisual: function (supplementVisualOption) {
  72011. var stateList = this.stateList;
  72012. supplementVisualOption = bind(supplementVisualOption, this);
  72013. this.controllerVisuals = createVisualMappings(
  72014. this.option.controller, stateList, supplementVisualOption
  72015. );
  72016. this.targetVisuals = createVisualMappings(
  72017. this.option.target, stateList, supplementVisualOption
  72018. );
  72019. },
  72020. /**
  72021. * @protected
  72022. * @return {Array.<number>} An array of series indices.
  72023. */
  72024. getTargetSeriesIndices: function () {
  72025. var optionSeriesIndex = this.option.seriesIndex;
  72026. var seriesIndices = [];
  72027. if (optionSeriesIndex == null || optionSeriesIndex === 'all') {
  72028. this.ecModel.eachSeries(function (seriesModel, index) {
  72029. seriesIndices.push(index);
  72030. });
  72031. }
  72032. else {
  72033. seriesIndices = normalizeToArray(optionSeriesIndex);
  72034. }
  72035. return seriesIndices;
  72036. },
  72037. /**
  72038. * @public
  72039. */
  72040. eachTargetSeries: function (callback, context) {
  72041. each$1(this.getTargetSeriesIndices(), function (seriesIndex) {
  72042. callback.call(context, this.ecModel.getSeriesByIndex(seriesIndex));
  72043. }, this);
  72044. },
  72045. /**
  72046. * @pubilc
  72047. */
  72048. isTargetSeries: function (seriesModel) {
  72049. var is = false;
  72050. this.eachTargetSeries(function (model) {
  72051. model === seriesModel && (is = true);
  72052. });
  72053. return is;
  72054. },
  72055. /**
  72056. * @example
  72057. * this.formatValueText(someVal); // format single numeric value to text.
  72058. * this.formatValueText(someVal, true); // format single category value to text.
  72059. * this.formatValueText([min, max]); // format numeric min-max to text.
  72060. * this.formatValueText([this.dataBound[0], max]); // using data lower bound.
  72061. * this.formatValueText([min, this.dataBound[1]]); // using data upper bound.
  72062. *
  72063. * @param {number|Array.<number>} value Real value, or this.dataBound[0 or 1].
  72064. * @param {boolean} [isCategory=false] Only available when value is number.
  72065. * @param {Array.<string>} edgeSymbols Open-close symbol when value is interval.
  72066. * @return {string}
  72067. * @protected
  72068. */
  72069. formatValueText: function (value, isCategory, edgeSymbols) {
  72070. var option = this.option;
  72071. var precision = option.precision;
  72072. var dataBound = this.dataBound;
  72073. var formatter = option.formatter;
  72074. var isMinMax;
  72075. var textValue;
  72076. edgeSymbols = edgeSymbols || ['<', '>'];
  72077. if (isArray(value)) {
  72078. value = value.slice();
  72079. isMinMax = true;
  72080. }
  72081. textValue = isCategory
  72082. ? value
  72083. : (isMinMax
  72084. ? [toFixed(value[0]), toFixed(value[1])]
  72085. : toFixed(value)
  72086. );
  72087. if (isString(formatter)) {
  72088. return formatter
  72089. .replace('{value}', isMinMax ? textValue[0] : textValue)
  72090. .replace('{value2}', isMinMax ? textValue[1] : textValue);
  72091. }
  72092. else if (isFunction$1(formatter)) {
  72093. return isMinMax
  72094. ? formatter(value[0], value[1])
  72095. : formatter(value);
  72096. }
  72097. if (isMinMax) {
  72098. if (value[0] === dataBound[0]) {
  72099. return edgeSymbols[0] + ' ' + textValue[1];
  72100. }
  72101. else if (value[1] === dataBound[1]) {
  72102. return edgeSymbols[1] + ' ' + textValue[0];
  72103. }
  72104. else {
  72105. return textValue[0] + ' - ' + textValue[1];
  72106. }
  72107. }
  72108. else { // Format single value (includes category case).
  72109. return textValue;
  72110. }
  72111. function toFixed(val) {
  72112. return val === dataBound[0]
  72113. ? 'min'
  72114. : val === dataBound[1]
  72115. ? 'max'
  72116. : (+val).toFixed(Math.min(precision, 20));
  72117. }
  72118. },
  72119. /**
  72120. * @protected
  72121. */
  72122. resetExtent: function () {
  72123. var thisOption = this.option;
  72124. // Can not calculate data extent by data here.
  72125. // Because series and data may be modified in processing stage.
  72126. // So we do not support the feature "auto min/max".
  72127. var extent = asc$3([thisOption.min, thisOption.max]);
  72128. this._dataExtent = extent;
  72129. },
  72130. /**
  72131. * @public
  72132. * @param {module:echarts/data/List} list
  72133. * @return {string} Concrete dimention. If return null/undefined,
  72134. * no dimension used.
  72135. */
  72136. getDataDimension: function (list) {
  72137. var optDim = this.option.dimension;
  72138. var listDimensions = list.dimensions;
  72139. if (optDim == null && !listDimensions.length) {
  72140. return;
  72141. }
  72142. if (optDim != null) {
  72143. return list.getDimension(optDim);
  72144. }
  72145. var dimNames = list.dimensions;
  72146. for (var i = dimNames.length - 1; i >= 0; i--) {
  72147. var dimName = dimNames[i];
  72148. var dimInfo = list.getDimensionInfo(dimName);
  72149. if (!dimInfo.isCalculationCoord) {
  72150. return dimName;
  72151. }
  72152. }
  72153. },
  72154. /**
  72155. * @public
  72156. * @override
  72157. */
  72158. getExtent: function () {
  72159. return this._dataExtent.slice();
  72160. },
  72161. /**
  72162. * @protected
  72163. */
  72164. completeVisualOption: function () {
  72165. var ecModel = this.ecModel;
  72166. var thisOption = this.option;
  72167. var base = {inRange: thisOption.inRange, outOfRange: thisOption.outOfRange};
  72168. var target = thisOption.target || (thisOption.target = {});
  72169. var controller = thisOption.controller || (thisOption.controller = {});
  72170. merge(target, base); // Do not override
  72171. merge(controller, base); // Do not override
  72172. var isCategory = this.isCategory();
  72173. completeSingle.call(this, target);
  72174. completeSingle.call(this, controller);
  72175. completeInactive.call(this, target, 'inRange', 'outOfRange');
  72176. // completeInactive.call(this, target, 'outOfRange', 'inRange');
  72177. completeController.call(this, controller);
  72178. function completeSingle(base) {
  72179. // Compatible with ec2 dataRange.color.
  72180. // The mapping order of dataRange.color is: [high value, ..., low value]
  72181. // whereas inRange.color and outOfRange.color is [low value, ..., high value]
  72182. // Notice: ec2 has no inverse.
  72183. if (isArray$3(thisOption.color)
  72184. // If there has been inRange: {symbol: ...}, adding color is a mistake.
  72185. // So adding color only when no inRange defined.
  72186. && !base.inRange
  72187. ) {
  72188. base.inRange = {color: thisOption.color.slice().reverse()};
  72189. }
  72190. // Compatible with previous logic, always give a defautl color, otherwise
  72191. // simple config with no inRange and outOfRange will not work.
  72192. // Originally we use visualMap.color as the default color, but setOption at
  72193. // the second time the default color will be erased. So we change to use
  72194. // constant DEFAULT_COLOR.
  72195. // If user do not want the defualt color, set inRange: {color: null}.
  72196. base.inRange = base.inRange || {color: ecModel.get('gradientColor')};
  72197. // If using shortcut like: {inRange: 'symbol'}, complete default value.
  72198. each$25(this.stateList, function (state) {
  72199. var visualType = base[state];
  72200. if (isString(visualType)) {
  72201. var defa = visualDefault.get(visualType, 'active', isCategory);
  72202. if (defa) {
  72203. base[state] = {};
  72204. base[state][visualType] = defa;
  72205. }
  72206. else {
  72207. // Mark as not specified.
  72208. delete base[state];
  72209. }
  72210. }
  72211. }, this);
  72212. }
  72213. function completeInactive(base, stateExist, stateAbsent) {
  72214. var optExist = base[stateExist];
  72215. var optAbsent = base[stateAbsent];
  72216. if (optExist && !optAbsent) {
  72217. optAbsent = base[stateAbsent] = {};
  72218. each$25(optExist, function (visualData, visualType) {
  72219. if (!VisualMapping.isValidType(visualType)) {
  72220. return;
  72221. }
  72222. var defa = visualDefault.get(visualType, 'inactive', isCategory);
  72223. if (defa != null) {
  72224. optAbsent[visualType] = defa;
  72225. // Compatibable with ec2:
  72226. // Only inactive color to rgba(0,0,0,0) can not
  72227. // make label transparent, so use opacity also.
  72228. if (visualType === 'color'
  72229. && !optAbsent.hasOwnProperty('opacity')
  72230. && !optAbsent.hasOwnProperty('colorAlpha')
  72231. ) {
  72232. optAbsent.opacity = [0, 0];
  72233. }
  72234. }
  72235. });
  72236. }
  72237. }
  72238. function completeController(controller) {
  72239. var symbolExists = (controller.inRange || {}).symbol
  72240. || (controller.outOfRange || {}).symbol;
  72241. var symbolSizeExists = (controller.inRange || {}).symbolSize
  72242. || (controller.outOfRange || {}).symbolSize;
  72243. var inactiveColor = this.get('inactiveColor');
  72244. each$25(this.stateList, function (state) {
  72245. var itemSize = this.itemSize;
  72246. var visuals = controller[state];
  72247. // Set inactive color for controller if no other color
  72248. // attr (like colorAlpha) specified.
  72249. if (!visuals) {
  72250. visuals = controller[state] = {
  72251. color: isCategory ? inactiveColor : [inactiveColor]
  72252. };
  72253. }
  72254. // Consistent symbol and symbolSize if not specified.
  72255. if (visuals.symbol == null) {
  72256. visuals.symbol = symbolExists
  72257. && clone(symbolExists)
  72258. || (isCategory ? 'roundRect' : ['roundRect']);
  72259. }
  72260. if (visuals.symbolSize == null) {
  72261. visuals.symbolSize = symbolSizeExists
  72262. && clone(symbolSizeExists)
  72263. || (isCategory ? itemSize[0] : [itemSize[0], itemSize[0]]);
  72264. }
  72265. // Filter square and none.
  72266. visuals.symbol = mapVisual$2(visuals.symbol, function (symbol) {
  72267. return (symbol === 'none' || symbol === 'square') ? 'roundRect' : symbol;
  72268. });
  72269. // Normalize symbolSize
  72270. var symbolSize = visuals.symbolSize;
  72271. if (symbolSize != null) {
  72272. var max = -Infinity;
  72273. // symbolSize can be object when categories defined.
  72274. eachVisual(symbolSize, function (value) {
  72275. value > max && (max = value);
  72276. });
  72277. visuals.symbolSize = mapVisual$2(symbolSize, function (value) {
  72278. return linearMap$2(value, [0, max], [0, itemSize[0]], true);
  72279. });
  72280. }
  72281. }, this);
  72282. }
  72283. },
  72284. /**
  72285. * @protected
  72286. */
  72287. resetItemSize: function () {
  72288. this.itemSize = [
  72289. parseFloat(this.get('itemWidth')),
  72290. parseFloat(this.get('itemHeight'))
  72291. ];
  72292. },
  72293. /**
  72294. * @public
  72295. */
  72296. isCategory: function () {
  72297. return !!this.option.categories;
  72298. },
  72299. /**
  72300. * @public
  72301. * @abstract
  72302. */
  72303. setSelected: noop$2,
  72304. /**
  72305. * @public
  72306. * @abstract
  72307. * @param {*|module:echarts/data/List} valueOrData
  72308. * @param {number} dataIndex
  72309. * @return {string} state See this.stateList
  72310. */
  72311. getValueState: noop$2,
  72312. /**
  72313. * FIXME
  72314. * Do not publish to thirt-part-dev temporarily
  72315. * util the interface is stable. (Should it return
  72316. * a function but not visual meta?)
  72317. *
  72318. * @pubilc
  72319. * @abstract
  72320. * @param {Function} getColorVisual
  72321. * params: value, valueState
  72322. * return: color
  72323. * @return {Object} visualMeta
  72324. * should includes {stops, outerColors}
  72325. * outerColor means [colorBeyondMinValue, colorBeyondMaxValue]
  72326. */
  72327. getVisualMeta: noop$2
  72328. });
  72329. /*
  72330. * Licensed to the Apache Software Foundation (ASF) under one
  72331. * or more contributor license agreements. See the NOTICE file
  72332. * distributed with this work for additional information
  72333. * regarding copyright ownership. The ASF licenses this file
  72334. * to you under the Apache License, Version 2.0 (the
  72335. * "License"); you may not use this file except in compliance
  72336. * with the License. You may obtain a copy of the License at
  72337. *
  72338. * http://www.apache.org/licenses/LICENSE-2.0
  72339. *
  72340. * Unless required by applicable law or agreed to in writing,
  72341. * software distributed under the License is distributed on an
  72342. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72343. * KIND, either express or implied. See the License for the
  72344. * specific language governing permissions and limitations
  72345. * under the License.
  72346. */
  72347. // Constant
  72348. var DEFAULT_BAR_BOUND = [20, 140];
  72349. var ContinuousModel = VisualMapModel.extend({
  72350. type: 'visualMap.continuous',
  72351. /**
  72352. * @protected
  72353. */
  72354. defaultOption: {
  72355. align: 'auto', // 'auto', 'left', 'right', 'top', 'bottom'
  72356. calculable: false, // This prop effect default component type determine,
  72357. // See echarts/component/visualMap/typeDefaulter.
  72358. range: null, // selected range. In default case `range` is [min, max]
  72359. // and can auto change along with modification of min max,
  72360. // util use specifid a range.
  72361. realtime: true, // Whether realtime update.
  72362. itemHeight: null, // The length of the range control edge.
  72363. itemWidth: null, // The length of the other side.
  72364. hoverLink: true, // Enable hover highlight.
  72365. hoverLinkDataSize: null, // The size of hovered data.
  72366. hoverLinkOnHandle: null // Whether trigger hoverLink when hover handle.
  72367. // If not specified, follow the value of `realtime`.
  72368. },
  72369. /**
  72370. * @override
  72371. */
  72372. optionUpdated: function (newOption, isInit) {
  72373. ContinuousModel.superApply(this, 'optionUpdated', arguments);
  72374. this.resetExtent();
  72375. this.resetVisual(function (mappingOption) {
  72376. mappingOption.mappingMethod = 'linear';
  72377. mappingOption.dataExtent = this.getExtent();
  72378. });
  72379. this._resetRange();
  72380. },
  72381. /**
  72382. * @protected
  72383. * @override
  72384. */
  72385. resetItemSize: function () {
  72386. ContinuousModel.superApply(this, 'resetItemSize', arguments);
  72387. var itemSize = this.itemSize;
  72388. this._orient === 'horizontal' && itemSize.reverse();
  72389. (itemSize[0] == null || isNaN(itemSize[0])) && (itemSize[0] = DEFAULT_BAR_BOUND[0]);
  72390. (itemSize[1] == null || isNaN(itemSize[1])) && (itemSize[1] = DEFAULT_BAR_BOUND[1]);
  72391. },
  72392. /**
  72393. * @private
  72394. */
  72395. _resetRange: function () {
  72396. var dataExtent = this.getExtent();
  72397. var range = this.option.range;
  72398. if (!range || range.auto) {
  72399. // `range` should always be array (so we dont use other
  72400. // value like 'auto') for user-friend. (consider getOption).
  72401. dataExtent.auto = 1;
  72402. this.option.range = dataExtent;
  72403. }
  72404. else if (isArray(range)) {
  72405. if (range[0] > range[1]) {
  72406. range.reverse();
  72407. }
  72408. range[0] = Math.max(range[0], dataExtent[0]);
  72409. range[1] = Math.min(range[1], dataExtent[1]);
  72410. }
  72411. },
  72412. /**
  72413. * @protected
  72414. * @override
  72415. */
  72416. completeVisualOption: function () {
  72417. VisualMapModel.prototype.completeVisualOption.apply(this, arguments);
  72418. each$1(this.stateList, function (state) {
  72419. var symbolSize = this.option.controller[state].symbolSize;
  72420. if (symbolSize && symbolSize[0] !== symbolSize[1]) {
  72421. symbolSize[0] = 0; // For good looking.
  72422. }
  72423. }, this);
  72424. },
  72425. /**
  72426. * @override
  72427. */
  72428. setSelected: function (selected) {
  72429. this.option.range = selected.slice();
  72430. this._resetRange();
  72431. },
  72432. /**
  72433. * @public
  72434. */
  72435. getSelected: function () {
  72436. var dataExtent = this.getExtent();
  72437. var dataInterval = asc(
  72438. (this.get('range') || []).slice()
  72439. );
  72440. // Clamp
  72441. dataInterval[0] > dataExtent[1] && (dataInterval[0] = dataExtent[1]);
  72442. dataInterval[1] > dataExtent[1] && (dataInterval[1] = dataExtent[1]);
  72443. dataInterval[0] < dataExtent[0] && (dataInterval[0] = dataExtent[0]);
  72444. dataInterval[1] < dataExtent[0] && (dataInterval[1] = dataExtent[0]);
  72445. return dataInterval;
  72446. },
  72447. /**
  72448. * @override
  72449. */
  72450. getValueState: function (value) {
  72451. var range = this.option.range;
  72452. var dataExtent = this.getExtent();
  72453. // When range[0] === dataExtent[0], any value larger than dataExtent[0] maps to 'inRange'.
  72454. // range[1] is processed likewise.
  72455. return (
  72456. (range[0] <= dataExtent[0] || range[0] <= value)
  72457. && (range[1] >= dataExtent[1] || value <= range[1])
  72458. ) ? 'inRange' : 'outOfRange';
  72459. },
  72460. /**
  72461. * @params {Array.<number>} range target value: range[0] <= value && value <= range[1]
  72462. * @return {Array.<Object>} [{seriesId, dataIndices: <Array.<number>>}, ...]
  72463. */
  72464. findTargetDataIndices: function (range) {
  72465. var result = [];
  72466. this.eachTargetSeries(function (seriesModel) {
  72467. var dataIndices = [];
  72468. var data = seriesModel.getData();
  72469. data.each(this.getDataDimension(data), function (value, dataIndex) {
  72470. range[0] <= value && value <= range[1] && dataIndices.push(dataIndex);
  72471. }, this);
  72472. result.push({seriesId: seriesModel.id, dataIndex: dataIndices});
  72473. }, this);
  72474. return result;
  72475. },
  72476. /**
  72477. * @implement
  72478. */
  72479. getVisualMeta: function (getColorVisual) {
  72480. var oVals = getColorStopValues(this, 'outOfRange', this.getExtent());
  72481. var iVals = getColorStopValues(this, 'inRange', this.option.range.slice());
  72482. var stops = [];
  72483. function setStop(value, valueState) {
  72484. stops.push({
  72485. value: value,
  72486. color: getColorVisual(value, valueState)
  72487. });
  72488. }
  72489. // Format to: outOfRange -- inRange -- outOfRange.
  72490. var iIdx = 0;
  72491. var oIdx = 0;
  72492. var iLen = iVals.length;
  72493. var oLen = oVals.length;
  72494. for (; oIdx < oLen && (!iVals.length || oVals[oIdx] <= iVals[0]); oIdx++) {
  72495. // If oVal[oIdx] === iVals[iIdx], oVal[oIdx] should be ignored.
  72496. if (oVals[oIdx] < iVals[iIdx]) {
  72497. setStop(oVals[oIdx], 'outOfRange');
  72498. }
  72499. }
  72500. for (var first = 1; iIdx < iLen; iIdx++, first = 0) {
  72501. // If range is full, value beyond min, max will be clamped.
  72502. // make a singularity
  72503. first && stops.length && setStop(iVals[iIdx], 'outOfRange');
  72504. setStop(iVals[iIdx], 'inRange');
  72505. }
  72506. for (var first = 1; oIdx < oLen; oIdx++) {
  72507. if (!iVals.length || iVals[iVals.length - 1] < oVals[oIdx]) {
  72508. // make a singularity
  72509. if (first) {
  72510. stops.length && setStop(stops[stops.length - 1].value, 'outOfRange');
  72511. first = 0;
  72512. }
  72513. setStop(oVals[oIdx], 'outOfRange');
  72514. }
  72515. }
  72516. var stopsLen = stops.length;
  72517. return {
  72518. stops: stops,
  72519. outerColors: [
  72520. stopsLen ? stops[0].color : 'transparent',
  72521. stopsLen ? stops[stopsLen - 1].color : 'transparent'
  72522. ]
  72523. };
  72524. }
  72525. });
  72526. function getColorStopValues(visualMapModel, valueState, dataExtent) {
  72527. if (dataExtent[0] === dataExtent[1]) {
  72528. return dataExtent.slice();
  72529. }
  72530. // When using colorHue mapping, it is not linear color any more.
  72531. // Moreover, canvas gradient seems not to be accurate linear.
  72532. // FIXME
  72533. // Should be arbitrary value 100? or based on pixel size?
  72534. var count = 200;
  72535. var step = (dataExtent[1] - dataExtent[0]) / count;
  72536. var value = dataExtent[0];
  72537. var stopValues = [];
  72538. for (var i = 0; i <= count && value < dataExtent[1]; i++) {
  72539. stopValues.push(value);
  72540. value += step;
  72541. }
  72542. stopValues.push(dataExtent[1]);
  72543. return stopValues;
  72544. }
  72545. /*
  72546. * Licensed to the Apache Software Foundation (ASF) under one
  72547. * or more contributor license agreements. See the NOTICE file
  72548. * distributed with this work for additional information
  72549. * regarding copyright ownership. The ASF licenses this file
  72550. * to you under the Apache License, Version 2.0 (the
  72551. * "License"); you may not use this file except in compliance
  72552. * with the License. You may obtain a copy of the License at
  72553. *
  72554. * http://www.apache.org/licenses/LICENSE-2.0
  72555. *
  72556. * Unless required by applicable law or agreed to in writing,
  72557. * software distributed under the License is distributed on an
  72558. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72559. * KIND, either express or implied. See the License for the
  72560. * specific language governing permissions and limitations
  72561. * under the License.
  72562. */
  72563. var VisualMapView = extendComponentView({
  72564. type: 'visualMap',
  72565. /**
  72566. * @readOnly
  72567. * @type {Object}
  72568. */
  72569. autoPositionValues: {left: 1, right: 1, top: 1, bottom: 1},
  72570. init: function (ecModel, api) {
  72571. /**
  72572. * @readOnly
  72573. * @type {module:echarts/model/Global}
  72574. */
  72575. this.ecModel = ecModel;
  72576. /**
  72577. * @readOnly
  72578. * @type {module:echarts/ExtensionAPI}
  72579. */
  72580. this.api = api;
  72581. /**
  72582. * @readOnly
  72583. * @type {module:echarts/component/visualMap/visualMapModel}
  72584. */
  72585. this.visualMapModel;
  72586. },
  72587. /**
  72588. * @protected
  72589. */
  72590. render: function (visualMapModel, ecModel, api, payload) {
  72591. this.visualMapModel = visualMapModel;
  72592. if (visualMapModel.get('show') === false) {
  72593. this.group.removeAll();
  72594. return;
  72595. }
  72596. this.doRender.apply(this, arguments);
  72597. },
  72598. /**
  72599. * @protected
  72600. */
  72601. renderBackground: function (group) {
  72602. var visualMapModel = this.visualMapModel;
  72603. var padding = normalizeCssArray$1(visualMapModel.get('padding') || 0);
  72604. var rect = group.getBoundingRect();
  72605. group.add(new Rect({
  72606. z2: -1, // Lay background rect on the lowest layer.
  72607. silent: true,
  72608. shape: {
  72609. x: rect.x - padding[3],
  72610. y: rect.y - padding[0],
  72611. width: rect.width + padding[3] + padding[1],
  72612. height: rect.height + padding[0] + padding[2]
  72613. },
  72614. style: {
  72615. fill: visualMapModel.get('backgroundColor'),
  72616. stroke: visualMapModel.get('borderColor'),
  72617. lineWidth: visualMapModel.get('borderWidth')
  72618. }
  72619. }));
  72620. },
  72621. /**
  72622. * @protected
  72623. * @param {number} targetValue can be Infinity or -Infinity
  72624. * @param {string=} visualCluster Only can be 'color' 'opacity' 'symbol' 'symbolSize'
  72625. * @param {Object} [opts]
  72626. * @param {string=} [opts.forceState] Specify state, instead of using getValueState method.
  72627. * @param {string=} [opts.convertOpacityToAlpha=false] For color gradient in controller widget.
  72628. * @return {*} Visual value.
  72629. */
  72630. getControllerVisual: function (targetValue, visualCluster, opts) {
  72631. opts = opts || {};
  72632. var forceState = opts.forceState;
  72633. var visualMapModel = this.visualMapModel;
  72634. var visualObj = {};
  72635. // Default values.
  72636. if (visualCluster === 'symbol') {
  72637. visualObj.symbol = visualMapModel.get('itemSymbol');
  72638. }
  72639. if (visualCluster === 'color') {
  72640. var defaultColor = visualMapModel.get('contentColor');
  72641. visualObj.color = defaultColor;
  72642. }
  72643. function getter(key) {
  72644. return visualObj[key];
  72645. }
  72646. function setter(key, value) {
  72647. visualObj[key] = value;
  72648. }
  72649. var mappings = visualMapModel.controllerVisuals[
  72650. forceState || visualMapModel.getValueState(targetValue)
  72651. ];
  72652. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  72653. each$1(visualTypes, function (type) {
  72654. var visualMapping = mappings[type];
  72655. if (opts.convertOpacityToAlpha && type === 'opacity') {
  72656. type = 'colorAlpha';
  72657. visualMapping = mappings.__alphaForOpacity;
  72658. }
  72659. if (VisualMapping.dependsOn(type, visualCluster)) {
  72660. visualMapping && visualMapping.applyVisual(
  72661. targetValue, getter, setter
  72662. );
  72663. }
  72664. });
  72665. return visualObj[visualCluster];
  72666. },
  72667. /**
  72668. * @protected
  72669. */
  72670. positionGroup: function (group) {
  72671. var model = this.visualMapModel;
  72672. var api = this.api;
  72673. positionElement(
  72674. group,
  72675. model.getBoxLayoutParams(),
  72676. {width: api.getWidth(), height: api.getHeight()}
  72677. );
  72678. },
  72679. /**
  72680. * @protected
  72681. * @abstract
  72682. */
  72683. doRender: noop
  72684. });
  72685. /*
  72686. * Licensed to the Apache Software Foundation (ASF) under one
  72687. * or more contributor license agreements. See the NOTICE file
  72688. * distributed with this work for additional information
  72689. * regarding copyright ownership. The ASF licenses this file
  72690. * to you under the Apache License, Version 2.0 (the
  72691. * "License"); you may not use this file except in compliance
  72692. * with the License. You may obtain a copy of the License at
  72693. *
  72694. * http://www.apache.org/licenses/LICENSE-2.0
  72695. *
  72696. * Unless required by applicable law or agreed to in writing,
  72697. * software distributed under the License is distributed on an
  72698. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72699. * KIND, either express or implied. See the License for the
  72700. * specific language governing permissions and limitations
  72701. * under the License.
  72702. */
  72703. /**
  72704. * @param {module:echarts/component/visualMap/VisualMapModel} visualMapModel\
  72705. * @param {module:echarts/ExtensionAPI} api
  72706. * @param {Array.<number>} itemSize always [short, long]
  72707. * @return {string} 'left' or 'right' or 'top' or 'bottom'
  72708. */
  72709. function getItemAlign(visualMapModel, api, itemSize) {
  72710. var modelOption = visualMapModel.option;
  72711. var itemAlign = modelOption.align;
  72712. if (itemAlign != null && itemAlign !== 'auto') {
  72713. return itemAlign;
  72714. }
  72715. // Auto decision align.
  72716. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  72717. var realIndex = modelOption.orient === 'horizontal' ? 1 : 0;
  72718. var paramsSet = [
  72719. ['left', 'right', 'width'],
  72720. ['top', 'bottom', 'height']
  72721. ];
  72722. var reals = paramsSet[realIndex];
  72723. var fakeValue = [0, null, 10];
  72724. var layoutInput = {};
  72725. for (var i = 0; i < 3; i++) {
  72726. layoutInput[paramsSet[1 - realIndex][i]] = fakeValue[i];
  72727. layoutInput[reals[i]] = i === 2 ? itemSize[0] : modelOption[reals[i]];
  72728. }
  72729. var rParam = [['x', 'width', 3], ['y', 'height', 0]][realIndex];
  72730. var rect = getLayoutRect(layoutInput, ecSize, modelOption.padding);
  72731. return reals[
  72732. (rect.margin[rParam[2]] || 0) + rect[rParam[0]] + rect[rParam[1]] * 0.5
  72733. < ecSize[rParam[1]] * 0.5 ? 0 : 1
  72734. ];
  72735. }
  72736. /**
  72737. * Prepare dataIndex for outside usage, where dataIndex means rawIndex, and
  72738. * dataIndexInside means filtered index.
  72739. */
  72740. function convertDataIndex(batch) {
  72741. each$1(batch || [], function (batchItem) {
  72742. if (batch.dataIndex != null) {
  72743. batch.dataIndexInside = batch.dataIndex;
  72744. batch.dataIndex = null;
  72745. }
  72746. });
  72747. return batch;
  72748. }
  72749. /*
  72750. * Licensed to the Apache Software Foundation (ASF) under one
  72751. * or more contributor license agreements. See the NOTICE file
  72752. * distributed with this work for additional information
  72753. * regarding copyright ownership. The ASF licenses this file
  72754. * to you under the Apache License, Version 2.0 (the
  72755. * "License"); you may not use this file except in compliance
  72756. * with the License. You may obtain a copy of the License at
  72757. *
  72758. * http://www.apache.org/licenses/LICENSE-2.0
  72759. *
  72760. * Unless required by applicable law or agreed to in writing,
  72761. * software distributed under the License is distributed on an
  72762. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72763. * KIND, either express or implied. See the License for the
  72764. * specific language governing permissions and limitations
  72765. * under the License.
  72766. */
  72767. var linearMap$3 = linearMap;
  72768. var each$26 = each$1;
  72769. var mathMin$7 = Math.min;
  72770. var mathMax$7 = Math.max;
  72771. // Arbitrary value
  72772. var HOVER_LINK_SIZE = 12;
  72773. var HOVER_LINK_OUT = 6;
  72774. // Notice:
  72775. // Any "interval" should be by the order of [low, high].
  72776. // "handle0" (handleIndex === 0) maps to
  72777. // low data value: this._dataInterval[0] and has low coord.
  72778. // "handle1" (handleIndex === 1) maps to
  72779. // high data value: this._dataInterval[1] and has high coord.
  72780. // The logic of transform is implemented in this._createBarGroup.
  72781. var ContinuousView = VisualMapView.extend({
  72782. type: 'visualMap.continuous',
  72783. /**
  72784. * @override
  72785. */
  72786. init: function () {
  72787. ContinuousView.superApply(this, 'init', arguments);
  72788. /**
  72789. * @private
  72790. */
  72791. this._shapes = {};
  72792. /**
  72793. * @private
  72794. */
  72795. this._dataInterval = [];
  72796. /**
  72797. * @private
  72798. */
  72799. this._handleEnds = [];
  72800. /**
  72801. * @private
  72802. */
  72803. this._orient;
  72804. /**
  72805. * @private
  72806. */
  72807. this._useHandle;
  72808. /**
  72809. * @private
  72810. */
  72811. this._hoverLinkDataIndices = [];
  72812. /**
  72813. * @private
  72814. */
  72815. this._dragging;
  72816. /**
  72817. * @private
  72818. */
  72819. this._hovering;
  72820. },
  72821. /**
  72822. * @protected
  72823. * @override
  72824. */
  72825. doRender: function (visualMapModel, ecModel, api, payload) {
  72826. if (!payload || payload.type !== 'selectDataRange' || payload.from !== this.uid) {
  72827. this._buildView();
  72828. }
  72829. },
  72830. /**
  72831. * @private
  72832. */
  72833. _buildView: function () {
  72834. this.group.removeAll();
  72835. var visualMapModel = this.visualMapModel;
  72836. var thisGroup = this.group;
  72837. this._orient = visualMapModel.get('orient');
  72838. this._useHandle = visualMapModel.get('calculable');
  72839. this._resetInterval();
  72840. this._renderBar(thisGroup);
  72841. var dataRangeText = visualMapModel.get('text');
  72842. this._renderEndsText(thisGroup, dataRangeText, 0);
  72843. this._renderEndsText(thisGroup, dataRangeText, 1);
  72844. // Do this for background size calculation.
  72845. this._updateView(true);
  72846. // After updating view, inner shapes is built completely,
  72847. // and then background can be rendered.
  72848. this.renderBackground(thisGroup);
  72849. // Real update view
  72850. this._updateView();
  72851. this._enableHoverLinkToSeries();
  72852. this._enableHoverLinkFromSeries();
  72853. this.positionGroup(thisGroup);
  72854. },
  72855. /**
  72856. * @private
  72857. */
  72858. _renderEndsText: function (group, dataRangeText, endsIndex) {
  72859. if (!dataRangeText) {
  72860. return;
  72861. }
  72862. // Compatible with ec2, text[0] map to high value, text[1] map low value.
  72863. var text = dataRangeText[1 - endsIndex];
  72864. text = text != null ? text + '' : '';
  72865. var visualMapModel = this.visualMapModel;
  72866. var textGap = visualMapModel.get('textGap');
  72867. var itemSize = visualMapModel.itemSize;
  72868. var barGroup = this._shapes.barGroup;
  72869. var position = this._applyTransform(
  72870. [
  72871. itemSize[0] / 2,
  72872. endsIndex === 0 ? -textGap : itemSize[1] + textGap
  72873. ],
  72874. barGroup
  72875. );
  72876. var align = this._applyTransform(
  72877. endsIndex === 0 ? 'bottom' : 'top',
  72878. barGroup
  72879. );
  72880. var orient = this._orient;
  72881. var textStyleModel = this.visualMapModel.textStyleModel;
  72882. this.group.add(new Text({
  72883. style: {
  72884. x: position[0],
  72885. y: position[1],
  72886. textVerticalAlign: orient === 'horizontal' ? 'middle' : align,
  72887. textAlign: orient === 'horizontal' ? align : 'center',
  72888. text: text,
  72889. textFont: textStyleModel.getFont(),
  72890. textFill: textStyleModel.getTextColor()
  72891. }
  72892. }));
  72893. },
  72894. /**
  72895. * @private
  72896. */
  72897. _renderBar: function (targetGroup) {
  72898. var visualMapModel = this.visualMapModel;
  72899. var shapes = this._shapes;
  72900. var itemSize = visualMapModel.itemSize;
  72901. var orient = this._orient;
  72902. var useHandle = this._useHandle;
  72903. var itemAlign = getItemAlign(visualMapModel, this.api, itemSize);
  72904. var barGroup = shapes.barGroup = this._createBarGroup(itemAlign);
  72905. // Bar
  72906. barGroup.add(shapes.outOfRange = createPolygon());
  72907. barGroup.add(shapes.inRange = createPolygon(
  72908. null,
  72909. useHandle ? getCursor$1(this._orient) : null,
  72910. bind(this._dragHandle, this, 'all', false),
  72911. bind(this._dragHandle, this, 'all', true)
  72912. ));
  72913. var textRect = visualMapModel.textStyleModel.getTextRect('国');
  72914. var textSize = mathMax$7(textRect.width, textRect.height);
  72915. // Handle
  72916. if (useHandle) {
  72917. shapes.handleThumbs = [];
  72918. shapes.handleLabels = [];
  72919. shapes.handleLabelPoints = [];
  72920. this._createHandle(barGroup, 0, itemSize, textSize, orient, itemAlign);
  72921. this._createHandle(barGroup, 1, itemSize, textSize, orient, itemAlign);
  72922. }
  72923. this._createIndicator(barGroup, itemSize, textSize, orient);
  72924. targetGroup.add(barGroup);
  72925. },
  72926. /**
  72927. * @private
  72928. */
  72929. _createHandle: function (barGroup, handleIndex, itemSize, textSize, orient) {
  72930. var onDrift = bind(this._dragHandle, this, handleIndex, false);
  72931. var onDragEnd = bind(this._dragHandle, this, handleIndex, true);
  72932. var handleThumb = createPolygon(
  72933. createHandlePoints(handleIndex, textSize),
  72934. getCursor$1(this._orient),
  72935. onDrift,
  72936. onDragEnd
  72937. );
  72938. handleThumb.position[0] = itemSize[0];
  72939. barGroup.add(handleThumb);
  72940. // Text is always horizontal layout but should not be effected by
  72941. // transform (orient/inverse). So label is built separately but not
  72942. // use zrender/graphic/helper/RectText, and is located based on view
  72943. // group (according to handleLabelPoint) but not barGroup.
  72944. var textStyleModel = this.visualMapModel.textStyleModel;
  72945. var handleLabel = new Text({
  72946. draggable: true,
  72947. drift: onDrift,
  72948. onmousemove: function (e) {
  72949. // Fot mobile devicem, prevent screen slider on the button.
  72950. stop(e.event);
  72951. },
  72952. ondragend: onDragEnd,
  72953. style: {
  72954. x: 0, y: 0, text: '',
  72955. textFont: textStyleModel.getFont(),
  72956. textFill: textStyleModel.getTextColor()
  72957. }
  72958. });
  72959. this.group.add(handleLabel);
  72960. var handleLabelPoint = [
  72961. orient === 'horizontal'
  72962. ? textSize / 2
  72963. : textSize * 1.5,
  72964. orient === 'horizontal'
  72965. ? (handleIndex === 0 ? -(textSize * 1.5) : (textSize * 1.5))
  72966. : (handleIndex === 0 ? -textSize / 2 : textSize / 2)
  72967. ];
  72968. var shapes = this._shapes;
  72969. shapes.handleThumbs[handleIndex] = handleThumb;
  72970. shapes.handleLabelPoints[handleIndex] = handleLabelPoint;
  72971. shapes.handleLabels[handleIndex] = handleLabel;
  72972. },
  72973. /**
  72974. * @private
  72975. */
  72976. _createIndicator: function (barGroup, itemSize, textSize, orient) {
  72977. var indicator = createPolygon([[0, 0]], 'move');
  72978. indicator.position[0] = itemSize[0];
  72979. indicator.attr({invisible: true, silent: true});
  72980. barGroup.add(indicator);
  72981. var textStyleModel = this.visualMapModel.textStyleModel;
  72982. var indicatorLabel = new Text({
  72983. silent: true,
  72984. invisible: true,
  72985. style: {
  72986. x: 0, y: 0, text: '',
  72987. textFont: textStyleModel.getFont(),
  72988. textFill: textStyleModel.getTextColor()
  72989. }
  72990. });
  72991. this.group.add(indicatorLabel);
  72992. var indicatorLabelPoint = [
  72993. orient === 'horizontal' ? textSize / 2 : HOVER_LINK_OUT + 3,
  72994. 0
  72995. ];
  72996. var shapes = this._shapes;
  72997. shapes.indicator = indicator;
  72998. shapes.indicatorLabel = indicatorLabel;
  72999. shapes.indicatorLabelPoint = indicatorLabelPoint;
  73000. },
  73001. /**
  73002. * @private
  73003. */
  73004. _dragHandle: function (handleIndex, isEnd, dx, dy) {
  73005. if (!this._useHandle) {
  73006. return;
  73007. }
  73008. this._dragging = !isEnd;
  73009. if (!isEnd) {
  73010. // Transform dx, dy to bar coordination.
  73011. var vertex = this._applyTransform([dx, dy], this._shapes.barGroup, true);
  73012. this._updateInterval(handleIndex, vertex[1]);
  73013. // Considering realtime, update view should be executed
  73014. // before dispatch action.
  73015. this._updateView();
  73016. }
  73017. // dragEnd do not dispatch action when realtime.
  73018. if (isEnd === !this.visualMapModel.get('realtime')) { // jshint ignore:line
  73019. this.api.dispatchAction({
  73020. type: 'selectDataRange',
  73021. from: this.uid,
  73022. visualMapId: this.visualMapModel.id,
  73023. selected: this._dataInterval.slice()
  73024. });
  73025. }
  73026. if (isEnd) {
  73027. !this._hovering && this._clearHoverLinkToSeries();
  73028. }
  73029. else if (useHoverLinkOnHandle(this.visualMapModel)) {
  73030. this._doHoverLinkToSeries(this._handleEnds[handleIndex], false);
  73031. }
  73032. },
  73033. /**
  73034. * @private
  73035. */
  73036. _resetInterval: function () {
  73037. var visualMapModel = this.visualMapModel;
  73038. var dataInterval = this._dataInterval = visualMapModel.getSelected();
  73039. var dataExtent = visualMapModel.getExtent();
  73040. var sizeExtent = [0, visualMapModel.itemSize[1]];
  73041. this._handleEnds = [
  73042. linearMap$3(dataInterval[0], dataExtent, sizeExtent, true),
  73043. linearMap$3(dataInterval[1], dataExtent, sizeExtent, true)
  73044. ];
  73045. },
  73046. /**
  73047. * @private
  73048. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  73049. * @param {number} dx
  73050. * @param {number} dy
  73051. */
  73052. _updateInterval: function (handleIndex, delta) {
  73053. delta = delta || 0;
  73054. var visualMapModel = this.visualMapModel;
  73055. var handleEnds = this._handleEnds;
  73056. var sizeExtent = [0, visualMapModel.itemSize[1]];
  73057. sliderMove(
  73058. delta,
  73059. handleEnds,
  73060. sizeExtent,
  73061. handleIndex,
  73062. // cross is forbiden
  73063. 0
  73064. );
  73065. var dataExtent = visualMapModel.getExtent();
  73066. // Update data interval.
  73067. this._dataInterval = [
  73068. linearMap$3(handleEnds[0], sizeExtent, dataExtent, true),
  73069. linearMap$3(handleEnds[1], sizeExtent, dataExtent, true)
  73070. ];
  73071. },
  73072. /**
  73073. * @private
  73074. */
  73075. _updateView: function (forSketch) {
  73076. var visualMapModel = this.visualMapModel;
  73077. var dataExtent = visualMapModel.getExtent();
  73078. var shapes = this._shapes;
  73079. var outOfRangeHandleEnds = [0, visualMapModel.itemSize[1]];
  73080. var inRangeHandleEnds = forSketch ? outOfRangeHandleEnds : this._handleEnds;
  73081. var visualInRange = this._createBarVisual(
  73082. this._dataInterval, dataExtent, inRangeHandleEnds, 'inRange'
  73083. );
  73084. var visualOutOfRange = this._createBarVisual(
  73085. dataExtent, dataExtent, outOfRangeHandleEnds, 'outOfRange'
  73086. );
  73087. shapes.inRange
  73088. .setStyle({
  73089. fill: visualInRange.barColor,
  73090. opacity: visualInRange.opacity
  73091. })
  73092. .setShape('points', visualInRange.barPoints);
  73093. shapes.outOfRange
  73094. .setStyle({
  73095. fill: visualOutOfRange.barColor,
  73096. opacity: visualOutOfRange.opacity
  73097. })
  73098. .setShape('points', visualOutOfRange.barPoints);
  73099. this._updateHandle(inRangeHandleEnds, visualInRange);
  73100. },
  73101. /**
  73102. * @private
  73103. */
  73104. _createBarVisual: function (dataInterval, dataExtent, handleEnds, forceState) {
  73105. var opts = {
  73106. forceState: forceState,
  73107. convertOpacityToAlpha: true
  73108. };
  73109. var colorStops = this._makeColorGradient(dataInterval, opts);
  73110. var symbolSizes = [
  73111. this.getControllerVisual(dataInterval[0], 'symbolSize', opts),
  73112. this.getControllerVisual(dataInterval[1], 'symbolSize', opts)
  73113. ];
  73114. var barPoints = this._createBarPoints(handleEnds, symbolSizes);
  73115. return {
  73116. barColor: new LinearGradient(0, 0, 0, 1, colorStops),
  73117. barPoints: barPoints,
  73118. handlesColor: [
  73119. colorStops[0].color,
  73120. colorStops[colorStops.length - 1].color
  73121. ]
  73122. };
  73123. },
  73124. /**
  73125. * @private
  73126. */
  73127. _makeColorGradient: function (dataInterval, opts) {
  73128. // Considering colorHue, which is not linear, so we have to sample
  73129. // to calculate gradient color stops, but not only caculate head
  73130. // and tail.
  73131. var sampleNumber = 100; // Arbitrary value.
  73132. var colorStops = [];
  73133. var step = (dataInterval[1] - dataInterval[0]) / sampleNumber;
  73134. colorStops.push({
  73135. color: this.getControllerVisual(dataInterval[0], 'color', opts),
  73136. offset: 0
  73137. });
  73138. for (var i = 1; i < sampleNumber; i++) {
  73139. var currValue = dataInterval[0] + step * i;
  73140. if (currValue > dataInterval[1]) {
  73141. break;
  73142. }
  73143. colorStops.push({
  73144. color: this.getControllerVisual(currValue, 'color', opts),
  73145. offset: i / sampleNumber
  73146. });
  73147. }
  73148. colorStops.push({
  73149. color: this.getControllerVisual(dataInterval[1], 'color', opts),
  73150. offset: 1
  73151. });
  73152. return colorStops;
  73153. },
  73154. /**
  73155. * @private
  73156. */
  73157. _createBarPoints: function (handleEnds, symbolSizes) {
  73158. var itemSize = this.visualMapModel.itemSize;
  73159. return [
  73160. [itemSize[0] - symbolSizes[0], handleEnds[0]],
  73161. [itemSize[0], handleEnds[0]],
  73162. [itemSize[0], handleEnds[1]],
  73163. [itemSize[0] - symbolSizes[1], handleEnds[1]]
  73164. ];
  73165. },
  73166. /**
  73167. * @private
  73168. */
  73169. _createBarGroup: function (itemAlign) {
  73170. var orient = this._orient;
  73171. var inverse = this.visualMapModel.get('inverse');
  73172. return new Group(
  73173. (orient === 'horizontal' && !inverse)
  73174. ? {scale: itemAlign === 'bottom' ? [1, 1] : [-1, 1], rotation: Math.PI / 2}
  73175. : (orient === 'horizontal' && inverse)
  73176. ? {scale: itemAlign === 'bottom' ? [-1, 1] : [1, 1], rotation: -Math.PI / 2}
  73177. : (orient === 'vertical' && !inverse)
  73178. ? {scale: itemAlign === 'left' ? [1, -1] : [-1, -1]}
  73179. : {scale: itemAlign === 'left' ? [1, 1] : [-1, 1]}
  73180. );
  73181. },
  73182. /**
  73183. * @private
  73184. */
  73185. _updateHandle: function (handleEnds, visualInRange) {
  73186. if (!this._useHandle) {
  73187. return;
  73188. }
  73189. var shapes = this._shapes;
  73190. var visualMapModel = this.visualMapModel;
  73191. var handleThumbs = shapes.handleThumbs;
  73192. var handleLabels = shapes.handleLabels;
  73193. each$26([0, 1], function (handleIndex) {
  73194. var handleThumb = handleThumbs[handleIndex];
  73195. handleThumb.setStyle('fill', visualInRange.handlesColor[handleIndex]);
  73196. handleThumb.position[1] = handleEnds[handleIndex];
  73197. // Update handle label position.
  73198. var textPoint = applyTransform$1(
  73199. shapes.handleLabelPoints[handleIndex],
  73200. getTransform(handleThumb, this.group)
  73201. );
  73202. handleLabels[handleIndex].setStyle({
  73203. x: textPoint[0],
  73204. y: textPoint[1],
  73205. text: visualMapModel.formatValueText(this._dataInterval[handleIndex]),
  73206. textVerticalAlign: 'middle',
  73207. textAlign: this._applyTransform(
  73208. this._orient === 'horizontal'
  73209. ? (handleIndex === 0 ? 'bottom' : 'top')
  73210. : 'left',
  73211. shapes.barGroup
  73212. )
  73213. });
  73214. }, this);
  73215. },
  73216. /**
  73217. * @private
  73218. * @param {number} cursorValue
  73219. * @param {number} textValue
  73220. * @param {string} [rangeSymbol]
  73221. * @param {number} [halfHoverLinkSize]
  73222. */
  73223. _showIndicator: function (cursorValue, textValue, rangeSymbol, halfHoverLinkSize) {
  73224. var visualMapModel = this.visualMapModel;
  73225. var dataExtent = visualMapModel.getExtent();
  73226. var itemSize = visualMapModel.itemSize;
  73227. var sizeExtent = [0, itemSize[1]];
  73228. var pos = linearMap$3(cursorValue, dataExtent, sizeExtent, true);
  73229. var shapes = this._shapes;
  73230. var indicator = shapes.indicator;
  73231. if (!indicator) {
  73232. return;
  73233. }
  73234. indicator.position[1] = pos;
  73235. indicator.attr('invisible', false);
  73236. indicator.setShape('points', createIndicatorPoints(
  73237. !!rangeSymbol, halfHoverLinkSize, pos, itemSize[1]
  73238. ));
  73239. var opts = {convertOpacityToAlpha: true};
  73240. var color = this.getControllerVisual(cursorValue, 'color', opts);
  73241. indicator.setStyle('fill', color);
  73242. // Update handle label position.
  73243. var textPoint = applyTransform$1(
  73244. shapes.indicatorLabelPoint,
  73245. getTransform(indicator, this.group)
  73246. );
  73247. var indicatorLabel = shapes.indicatorLabel;
  73248. indicatorLabel.attr('invisible', false);
  73249. var align = this._applyTransform('left', shapes.barGroup);
  73250. var orient = this._orient;
  73251. indicatorLabel.setStyle({
  73252. text: (rangeSymbol ? rangeSymbol : '') + visualMapModel.formatValueText(textValue),
  73253. textVerticalAlign: orient === 'horizontal' ? align : 'middle',
  73254. textAlign: orient === 'horizontal' ? 'center' : align,
  73255. x: textPoint[0],
  73256. y: textPoint[1]
  73257. });
  73258. },
  73259. /**
  73260. * @private
  73261. */
  73262. _enableHoverLinkToSeries: function () {
  73263. var self = this;
  73264. this._shapes.barGroup
  73265. .on('mousemove', function (e) {
  73266. self._hovering = true;
  73267. if (!self._dragging) {
  73268. var itemSize = self.visualMapModel.itemSize;
  73269. var pos = self._applyTransform(
  73270. [e.offsetX, e.offsetY], self._shapes.barGroup, true, true
  73271. );
  73272. // For hover link show when hover handle, which might be
  73273. // below or upper than sizeExtent.
  73274. pos[1] = mathMin$7(mathMax$7(0, pos[1]), itemSize[1]);
  73275. self._doHoverLinkToSeries(
  73276. pos[1],
  73277. 0 <= pos[0] && pos[0] <= itemSize[0]
  73278. );
  73279. }
  73280. })
  73281. .on('mouseout', function () {
  73282. // When mouse is out of handle, hoverLink still need
  73283. // to be displayed when realtime is set as false.
  73284. self._hovering = false;
  73285. !self._dragging && self._clearHoverLinkToSeries();
  73286. });
  73287. },
  73288. /**
  73289. * @private
  73290. */
  73291. _enableHoverLinkFromSeries: function () {
  73292. var zr = this.api.getZr();
  73293. if (this.visualMapModel.option.hoverLink) {
  73294. zr.on('mouseover', this._hoverLinkFromSeriesMouseOver, this);
  73295. zr.on('mouseout', this._hideIndicator, this);
  73296. }
  73297. else {
  73298. this._clearHoverLinkFromSeries();
  73299. }
  73300. },
  73301. /**
  73302. * @private
  73303. */
  73304. _doHoverLinkToSeries: function (cursorPos, hoverOnBar) {
  73305. var visualMapModel = this.visualMapModel;
  73306. var itemSize = visualMapModel.itemSize;
  73307. if (!visualMapModel.option.hoverLink) {
  73308. return;
  73309. }
  73310. var sizeExtent = [0, itemSize[1]];
  73311. var dataExtent = visualMapModel.getExtent();
  73312. // For hover link show when hover handle, which might be below or upper than sizeExtent.
  73313. cursorPos = mathMin$7(mathMax$7(sizeExtent[0], cursorPos), sizeExtent[1]);
  73314. var halfHoverLinkSize = getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent);
  73315. var hoverRange = [cursorPos - halfHoverLinkSize, cursorPos + halfHoverLinkSize];
  73316. var cursorValue = linearMap$3(cursorPos, sizeExtent, dataExtent, true);
  73317. var valueRange = [
  73318. linearMap$3(hoverRange[0], sizeExtent, dataExtent, true),
  73319. linearMap$3(hoverRange[1], sizeExtent, dataExtent, true)
  73320. ];
  73321. // Consider data range is out of visualMap range, see test/visualMap-continuous.html,
  73322. // where china and india has very large population.
  73323. hoverRange[0] < sizeExtent[0] && (valueRange[0] = -Infinity);
  73324. hoverRange[1] > sizeExtent[1] && (valueRange[1] = Infinity);
  73325. // Do not show indicator when mouse is over handle,
  73326. // otherwise labels overlap, especially when dragging.
  73327. if (hoverOnBar) {
  73328. if (valueRange[0] === -Infinity) {
  73329. this._showIndicator(cursorValue, valueRange[1], '< ', halfHoverLinkSize);
  73330. }
  73331. else if (valueRange[1] === Infinity) {
  73332. this._showIndicator(cursorValue, valueRange[0], '> ', halfHoverLinkSize);
  73333. }
  73334. else {
  73335. this._showIndicator(cursorValue, cursorValue, '≈ ', halfHoverLinkSize);
  73336. }
  73337. }
  73338. // When realtime is set as false, handles, which are in barGroup,
  73339. // also trigger hoverLink, which help user to realize where they
  73340. // focus on when dragging. (see test/heatmap-large.html)
  73341. // When realtime is set as true, highlight will not show when hover
  73342. // handle, because the label on handle, which displays a exact value
  73343. // but not range, might mislead users.
  73344. var oldBatch = this._hoverLinkDataIndices;
  73345. var newBatch = [];
  73346. if (hoverOnBar || useHoverLinkOnHandle(visualMapModel)) {
  73347. newBatch = this._hoverLinkDataIndices = visualMapModel.findTargetDataIndices(valueRange);
  73348. }
  73349. var resultBatches = compressBatches(oldBatch, newBatch);
  73350. this._dispatchHighDown('downplay', convertDataIndex(resultBatches[0]));
  73351. this._dispatchHighDown('highlight', convertDataIndex(resultBatches[1]));
  73352. },
  73353. /**
  73354. * @private
  73355. */
  73356. _hoverLinkFromSeriesMouseOver: function (e) {
  73357. var el = e.target;
  73358. var visualMapModel = this.visualMapModel;
  73359. if (!el || el.dataIndex == null) {
  73360. return;
  73361. }
  73362. var dataModel = this.ecModel.getSeriesByIndex(el.seriesIndex);
  73363. if (!visualMapModel.isTargetSeries(dataModel)) {
  73364. return;
  73365. }
  73366. var data = dataModel.getData(el.dataType);
  73367. var value = data.get(visualMapModel.getDataDimension(data), el.dataIndex, true);
  73368. if (!isNaN(value)) {
  73369. this._showIndicator(value, value);
  73370. }
  73371. },
  73372. /**
  73373. * @private
  73374. */
  73375. _hideIndicator: function () {
  73376. var shapes = this._shapes;
  73377. shapes.indicator && shapes.indicator.attr('invisible', true);
  73378. shapes.indicatorLabel && shapes.indicatorLabel.attr('invisible', true);
  73379. },
  73380. /**
  73381. * @private
  73382. */
  73383. _clearHoverLinkToSeries: function () {
  73384. this._hideIndicator();
  73385. var indices = this._hoverLinkDataIndices;
  73386. this._dispatchHighDown('downplay', convertDataIndex(indices));
  73387. indices.length = 0;
  73388. },
  73389. /**
  73390. * @private
  73391. */
  73392. _clearHoverLinkFromSeries: function () {
  73393. this._hideIndicator();
  73394. var zr = this.api.getZr();
  73395. zr.off('mouseover', this._hoverLinkFromSeriesMouseOver);
  73396. zr.off('mouseout', this._hideIndicator);
  73397. },
  73398. /**
  73399. * @private
  73400. */
  73401. _applyTransform: function (vertex, element, inverse, global) {
  73402. var transform = getTransform(element, global ? null : this.group);
  73403. return graphic[
  73404. isArray(vertex) ? 'applyTransform' : 'transformDirection'
  73405. ](vertex, transform, inverse);
  73406. },
  73407. /**
  73408. * @private
  73409. */
  73410. _dispatchHighDown: function (type, batch) {
  73411. batch && batch.length && this.api.dispatchAction({
  73412. type: type,
  73413. batch: batch
  73414. });
  73415. },
  73416. /**
  73417. * @override
  73418. */
  73419. dispose: function () {
  73420. this._clearHoverLinkFromSeries();
  73421. this._clearHoverLinkToSeries();
  73422. },
  73423. /**
  73424. * @override
  73425. */
  73426. remove: function () {
  73427. this._clearHoverLinkFromSeries();
  73428. this._clearHoverLinkToSeries();
  73429. }
  73430. });
  73431. function createPolygon(points, cursor, onDrift, onDragEnd) {
  73432. return new Polygon({
  73433. shape: {points: points},
  73434. draggable: !!onDrift,
  73435. cursor: cursor,
  73436. drift: onDrift,
  73437. onmousemove: function (e) {
  73438. // Fot mobile devicem, prevent screen slider on the button.
  73439. stop(e.event);
  73440. },
  73441. ondragend: onDragEnd
  73442. });
  73443. }
  73444. function createHandlePoints(handleIndex, textSize) {
  73445. return handleIndex === 0
  73446. ? [[0, 0], [textSize, 0], [textSize, -textSize]]
  73447. : [[0, 0], [textSize, 0], [textSize, textSize]];
  73448. }
  73449. function createIndicatorPoints(isRange, halfHoverLinkSize, pos, extentMax) {
  73450. return isRange
  73451. ? [ // indicate range
  73452. [0, -mathMin$7(halfHoverLinkSize, mathMax$7(pos, 0))],
  73453. [HOVER_LINK_OUT, 0],
  73454. [0, mathMin$7(halfHoverLinkSize, mathMax$7(extentMax - pos, 0))]
  73455. ]
  73456. : [ // indicate single value
  73457. [0, 0], [5, -5], [5, 5]
  73458. ];
  73459. }
  73460. function getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent) {
  73461. var halfHoverLinkSize = HOVER_LINK_SIZE / 2;
  73462. var hoverLinkDataSize = visualMapModel.get('hoverLinkDataSize');
  73463. if (hoverLinkDataSize) {
  73464. halfHoverLinkSize = linearMap$3(hoverLinkDataSize, dataExtent, sizeExtent, true) / 2;
  73465. }
  73466. return halfHoverLinkSize;
  73467. }
  73468. function useHoverLinkOnHandle(visualMapModel) {
  73469. var hoverLinkOnHandle = visualMapModel.get('hoverLinkOnHandle');
  73470. return !!(hoverLinkOnHandle == null ? visualMapModel.get('realtime') : hoverLinkOnHandle);
  73471. }
  73472. function getCursor$1(orient) {
  73473. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  73474. }
  73475. /*
  73476. * Licensed to the Apache Software Foundation (ASF) under one
  73477. * or more contributor license agreements. See the NOTICE file
  73478. * distributed with this work for additional information
  73479. * regarding copyright ownership. The ASF licenses this file
  73480. * to you under the Apache License, Version 2.0 (the
  73481. * "License"); you may not use this file except in compliance
  73482. * with the License. You may obtain a copy of the License at
  73483. *
  73484. * http://www.apache.org/licenses/LICENSE-2.0
  73485. *
  73486. * Unless required by applicable law or agreed to in writing,
  73487. * software distributed under the License is distributed on an
  73488. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73489. * KIND, either express or implied. See the License for the
  73490. * specific language governing permissions and limitations
  73491. * under the License.
  73492. */
  73493. var actionInfo$2 = {
  73494. type: 'selectDataRange',
  73495. event: 'dataRangeSelected',
  73496. // FIXME use updateView appears wrong
  73497. update: 'update'
  73498. };
  73499. registerAction(actionInfo$2, function (payload, ecModel) {
  73500. ecModel.eachComponent({mainType: 'visualMap', query: payload}, function (model) {
  73501. model.setSelected(payload.selected);
  73502. });
  73503. });
  73504. /*
  73505. * Licensed to the Apache Software Foundation (ASF) under one
  73506. * or more contributor license agreements. See the NOTICE file
  73507. * distributed with this work for additional information
  73508. * regarding copyright ownership. The ASF licenses this file
  73509. * to you under the Apache License, Version 2.0 (the
  73510. * "License"); you may not use this file except in compliance
  73511. * with the License. You may obtain a copy of the License at
  73512. *
  73513. * http://www.apache.org/licenses/LICENSE-2.0
  73514. *
  73515. * Unless required by applicable law or agreed to in writing,
  73516. * software distributed under the License is distributed on an
  73517. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73518. * KIND, either express or implied. See the License for the
  73519. * specific language governing permissions and limitations
  73520. * under the License.
  73521. */
  73522. /**
  73523. * DataZoom component entry
  73524. */
  73525. registerPreprocessor(preprocessor$2);
  73526. /*
  73527. * Licensed to the Apache Software Foundation (ASF) under one
  73528. * or more contributor license agreements. See the NOTICE file
  73529. * distributed with this work for additional information
  73530. * regarding copyright ownership. The ASF licenses this file
  73531. * to you under the Apache License, Version 2.0 (the
  73532. * "License"); you may not use this file except in compliance
  73533. * with the License. You may obtain a copy of the License at
  73534. *
  73535. * http://www.apache.org/licenses/LICENSE-2.0
  73536. *
  73537. * Unless required by applicable law or agreed to in writing,
  73538. * software distributed under the License is distributed on an
  73539. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73540. * KIND, either express or implied. See the License for the
  73541. * specific language governing permissions and limitations
  73542. * under the License.
  73543. */
  73544. var PiecewiseModel = VisualMapModel.extend({
  73545. type: 'visualMap.piecewise',
  73546. /**
  73547. * Order Rule:
  73548. *
  73549. * option.categories / option.pieces / option.text / option.selected:
  73550. * If !option.inverse,
  73551. * Order when vertical: ['top', ..., 'bottom'].
  73552. * Order when horizontal: ['left', ..., 'right'].
  73553. * If option.inverse, the meaning of
  73554. * the order should be reversed.
  73555. *
  73556. * this._pieceList:
  73557. * The order is always [low, ..., high].
  73558. *
  73559. * Mapping from location to low-high:
  73560. * If !option.inverse
  73561. * When vertical, top is high.
  73562. * When horizontal, right is high.
  73563. * If option.inverse, reverse.
  73564. */
  73565. /**
  73566. * @protected
  73567. */
  73568. defaultOption: {
  73569. selected: null, // Object. If not specified, means selected.
  73570. // When pieces and splitNumber: {'0': true, '5': true}
  73571. // When categories: {'cate1': false, 'cate3': true}
  73572. // When selected === false, means all unselected.
  73573. minOpen: false, // Whether include values that smaller than `min`.
  73574. maxOpen: false, // Whether include values that bigger than `max`.
  73575. align: 'auto', // 'auto', 'left', 'right'
  73576. itemWidth: 20, // When put the controller vertically, it is the length of
  73577. // horizontal side of each item. Otherwise, vertical side.
  73578. itemHeight: 14, // When put the controller vertically, it is the length of
  73579. // vertical side of each item. Otherwise, horizontal side.
  73580. itemSymbol: 'roundRect',
  73581. pieceList: null, // Each item is Object, with some of those attrs:
  73582. // {min, max, lt, gt, lte, gte, value,
  73583. // color, colorSaturation, colorAlpha, opacity,
  73584. // symbol, symbolSize}, which customize the range or visual
  73585. // coding of the certain piece. Besides, see "Order Rule".
  73586. categories: null, // category names, like: ['some1', 'some2', 'some3'].
  73587. // Attr min/max are ignored when categories set. See "Order Rule"
  73588. splitNumber: 5, // If set to 5, auto split five pieces equally.
  73589. // If set to 0 and component type not set, component type will be
  73590. // determined as "continuous". (It is less reasonable but for ec2
  73591. // compatibility, see echarts/component/visualMap/typeDefaulter)
  73592. selectedMode: 'multiple', // Can be 'multiple' or 'single'.
  73593. itemGap: 10, // The gap between two items, in px.
  73594. hoverLink: true, // Enable hover highlight.
  73595. showLabel: null // By default, when text is used, label will hide (the logic
  73596. // is remained for compatibility reason)
  73597. },
  73598. /**
  73599. * @override
  73600. */
  73601. optionUpdated: function (newOption, isInit) {
  73602. PiecewiseModel.superApply(this, 'optionUpdated', arguments);
  73603. /**
  73604. * The order is always [low, ..., high].
  73605. * [{text: string, interval: Array.<number>}, ...]
  73606. * @private
  73607. * @type {Array.<Object>}
  73608. */
  73609. this._pieceList = [];
  73610. this.resetExtent();
  73611. /**
  73612. * 'pieces', 'categories', 'splitNumber'
  73613. * @type {string}
  73614. */
  73615. var mode = this._mode = this._determineMode();
  73616. resetMethods[this._mode].call(this);
  73617. this._resetSelected(newOption, isInit);
  73618. var categories = this.option.categories;
  73619. this.resetVisual(function (mappingOption, state) {
  73620. if (mode === 'categories') {
  73621. mappingOption.mappingMethod = 'category';
  73622. mappingOption.categories = clone(categories);
  73623. }
  73624. else {
  73625. mappingOption.dataExtent = this.getExtent();
  73626. mappingOption.mappingMethod = 'piecewise';
  73627. mappingOption.pieceList = map(this._pieceList, function (piece) {
  73628. var piece = clone(piece);
  73629. if (state !== 'inRange') {
  73630. // FIXME
  73631. // outOfRange do not support special visual in pieces.
  73632. piece.visual = null;
  73633. }
  73634. return piece;
  73635. });
  73636. }
  73637. });
  73638. },
  73639. /**
  73640. * @protected
  73641. * @override
  73642. */
  73643. completeVisualOption: function () {
  73644. // Consider this case:
  73645. // visualMap: {
  73646. // pieces: [{symbol: 'circle', lt: 0}, {symbol: 'rect', gte: 0}]
  73647. // }
  73648. // where no inRange/outOfRange set but only pieces. So we should make
  73649. // default inRange/outOfRange for this case, otherwise visuals that only
  73650. // appear in `pieces` will not be taken into account in visual encoding.
  73651. var option = this.option;
  73652. var visualTypesInPieces = {};
  73653. var visualTypes = VisualMapping.listVisualTypes();
  73654. var isCategory = this.isCategory();
  73655. each$1(option.pieces, function (piece) {
  73656. each$1(visualTypes, function (visualType) {
  73657. if (piece.hasOwnProperty(visualType)) {
  73658. visualTypesInPieces[visualType] = 1;
  73659. }
  73660. });
  73661. });
  73662. each$1(visualTypesInPieces, function (v, visualType) {
  73663. var exists = 0;
  73664. each$1(this.stateList, function (state) {
  73665. exists |= has(option, state, visualType)
  73666. || has(option.target, state, visualType);
  73667. }, this);
  73668. !exists && each$1(this.stateList, function (state) {
  73669. (option[state] || (option[state] = {}))[visualType] = visualDefault.get(
  73670. visualType, state === 'inRange' ? 'active' : 'inactive', isCategory
  73671. );
  73672. });
  73673. }, this);
  73674. function has(obj, state, visualType) {
  73675. return obj && obj[state] && (
  73676. isObject$1(obj[state])
  73677. ? obj[state].hasOwnProperty(visualType)
  73678. : obj[state] === visualType // e.g., inRange: 'symbol'
  73679. );
  73680. }
  73681. VisualMapModel.prototype.completeVisualOption.apply(this, arguments);
  73682. },
  73683. _resetSelected: function (newOption, isInit) {
  73684. var thisOption = this.option;
  73685. var pieceList = this._pieceList;
  73686. // Selected do not merge but all override.
  73687. var selected = (isInit ? thisOption : newOption).selected || {};
  73688. thisOption.selected = selected;
  73689. // Consider 'not specified' means true.
  73690. each$1(pieceList, function (piece, index) {
  73691. var key = this.getSelectedMapKey(piece);
  73692. if (!selected.hasOwnProperty(key)) {
  73693. selected[key] = true;
  73694. }
  73695. }, this);
  73696. if (thisOption.selectedMode === 'single') {
  73697. // Ensure there is only one selected.
  73698. var hasSel = false;
  73699. each$1(pieceList, function (piece, index) {
  73700. var key = this.getSelectedMapKey(piece);
  73701. if (selected[key]) {
  73702. hasSel
  73703. ? (selected[key] = false)
  73704. : (hasSel = true);
  73705. }
  73706. }, this);
  73707. }
  73708. // thisOption.selectedMode === 'multiple', default: all selected.
  73709. },
  73710. /**
  73711. * @public
  73712. */
  73713. getSelectedMapKey: function (piece) {
  73714. return this._mode === 'categories'
  73715. ? piece.value + '' : piece.index + '';
  73716. },
  73717. /**
  73718. * @public
  73719. */
  73720. getPieceList: function () {
  73721. return this._pieceList;
  73722. },
  73723. /**
  73724. * @private
  73725. * @return {string}
  73726. */
  73727. _determineMode: function () {
  73728. var option = this.option;
  73729. return option.pieces && option.pieces.length > 0
  73730. ? 'pieces'
  73731. : this.option.categories
  73732. ? 'categories'
  73733. : 'splitNumber';
  73734. },
  73735. /**
  73736. * @public
  73737. * @override
  73738. */
  73739. setSelected: function (selected) {
  73740. this.option.selected = clone(selected);
  73741. },
  73742. /**
  73743. * @public
  73744. * @override
  73745. */
  73746. getValueState: function (value) {
  73747. var index = VisualMapping.findPieceIndex(value, this._pieceList);
  73748. return index != null
  73749. ? (this.option.selected[this.getSelectedMapKey(this._pieceList[index])]
  73750. ? 'inRange' : 'outOfRange'
  73751. )
  73752. : 'outOfRange';
  73753. },
  73754. /**
  73755. * @public
  73756. * @params {number} pieceIndex piece index in visualMapModel.getPieceList()
  73757. * @return {Array.<Object>} [{seriesId, dataIndices: <Array.<number>>}, ...]
  73758. */
  73759. findTargetDataIndices: function (pieceIndex) {
  73760. var result = [];
  73761. this.eachTargetSeries(function (seriesModel) {
  73762. var dataIndices = [];
  73763. var data = seriesModel.getData();
  73764. data.each(this.getDataDimension(data), function (value, dataIndex) {
  73765. // Should always base on model pieceList, because it is order sensitive.
  73766. var pIdx = VisualMapping.findPieceIndex(value, this._pieceList);
  73767. pIdx === pieceIndex && dataIndices.push(dataIndex);
  73768. }, this);
  73769. result.push({seriesId: seriesModel.id, dataIndex: dataIndices});
  73770. }, this);
  73771. return result;
  73772. },
  73773. /**
  73774. * @private
  73775. * @param {Object} piece piece.value or piece.interval is required.
  73776. * @return {number} Can be Infinity or -Infinity
  73777. */
  73778. getRepresentValue: function (piece) {
  73779. var representValue;
  73780. if (this.isCategory()) {
  73781. representValue = piece.value;
  73782. }
  73783. else {
  73784. if (piece.value != null) {
  73785. representValue = piece.value;
  73786. }
  73787. else {
  73788. var pieceInterval = piece.interval || [];
  73789. representValue = (pieceInterval[0] === -Infinity && pieceInterval[1] === Infinity)
  73790. ? 0
  73791. : (pieceInterval[0] + pieceInterval[1]) / 2;
  73792. }
  73793. }
  73794. return representValue;
  73795. },
  73796. getVisualMeta: function (getColorVisual) {
  73797. // Do not support category. (category axis is ordinal, numerical)
  73798. if (this.isCategory()) {
  73799. return;
  73800. }
  73801. var stops = [];
  73802. var outerColors = [];
  73803. var visualMapModel = this;
  73804. function setStop(interval, valueState) {
  73805. var representValue = visualMapModel.getRepresentValue({interval: interval});
  73806. if (!valueState) {
  73807. valueState = visualMapModel.getValueState(representValue);
  73808. }
  73809. var color = getColorVisual(representValue, valueState);
  73810. if (interval[0] === -Infinity) {
  73811. outerColors[0] = color;
  73812. }
  73813. else if (interval[1] === Infinity) {
  73814. outerColors[1] = color;
  73815. }
  73816. else {
  73817. stops.push(
  73818. {value: interval[0], color: color},
  73819. {value: interval[1], color: color}
  73820. );
  73821. }
  73822. }
  73823. // Suplement
  73824. var pieceList = this._pieceList.slice();
  73825. if (!pieceList.length) {
  73826. pieceList.push({interval: [-Infinity, Infinity]});
  73827. }
  73828. else {
  73829. var edge = pieceList[0].interval[0];
  73830. edge !== -Infinity && pieceList.unshift({interval: [-Infinity, edge]});
  73831. edge = pieceList[pieceList.length - 1].interval[1];
  73832. edge !== Infinity && pieceList.push({interval: [edge, Infinity]});
  73833. }
  73834. var curr = -Infinity;
  73835. each$1(pieceList, function (piece) {
  73836. var interval = piece.interval;
  73837. if (interval) {
  73838. // Fulfill gap.
  73839. interval[0] > curr && setStop([curr, interval[0]], 'outOfRange');
  73840. setStop(interval.slice());
  73841. curr = interval[1];
  73842. }
  73843. }, this);
  73844. return {stops: stops, outerColors: outerColors};
  73845. }
  73846. });
  73847. /**
  73848. * Key is this._mode
  73849. * @type {Object}
  73850. * @this {module:echarts/component/viusalMap/PiecewiseMode}
  73851. */
  73852. var resetMethods = {
  73853. splitNumber: function () {
  73854. var thisOption = this.option;
  73855. var pieceList = this._pieceList;
  73856. var precision = Math.min(thisOption.precision, 20);
  73857. var dataExtent = this.getExtent();
  73858. var splitNumber = thisOption.splitNumber;
  73859. splitNumber = Math.max(parseInt(splitNumber, 10), 1);
  73860. thisOption.splitNumber = splitNumber;
  73861. var splitStep = (dataExtent[1] - dataExtent[0]) / splitNumber;
  73862. // Precision auto-adaption
  73863. while (+splitStep.toFixed(precision) !== splitStep && precision < 5) {
  73864. precision++;
  73865. }
  73866. thisOption.precision = precision;
  73867. splitStep = +splitStep.toFixed(precision);
  73868. var index = 0;
  73869. if (thisOption.minOpen) {
  73870. pieceList.push({
  73871. index: index++,
  73872. interval: [-Infinity, dataExtent[0]],
  73873. close: [0, 0]
  73874. });
  73875. }
  73876. for (
  73877. var curr = dataExtent[0], len = index + splitNumber;
  73878. index < len;
  73879. curr += splitStep
  73880. ) {
  73881. var max = index === splitNumber - 1 ? dataExtent[1] : (curr + splitStep);
  73882. pieceList.push({
  73883. index: index++,
  73884. interval: [curr, max],
  73885. close: [1, 1]
  73886. });
  73887. }
  73888. if (thisOption.maxOpen) {
  73889. pieceList.push({
  73890. index: index++,
  73891. interval: [dataExtent[1], Infinity],
  73892. close: [0, 0]
  73893. });
  73894. }
  73895. reformIntervals(pieceList);
  73896. each$1(pieceList, function (piece) {
  73897. piece.text = this.formatValueText(piece.interval);
  73898. }, this);
  73899. },
  73900. categories: function () {
  73901. var thisOption = this.option;
  73902. each$1(thisOption.categories, function (cate) {
  73903. // FIXME category模式也使用pieceList,但在visualMapping中不是使用pieceList。
  73904. // 是否改一致。
  73905. this._pieceList.push({
  73906. text: this.formatValueText(cate, true),
  73907. value: cate
  73908. });
  73909. }, this);
  73910. // See "Order Rule".
  73911. normalizeReverse(thisOption, this._pieceList);
  73912. },
  73913. pieces: function () {
  73914. var thisOption = this.option;
  73915. var pieceList = this._pieceList;
  73916. each$1(thisOption.pieces, function (pieceListItem, index) {
  73917. if (!isObject$1(pieceListItem)) {
  73918. pieceListItem = {value: pieceListItem};
  73919. }
  73920. var item = {text: '', index: index};
  73921. if (pieceListItem.label != null) {
  73922. item.text = pieceListItem.label;
  73923. }
  73924. if (pieceListItem.hasOwnProperty('value')) {
  73925. var value = item.value = pieceListItem.value;
  73926. item.interval = [value, value];
  73927. item.close = [1, 1];
  73928. }
  73929. else {
  73930. // `min` `max` is legacy option.
  73931. // `lt` `gt` `lte` `gte` is recommanded.
  73932. var interval = item.interval = [];
  73933. var close = item.close = [0, 0];
  73934. var closeList = [1, 0, 1];
  73935. var infinityList = [-Infinity, Infinity];
  73936. var useMinMax = [];
  73937. for (var lg = 0; lg < 2; lg++) {
  73938. var names = [['gte', 'gt', 'min'], ['lte', 'lt', 'max']][lg];
  73939. for (var i = 0; i < 3 && interval[lg] == null; i++) {
  73940. interval[lg] = pieceListItem[names[i]];
  73941. close[lg] = closeList[i];
  73942. useMinMax[lg] = i === 2;
  73943. }
  73944. interval[lg] == null && (interval[lg] = infinityList[lg]);
  73945. }
  73946. useMinMax[0] && interval[1] === Infinity && (close[0] = 0);
  73947. useMinMax[1] && interval[0] === -Infinity && (close[1] = 0);
  73948. if (__DEV__) {
  73949. if (interval[0] > interval[1]) {
  73950. console.warn(
  73951. 'Piece ' + index + 'is illegal: ' + interval
  73952. + ' lower bound should not greater then uppper bound.'
  73953. );
  73954. }
  73955. }
  73956. if (interval[0] === interval[1] && close[0] && close[1]) {
  73957. // Consider: [{min: 5, max: 5, visual: {...}}, {min: 0, max: 5}],
  73958. // we use value to lift the priority when min === max
  73959. item.value = interval[0];
  73960. }
  73961. }
  73962. item.visual = VisualMapping.retrieveVisuals(pieceListItem);
  73963. pieceList.push(item);
  73964. }, this);
  73965. // See "Order Rule".
  73966. normalizeReverse(thisOption, pieceList);
  73967. // Only pieces
  73968. reformIntervals(pieceList);
  73969. each$1(pieceList, function (piece) {
  73970. var close = piece.close;
  73971. var edgeSymbols = [['<', '≤'][close[1]], ['>', '≥'][close[0]]];
  73972. piece.text = piece.text || this.formatValueText(
  73973. piece.value != null ? piece.value : piece.interval,
  73974. false,
  73975. edgeSymbols
  73976. );
  73977. }, this);
  73978. }
  73979. };
  73980. function normalizeReverse(thisOption, pieceList) {
  73981. var inverse = thisOption.inverse;
  73982. if (thisOption.orient === 'vertical' ? !inverse : inverse) {
  73983. pieceList.reverse();
  73984. }
  73985. }
  73986. /*
  73987. * Licensed to the Apache Software Foundation (ASF) under one
  73988. * or more contributor license agreements. See the NOTICE file
  73989. * distributed with this work for additional information
  73990. * regarding copyright ownership. The ASF licenses this file
  73991. * to you under the Apache License, Version 2.0 (the
  73992. * "License"); you may not use this file except in compliance
  73993. * with the License. You may obtain a copy of the License at
  73994. *
  73995. * http://www.apache.org/licenses/LICENSE-2.0
  73996. *
  73997. * Unless required by applicable law or agreed to in writing,
  73998. * software distributed under the License is distributed on an
  73999. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74000. * KIND, either express or implied. See the License for the
  74001. * specific language governing permissions and limitations
  74002. * under the License.
  74003. */
  74004. var PiecewiseVisualMapView = VisualMapView.extend({
  74005. type: 'visualMap.piecewise',
  74006. /**
  74007. * @protected
  74008. * @override
  74009. */
  74010. doRender: function () {
  74011. var thisGroup = this.group;
  74012. thisGroup.removeAll();
  74013. var visualMapModel = this.visualMapModel;
  74014. var textGap = visualMapModel.get('textGap');
  74015. var textStyleModel = visualMapModel.textStyleModel;
  74016. var textFont = textStyleModel.getFont();
  74017. var textFill = textStyleModel.getTextColor();
  74018. var itemAlign = this._getItemAlign();
  74019. var itemSize = visualMapModel.itemSize;
  74020. var viewData = this._getViewData();
  74021. var endsText = viewData.endsText;
  74022. var showLabel = retrieve(visualMapModel.get('showLabel', true), !endsText);
  74023. endsText && this._renderEndsText(
  74024. thisGroup, endsText[0], itemSize, showLabel, itemAlign
  74025. );
  74026. each$1(viewData.viewPieceList, renderItem, this);
  74027. endsText && this._renderEndsText(
  74028. thisGroup, endsText[1], itemSize, showLabel, itemAlign
  74029. );
  74030. box(
  74031. visualMapModel.get('orient'), thisGroup, visualMapModel.get('itemGap')
  74032. );
  74033. this.renderBackground(thisGroup);
  74034. this.positionGroup(thisGroup);
  74035. function renderItem(item) {
  74036. var piece = item.piece;
  74037. var itemGroup = new Group();
  74038. itemGroup.onclick = bind(this._onItemClick, this, piece);
  74039. this._enableHoverLink(itemGroup, item.indexInModelPieceList);
  74040. var representValue = visualMapModel.getRepresentValue(piece);
  74041. this._createItemSymbol(
  74042. itemGroup, representValue, [0, 0, itemSize[0], itemSize[1]]
  74043. );
  74044. if (showLabel) {
  74045. var visualState = this.visualMapModel.getValueState(representValue);
  74046. itemGroup.add(new Text({
  74047. style: {
  74048. x: itemAlign === 'right' ? -textGap : itemSize[0] + textGap,
  74049. y: itemSize[1] / 2,
  74050. text: piece.text,
  74051. textVerticalAlign: 'middle',
  74052. textAlign: itemAlign,
  74053. textFont: textFont,
  74054. textFill: textFill,
  74055. opacity: visualState === 'outOfRange' ? 0.5 : 1
  74056. }
  74057. }));
  74058. }
  74059. thisGroup.add(itemGroup);
  74060. }
  74061. },
  74062. /**
  74063. * @private
  74064. */
  74065. _enableHoverLink: function (itemGroup, pieceIndex) {
  74066. itemGroup
  74067. .on('mouseover', bind(onHoverLink, this, 'highlight'))
  74068. .on('mouseout', bind(onHoverLink, this, 'downplay'));
  74069. function onHoverLink(method) {
  74070. var visualMapModel = this.visualMapModel;
  74071. visualMapModel.option.hoverLink && this.api.dispatchAction({
  74072. type: method,
  74073. batch: convertDataIndex(
  74074. visualMapModel.findTargetDataIndices(pieceIndex)
  74075. )
  74076. });
  74077. }
  74078. },
  74079. /**
  74080. * @private
  74081. */
  74082. _getItemAlign: function () {
  74083. var visualMapModel = this.visualMapModel;
  74084. var modelOption = visualMapModel.option;
  74085. if (modelOption.orient === 'vertical') {
  74086. return getItemAlign(
  74087. visualMapModel, this.api, visualMapModel.itemSize
  74088. );
  74089. }
  74090. else { // horizontal, most case left unless specifying right.
  74091. var align = modelOption.align;
  74092. if (!align || align === 'auto') {
  74093. align = 'left';
  74094. }
  74095. return align;
  74096. }
  74097. },
  74098. /**
  74099. * @private
  74100. */
  74101. _renderEndsText: function (group, text, itemSize, showLabel, itemAlign) {
  74102. if (!text) {
  74103. return;
  74104. }
  74105. var itemGroup = new Group();
  74106. var textStyleModel = this.visualMapModel.textStyleModel;
  74107. itemGroup.add(new Text({
  74108. style: {
  74109. x: showLabel ? (itemAlign === 'right' ? itemSize[0] : 0) : itemSize[0] / 2,
  74110. y: itemSize[1] / 2,
  74111. textVerticalAlign: 'middle',
  74112. textAlign: showLabel ? itemAlign : 'center',
  74113. text: text,
  74114. textFont: textStyleModel.getFont(),
  74115. textFill: textStyleModel.getTextColor()
  74116. }
  74117. }));
  74118. group.add(itemGroup);
  74119. },
  74120. /**
  74121. * @private
  74122. * @return {Object} {peiceList, endsText} The order is the same as screen pixel order.
  74123. */
  74124. _getViewData: function () {
  74125. var visualMapModel = this.visualMapModel;
  74126. var viewPieceList = map(visualMapModel.getPieceList(), function (piece, index) {
  74127. return {piece: piece, indexInModelPieceList: index};
  74128. });
  74129. var endsText = visualMapModel.get('text');
  74130. // Consider orient and inverse.
  74131. var orient = visualMapModel.get('orient');
  74132. var inverse = visualMapModel.get('inverse');
  74133. // Order of model pieceList is always [low, ..., high]
  74134. if (orient === 'horizontal' ? inverse : !inverse) {
  74135. viewPieceList.reverse();
  74136. }
  74137. // Origin order of endsText is [high, low]
  74138. else if (endsText) {
  74139. endsText = endsText.slice().reverse();
  74140. }
  74141. return {viewPieceList: viewPieceList, endsText: endsText};
  74142. },
  74143. /**
  74144. * @private
  74145. */
  74146. _createItemSymbol: function (group, representValue, shapeParam) {
  74147. group.add(createSymbol(
  74148. this.getControllerVisual(representValue, 'symbol'),
  74149. shapeParam[0], shapeParam[1], shapeParam[2], shapeParam[3],
  74150. this.getControllerVisual(representValue, 'color')
  74151. ));
  74152. },
  74153. /**
  74154. * @private
  74155. */
  74156. _onItemClick: function (piece) {
  74157. var visualMapModel = this.visualMapModel;
  74158. var option = visualMapModel.option;
  74159. var selected = clone(option.selected);
  74160. var newKey = visualMapModel.getSelectedMapKey(piece);
  74161. if (option.selectedMode === 'single') {
  74162. selected[newKey] = true;
  74163. each$1(selected, function (o, key) {
  74164. selected[key] = key === newKey;
  74165. });
  74166. }
  74167. else {
  74168. selected[newKey] = !selected[newKey];
  74169. }
  74170. this.api.dispatchAction({
  74171. type: 'selectDataRange',
  74172. from: this.uid,
  74173. visualMapId: this.visualMapModel.id,
  74174. selected: selected
  74175. });
  74176. }
  74177. });
  74178. /*
  74179. * Licensed to the Apache Software Foundation (ASF) under one
  74180. * or more contributor license agreements. See the NOTICE file
  74181. * distributed with this work for additional information
  74182. * regarding copyright ownership. The ASF licenses this file
  74183. * to you under the Apache License, Version 2.0 (the
  74184. * "License"); you may not use this file except in compliance
  74185. * with the License. You may obtain a copy of the License at
  74186. *
  74187. * http://www.apache.org/licenses/LICENSE-2.0
  74188. *
  74189. * Unless required by applicable law or agreed to in writing,
  74190. * software distributed under the License is distributed on an
  74191. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74192. * KIND, either express or implied. See the License for the
  74193. * specific language governing permissions and limitations
  74194. * under the License.
  74195. */
  74196. /**
  74197. * DataZoom component entry
  74198. */
  74199. registerPreprocessor(preprocessor$2);
  74200. /*
  74201. * Licensed to the Apache Software Foundation (ASF) under one
  74202. * or more contributor license agreements. See the NOTICE file
  74203. * distributed with this work for additional information
  74204. * regarding copyright ownership. The ASF licenses this file
  74205. * to you under the Apache License, Version 2.0 (the
  74206. * "License"); you may not use this file except in compliance
  74207. * with the License. You may obtain a copy of the License at
  74208. *
  74209. * http://www.apache.org/licenses/LICENSE-2.0
  74210. *
  74211. * Unless required by applicable law or agreed to in writing,
  74212. * software distributed under the License is distributed on an
  74213. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74214. * KIND, either express or implied. See the License for the
  74215. * specific language governing permissions and limitations
  74216. * under the License.
  74217. */
  74218. /**
  74219. * visualMap component entry
  74220. */
  74221. /*
  74222. * Licensed to the Apache Software Foundation (ASF) under one
  74223. * or more contributor license agreements. See the NOTICE file
  74224. * distributed with this work for additional information
  74225. * regarding copyright ownership. The ASF licenses this file
  74226. * to you under the Apache License, Version 2.0 (the
  74227. * "License"); you may not use this file except in compliance
  74228. * with the License. You may obtain a copy of the License at
  74229. *
  74230. * http://www.apache.org/licenses/LICENSE-2.0
  74231. *
  74232. * Unless required by applicable law or agreed to in writing,
  74233. * software distributed under the License is distributed on an
  74234. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74235. * KIND, either express or implied. See the License for the
  74236. * specific language governing permissions and limitations
  74237. * under the License.
  74238. */
  74239. var addCommas$1 = addCommas;
  74240. var encodeHTML$1 = encodeHTML;
  74241. function fillLabel(opt) {
  74242. defaultEmphasis(opt, 'label', ['show']);
  74243. }
  74244. var MarkerModel = extendComponentModel({
  74245. type: 'marker',
  74246. dependencies: ['series', 'grid', 'polar', 'geo'],
  74247. /**
  74248. * @overrite
  74249. */
  74250. init: function (option, parentModel, ecModel, extraOpt) {
  74251. if (__DEV__) {
  74252. if (this.type === 'marker') {
  74253. throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
  74254. }
  74255. }
  74256. this.mergeDefaultAndTheme(option, ecModel);
  74257. this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
  74258. },
  74259. /**
  74260. * @return {boolean}
  74261. */
  74262. isAnimationEnabled: function () {
  74263. if (env$1.node) {
  74264. return false;
  74265. }
  74266. var hostSeries = this.__hostSeries;
  74267. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  74268. },
  74269. mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
  74270. var MarkerModel = this.constructor;
  74271. var modelPropName = this.mainType + 'Model';
  74272. if (!createdBySelf) {
  74273. ecModel.eachSeries(function (seriesModel) {
  74274. var markerOpt = seriesModel.get(this.mainType, true);
  74275. var markerModel = seriesModel[modelPropName];
  74276. if (!markerOpt || !markerOpt.data) {
  74277. seriesModel[modelPropName] = null;
  74278. return;
  74279. }
  74280. if (!markerModel) {
  74281. if (isInit) {
  74282. // Default label emphasis `position` and `show`
  74283. fillLabel(markerOpt);
  74284. }
  74285. each$1(markerOpt.data, function (item) {
  74286. // FIXME Overwrite fillLabel method ?
  74287. if (item instanceof Array) {
  74288. fillLabel(item[0]);
  74289. fillLabel(item[1]);
  74290. }
  74291. else {
  74292. fillLabel(item);
  74293. }
  74294. });
  74295. markerModel = new MarkerModel(
  74296. markerOpt, this, ecModel
  74297. );
  74298. extend(markerModel, {
  74299. mainType: this.mainType,
  74300. // Use the same series index and name
  74301. seriesIndex: seriesModel.seriesIndex,
  74302. name: seriesModel.name,
  74303. createdBySelf: true
  74304. });
  74305. markerModel.__hostSeries = seriesModel;
  74306. }
  74307. else {
  74308. markerModel.mergeOption(markerOpt, ecModel, true);
  74309. }
  74310. seriesModel[modelPropName] = markerModel;
  74311. }, this);
  74312. }
  74313. },
  74314. formatTooltip: function (dataIndex) {
  74315. var data = this.getData();
  74316. var value = this.getRawValue(dataIndex);
  74317. var formattedValue = isArray(value)
  74318. ? map(value, addCommas$1).join(', ') : addCommas$1(value);
  74319. var name = data.getName(dataIndex);
  74320. var html = encodeHTML$1(this.name);
  74321. if (value != null || name) {
  74322. html += '<br />';
  74323. }
  74324. if (name) {
  74325. html += encodeHTML$1(name);
  74326. if (value != null) {
  74327. html += ' : ';
  74328. }
  74329. }
  74330. if (value != null) {
  74331. html += encodeHTML$1(formattedValue);
  74332. }
  74333. return html;
  74334. },
  74335. getData: function () {
  74336. return this._data;
  74337. },
  74338. setData: function (data) {
  74339. this._data = data;
  74340. }
  74341. });
  74342. mixin(MarkerModel, dataFormatMixin);
  74343. /*
  74344. * Licensed to the Apache Software Foundation (ASF) under one
  74345. * or more contributor license agreements. See the NOTICE file
  74346. * distributed with this work for additional information
  74347. * regarding copyright ownership. The ASF licenses this file
  74348. * to you under the Apache License, Version 2.0 (the
  74349. * "License"); you may not use this file except in compliance
  74350. * with the License. You may obtain a copy of the License at
  74351. *
  74352. * http://www.apache.org/licenses/LICENSE-2.0
  74353. *
  74354. * Unless required by applicable law or agreed to in writing,
  74355. * software distributed under the License is distributed on an
  74356. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74357. * KIND, either express or implied. See the License for the
  74358. * specific language governing permissions and limitations
  74359. * under the License.
  74360. */
  74361. MarkerModel.extend({
  74362. type: 'markPoint',
  74363. defaultOption: {
  74364. zlevel: 0,
  74365. z: 5,
  74366. symbol: 'pin',
  74367. symbolSize: 50,
  74368. //symbolRotate: 0,
  74369. //symbolOffset: [0, 0]
  74370. tooltip: {
  74371. trigger: 'item'
  74372. },
  74373. label: {
  74374. show: true,
  74375. position: 'inside'
  74376. },
  74377. itemStyle: {
  74378. borderWidth: 2
  74379. },
  74380. emphasis: {
  74381. label: {
  74382. show: true
  74383. }
  74384. }
  74385. }
  74386. });
  74387. /*
  74388. * Licensed to the Apache Software Foundation (ASF) under one
  74389. * or more contributor license agreements. See the NOTICE file
  74390. * distributed with this work for additional information
  74391. * regarding copyright ownership. The ASF licenses this file
  74392. * to you under the Apache License, Version 2.0 (the
  74393. * "License"); you may not use this file except in compliance
  74394. * with the License. You may obtain a copy of the License at
  74395. *
  74396. * http://www.apache.org/licenses/LICENSE-2.0
  74397. *
  74398. * Unless required by applicable law or agreed to in writing,
  74399. * software distributed under the License is distributed on an
  74400. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74401. * KIND, either express or implied. See the License for the
  74402. * specific language governing permissions and limitations
  74403. * under the License.
  74404. */
  74405. var indexOf$2 = indexOf;
  74406. function hasXOrY(item) {
  74407. return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
  74408. }
  74409. function hasXAndY(item) {
  74410. return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
  74411. }
  74412. // Make it simple, do not visit all stacked value to count precision.
  74413. // function getPrecision(data, valueAxisDim, dataIndex) {
  74414. // var precision = -1;
  74415. // var stackedDim = data.mapDimension(valueAxisDim);
  74416. // do {
  74417. // precision = Math.max(
  74418. // numberUtil.getPrecision(data.get(stackedDim, dataIndex)),
  74419. // precision
  74420. // );
  74421. // var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  74422. // if (stackedOnSeries) {
  74423. // var byValue = data.get(data.getCalculationInfo('stackedByDimension'), dataIndex);
  74424. // data = stackedOnSeries.getData();
  74425. // dataIndex = data.indexOf(data.getCalculationInfo('stackedByDimension'), byValue);
  74426. // stackedDim = data.getCalculationInfo('stackedDimension');
  74427. // }
  74428. // else {
  74429. // data = null;
  74430. // }
  74431. // } while (data);
  74432. // return precision;
  74433. // }
  74434. function markerTypeCalculatorWithExtent(
  74435. mlType, data, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex
  74436. ) {
  74437. var coordArr = [];
  74438. var stacked = isDimensionStacked(data, targetDataDim /*, otherDataDim*/);
  74439. var calcDataDim = stacked
  74440. ? data.getCalculationInfo('stackResultDimension')
  74441. : targetDataDim;
  74442. var value = numCalculate(data, calcDataDim, mlType);
  74443. var dataIndex = data.indicesOfNearest(calcDataDim, value)[0];
  74444. coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex);
  74445. coordArr[targetCoordIndex] = data.get(targetDataDim, dataIndex);
  74446. // Make it simple, do not visit all stacked value to count precision.
  74447. var precision = getPrecision(data.get(targetDataDim, dataIndex));
  74448. precision = Math.min(precision, 20);
  74449. if (precision >= 0) {
  74450. coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
  74451. }
  74452. return coordArr;
  74453. }
  74454. var curry$6 = curry;
  74455. // TODO Specified percent
  74456. var markerTypeCalculator = {
  74457. /**
  74458. * @method
  74459. * @param {module:echarts/data/List} data
  74460. * @param {string} baseAxisDim
  74461. * @param {string} valueAxisDim
  74462. */
  74463. min: curry$6(markerTypeCalculatorWithExtent, 'min'),
  74464. /**
  74465. * @method
  74466. * @param {module:echarts/data/List} data
  74467. * @param {string} baseAxisDim
  74468. * @param {string} valueAxisDim
  74469. */
  74470. max: curry$6(markerTypeCalculatorWithExtent, 'max'),
  74471. /**
  74472. * @method
  74473. * @param {module:echarts/data/List} data
  74474. * @param {string} baseAxisDim
  74475. * @param {string} valueAxisDim
  74476. */
  74477. average: curry$6(markerTypeCalculatorWithExtent, 'average')
  74478. };
  74479. /**
  74480. * Transform markPoint data item to format used in List by do the following
  74481. * 1. Calculate statistic like `max`, `min`, `average`
  74482. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  74483. * @param {module:echarts/model/Series} seriesModel
  74484. * @param {module:echarts/coord/*} [coordSys]
  74485. * @param {Object} item
  74486. * @return {Object}
  74487. */
  74488. function dataTransform(seriesModel, item) {
  74489. var data = seriesModel.getData();
  74490. var coordSys = seriesModel.coordinateSystem;
  74491. // 1. If not specify the position with pixel directly
  74492. // 2. If `coord` is not a data array. Which uses `xAxis`,
  74493. // `yAxis` to specify the coord on each dimension
  74494. // parseFloat first because item.x and item.y can be percent string like '20%'
  74495. if (item && !hasXAndY(item) && !isArray(item.coord) && coordSys) {
  74496. var dims = coordSys.dimensions;
  74497. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  74498. // Clone the option
  74499. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  74500. item = clone(item);
  74501. if (item.type
  74502. && markerTypeCalculator[item.type]
  74503. && axisInfo.baseAxis && axisInfo.valueAxis
  74504. ) {
  74505. var otherCoordIndex = indexOf$2(dims, axisInfo.baseAxis.dim);
  74506. var targetCoordIndex = indexOf$2(dims, axisInfo.valueAxis.dim);
  74507. item.coord = markerTypeCalculator[item.type](
  74508. data, axisInfo.baseDataDim, axisInfo.valueDataDim,
  74509. otherCoordIndex, targetCoordIndex
  74510. );
  74511. // Force to use the value of calculated value.
  74512. item.value = item.coord[targetCoordIndex];
  74513. }
  74514. else {
  74515. // FIXME Only has one of xAxis and yAxis.
  74516. var coord = [
  74517. item.xAxis != null ? item.xAxis : item.radiusAxis,
  74518. item.yAxis != null ? item.yAxis : item.angleAxis
  74519. ];
  74520. // Each coord support max, min, average
  74521. for (var i = 0; i < 2; i++) {
  74522. if (markerTypeCalculator[coord[i]]) {
  74523. coord[i] = numCalculate(data, data.mapDimension(dims[i]), coord[i]);
  74524. }
  74525. }
  74526. item.coord = coord;
  74527. }
  74528. }
  74529. return item;
  74530. }
  74531. function getAxisInfo$1(item, data, coordSys, seriesModel) {
  74532. var ret = {};
  74533. if (item.valueIndex != null || item.valueDim != null) {
  74534. ret.valueDataDim = item.valueIndex != null
  74535. ? data.getDimension(item.valueIndex) : item.valueDim;
  74536. ret.valueAxis = coordSys.getAxis(dataDimToCoordDim(seriesModel, ret.valueDataDim));
  74537. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  74538. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  74539. }
  74540. else {
  74541. ret.baseAxis = seriesModel.getBaseAxis();
  74542. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  74543. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  74544. ret.valueDataDim = data.mapDimension(ret.valueAxis.dim);
  74545. }
  74546. return ret;
  74547. }
  74548. function dataDimToCoordDim(seriesModel, dataDim) {
  74549. var data = seriesModel.getData();
  74550. var dimensions = data.dimensions;
  74551. dataDim = data.getDimension(dataDim);
  74552. for (var i = 0; i < dimensions.length; i++) {
  74553. var dimItem = data.getDimensionInfo(dimensions[i]);
  74554. if (dimItem.name === dataDim) {
  74555. return dimItem.coordDim;
  74556. }
  74557. }
  74558. }
  74559. /**
  74560. * Filter data which is out of coordinateSystem range
  74561. * [dataFilter description]
  74562. * @param {module:echarts/coord/*} [coordSys]
  74563. * @param {Object} item
  74564. * @return {boolean}
  74565. */
  74566. function dataFilter$1(coordSys, item) {
  74567. // Alwalys return true if there is no coordSys
  74568. return (coordSys && coordSys.containData && item.coord && !hasXOrY(item))
  74569. ? coordSys.containData(item.coord) : true;
  74570. }
  74571. function dimValueGetter(item, dimName, dataIndex, dimIndex) {
  74572. // x, y, radius, angle
  74573. if (dimIndex < 2) {
  74574. return item.coord && item.coord[dimIndex];
  74575. }
  74576. return item.value;
  74577. }
  74578. function numCalculate(data, valueDataDim, type) {
  74579. if (type === 'average') {
  74580. var sum = 0;
  74581. var count = 0;
  74582. data.each(valueDataDim, function (val, idx) {
  74583. if (!isNaN(val)) {
  74584. sum += val;
  74585. count++;
  74586. }
  74587. });
  74588. return sum / count;
  74589. }
  74590. else if (type === 'median') {
  74591. return data.getMedian(valueDataDim);
  74592. }
  74593. else {
  74594. // max & min
  74595. return data.getDataExtent(valueDataDim, true)[type === 'max' ? 1 : 0];
  74596. }
  74597. }
  74598. /*
  74599. * Licensed to the Apache Software Foundation (ASF) under one
  74600. * or more contributor license agreements. See the NOTICE file
  74601. * distributed with this work for additional information
  74602. * regarding copyright ownership. The ASF licenses this file
  74603. * to you under the Apache License, Version 2.0 (the
  74604. * "License"); you may not use this file except in compliance
  74605. * with the License. You may obtain a copy of the License at
  74606. *
  74607. * http://www.apache.org/licenses/LICENSE-2.0
  74608. *
  74609. * Unless required by applicable law or agreed to in writing,
  74610. * software distributed under the License is distributed on an
  74611. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74612. * KIND, either express or implied. See the License for the
  74613. * specific language governing permissions and limitations
  74614. * under the License.
  74615. */
  74616. var MarkerView = extendComponentView({
  74617. type: 'marker',
  74618. init: function () {
  74619. /**
  74620. * Markline grouped by series
  74621. * @private
  74622. * @type {module:zrender/core/util.HashMap}
  74623. */
  74624. this.markerGroupMap = createHashMap();
  74625. },
  74626. render: function (markerModel, ecModel, api) {
  74627. var markerGroupMap = this.markerGroupMap;
  74628. markerGroupMap.each(function (item) {
  74629. item.__keep = false;
  74630. });
  74631. var markerModelKey = this.type + 'Model';
  74632. ecModel.eachSeries(function (seriesModel) {
  74633. var markerModel = seriesModel[markerModelKey];
  74634. markerModel && this.renderSeries(seriesModel, markerModel, ecModel, api);
  74635. }, this);
  74636. markerGroupMap.each(function (item) {
  74637. !item.__keep && this.group.remove(item.group);
  74638. }, this);
  74639. },
  74640. renderSeries: function () {}
  74641. });
  74642. /*
  74643. * Licensed to the Apache Software Foundation (ASF) under one
  74644. * or more contributor license agreements. See the NOTICE file
  74645. * distributed with this work for additional information
  74646. * regarding copyright ownership. The ASF licenses this file
  74647. * to you under the Apache License, Version 2.0 (the
  74648. * "License"); you may not use this file except in compliance
  74649. * with the License. You may obtain a copy of the License at
  74650. *
  74651. * http://www.apache.org/licenses/LICENSE-2.0
  74652. *
  74653. * Unless required by applicable law or agreed to in writing,
  74654. * software distributed under the License is distributed on an
  74655. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74656. * KIND, either express or implied. See the License for the
  74657. * specific language governing permissions and limitations
  74658. * under the License.
  74659. */
  74660. function updateMarkerLayout(mpData, seriesModel, api) {
  74661. var coordSys = seriesModel.coordinateSystem;
  74662. mpData.each(function (idx) {
  74663. var itemModel = mpData.getItemModel(idx);
  74664. var point;
  74665. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  74666. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  74667. if (!isNaN(xPx) && !isNaN(yPx)) {
  74668. point = [xPx, yPx];
  74669. }
  74670. // Chart like bar may have there own marker positioning logic
  74671. else if (seriesModel.getMarkerPosition) {
  74672. // Use the getMarkerPoisition
  74673. point = seriesModel.getMarkerPosition(
  74674. mpData.getValues(mpData.dimensions, idx)
  74675. );
  74676. }
  74677. else if (coordSys) {
  74678. var x = mpData.get(coordSys.dimensions[0], idx);
  74679. var y = mpData.get(coordSys.dimensions[1], idx);
  74680. point = coordSys.dataToPoint([x, y]);
  74681. }
  74682. // Use x, y if has any
  74683. if (!isNaN(xPx)) {
  74684. point[0] = xPx;
  74685. }
  74686. if (!isNaN(yPx)) {
  74687. point[1] = yPx;
  74688. }
  74689. mpData.setItemLayout(idx, point);
  74690. });
  74691. }
  74692. MarkerView.extend({
  74693. type: 'markPoint',
  74694. // updateLayout: function (markPointModel, ecModel, api) {
  74695. // ecModel.eachSeries(function (seriesModel) {
  74696. // var mpModel = seriesModel.markPointModel;
  74697. // if (mpModel) {
  74698. // updateMarkerLayout(mpModel.getData(), seriesModel, api);
  74699. // this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
  74700. // }
  74701. // }, this);
  74702. // },
  74703. updateTransform: function (markPointModel, ecModel, api) {
  74704. ecModel.eachSeries(function (seriesModel) {
  74705. var mpModel = seriesModel.markPointModel;
  74706. if (mpModel) {
  74707. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  74708. this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
  74709. }
  74710. }, this);
  74711. },
  74712. renderSeries: function (seriesModel, mpModel, ecModel, api) {
  74713. var coordSys = seriesModel.coordinateSystem;
  74714. var seriesId = seriesModel.id;
  74715. var seriesData = seriesModel.getData();
  74716. var symbolDrawMap = this.markerGroupMap;
  74717. var symbolDraw = symbolDrawMap.get(seriesId)
  74718. || symbolDrawMap.set(seriesId, new SymbolDraw());
  74719. var mpData = createList$1(coordSys, seriesModel, mpModel);
  74720. // FIXME
  74721. mpModel.setData(mpData);
  74722. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  74723. mpData.each(function (idx) {
  74724. var itemModel = mpData.getItemModel(idx);
  74725. var symbolSize = itemModel.getShallow('symbolSize');
  74726. if (typeof symbolSize === 'function') {
  74727. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  74728. symbolSize = symbolSize(
  74729. mpModel.getRawValue(idx), mpModel.getDataParams(idx)
  74730. );
  74731. }
  74732. mpData.setItemVisual(idx, {
  74733. symbolSize: symbolSize,
  74734. color: itemModel.get('itemStyle.color')
  74735. || seriesData.getVisual('color'),
  74736. symbol: itemModel.getShallow('symbol')
  74737. });
  74738. });
  74739. // TODO Text are wrong
  74740. symbolDraw.updateData(mpData);
  74741. this.group.add(symbolDraw.group);
  74742. // Set host model for tooltip
  74743. // FIXME
  74744. mpData.eachItemGraphicEl(function (el) {
  74745. el.traverse(function (child) {
  74746. child.dataModel = mpModel;
  74747. });
  74748. });
  74749. symbolDraw.__keep = true;
  74750. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  74751. }
  74752. });
  74753. /**
  74754. * @inner
  74755. * @param {module:echarts/coord/*} [coordSys]
  74756. * @param {module:echarts/model/Series} seriesModel
  74757. * @param {module:echarts/model/Model} mpModel
  74758. */
  74759. function createList$1(coordSys, seriesModel, mpModel) {
  74760. var coordDimsInfos;
  74761. if (coordSys) {
  74762. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  74763. var info = seriesModel.getData().getDimensionInfo(
  74764. seriesModel.getData().mapDimension(coordDim)
  74765. ) || {};
  74766. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  74767. return defaults({name: coordDim}, info);
  74768. });
  74769. }
  74770. else {
  74771. coordDimsInfos = [{
  74772. name: 'value',
  74773. type: 'float'
  74774. }];
  74775. }
  74776. var mpData = new List(coordDimsInfos, mpModel);
  74777. var dataOpt = map(mpModel.get('data'), curry(
  74778. dataTransform, seriesModel
  74779. ));
  74780. if (coordSys) {
  74781. dataOpt = filter(
  74782. dataOpt, curry(dataFilter$1, coordSys)
  74783. );
  74784. }
  74785. mpData.initData(dataOpt, null,
  74786. coordSys ? dimValueGetter : function (item) {
  74787. return item.value;
  74788. }
  74789. );
  74790. return mpData;
  74791. }
  74792. /*
  74793. * Licensed to the Apache Software Foundation (ASF) under one
  74794. * or more contributor license agreements. See the NOTICE file
  74795. * distributed with this work for additional information
  74796. * regarding copyright ownership. The ASF licenses this file
  74797. * to you under the Apache License, Version 2.0 (the
  74798. * "License"); you may not use this file except in compliance
  74799. * with the License. You may obtain a copy of the License at
  74800. *
  74801. * http://www.apache.org/licenses/LICENSE-2.0
  74802. *
  74803. * Unless required by applicable law or agreed to in writing,
  74804. * software distributed under the License is distributed on an
  74805. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74806. * KIND, either express or implied. See the License for the
  74807. * specific language governing permissions and limitations
  74808. * under the License.
  74809. */
  74810. // HINT Markpoint can't be used too much
  74811. registerPreprocessor(function (opt) {
  74812. // Make sure markPoint component is enabled
  74813. opt.markPoint = opt.markPoint || {};
  74814. });
  74815. /*
  74816. * Licensed to the Apache Software Foundation (ASF) under one
  74817. * or more contributor license agreements. See the NOTICE file
  74818. * distributed with this work for additional information
  74819. * regarding copyright ownership. The ASF licenses this file
  74820. * to you under the Apache License, Version 2.0 (the
  74821. * "License"); you may not use this file except in compliance
  74822. * with the License. You may obtain a copy of the License at
  74823. *
  74824. * http://www.apache.org/licenses/LICENSE-2.0
  74825. *
  74826. * Unless required by applicable law or agreed to in writing,
  74827. * software distributed under the License is distributed on an
  74828. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74829. * KIND, either express or implied. See the License for the
  74830. * specific language governing permissions and limitations
  74831. * under the License.
  74832. */
  74833. MarkerModel.extend({
  74834. type: 'markLine',
  74835. defaultOption: {
  74836. zlevel: 0,
  74837. z: 5,
  74838. symbol: ['circle', 'arrow'],
  74839. symbolSize: [8, 16],
  74840. //symbolRotate: 0,
  74841. precision: 2,
  74842. tooltip: {
  74843. trigger: 'item'
  74844. },
  74845. label: {
  74846. show: true,
  74847. position: 'end'
  74848. },
  74849. lineStyle: {
  74850. type: 'dashed'
  74851. },
  74852. emphasis: {
  74853. label: {
  74854. show: true
  74855. },
  74856. lineStyle: {
  74857. width: 3
  74858. }
  74859. },
  74860. animationEasing: 'linear'
  74861. }
  74862. });
  74863. /*
  74864. * Licensed to the Apache Software Foundation (ASF) under one
  74865. * or more contributor license agreements. See the NOTICE file
  74866. * distributed with this work for additional information
  74867. * regarding copyright ownership. The ASF licenses this file
  74868. * to you under the Apache License, Version 2.0 (the
  74869. * "License"); you may not use this file except in compliance
  74870. * with the License. You may obtain a copy of the License at
  74871. *
  74872. * http://www.apache.org/licenses/LICENSE-2.0
  74873. *
  74874. * Unless required by applicable law or agreed to in writing,
  74875. * software distributed under the License is distributed on an
  74876. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74877. * KIND, either express or implied. See the License for the
  74878. * specific language governing permissions and limitations
  74879. * under the License.
  74880. */
  74881. var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
  74882. var data = seriesModel.getData();
  74883. // Special type markLine like 'min', 'max', 'average', 'median'
  74884. var mlType = item.type;
  74885. if (!isArray(item)
  74886. && (
  74887. mlType === 'min' || mlType === 'max' || mlType === 'average' || mlType === 'median'
  74888. // In case
  74889. // data: [{
  74890. // yAxis: 10
  74891. // }]
  74892. || (item.xAxis != null || item.yAxis != null)
  74893. )
  74894. ) {
  74895. var valueAxis;
  74896. var valueDataDim;
  74897. var value;
  74898. if (item.yAxis != null || item.xAxis != null) {
  74899. valueDataDim = item.yAxis != null ? 'y' : 'x';
  74900. valueAxis = coordSys.getAxis(valueDataDim);
  74901. value = retrieve(item.yAxis, item.xAxis);
  74902. }
  74903. else {
  74904. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  74905. valueDataDim = axisInfo.valueDataDim;
  74906. valueAxis = axisInfo.valueAxis;
  74907. value = numCalculate(data, valueDataDim, mlType);
  74908. }
  74909. var valueIndex = valueDataDim === 'x' ? 0 : 1;
  74910. var baseIndex = 1 - valueIndex;
  74911. var mlFrom = clone(item);
  74912. var mlTo = {};
  74913. mlFrom.type = null;
  74914. mlFrom.coord = [];
  74915. mlTo.coord = [];
  74916. mlFrom.coord[baseIndex] = -Infinity;
  74917. mlTo.coord[baseIndex] = Infinity;
  74918. var precision = mlModel.get('precision');
  74919. if (precision >= 0 && typeof value === 'number') {
  74920. value = +value.toFixed(Math.min(precision, 20));
  74921. }
  74922. mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
  74923. item = [mlFrom, mlTo, { // Extra option for tooltip and label
  74924. type: mlType,
  74925. valueIndex: item.valueIndex,
  74926. // Force to use the value of calculated value.
  74927. value: value
  74928. }];
  74929. }
  74930. item = [
  74931. dataTransform(seriesModel, item[0]),
  74932. dataTransform(seriesModel, item[1]),
  74933. extend({}, item[2])
  74934. ];
  74935. // Avoid line data type is extended by from(to) data type
  74936. item[2].type = item[2].type || '';
  74937. // Merge from option and to option into line option
  74938. merge(item[2], item[0]);
  74939. merge(item[2], item[1]);
  74940. return item;
  74941. };
  74942. function isInifinity(val) {
  74943. return !isNaN(val) && !isFinite(val);
  74944. }
  74945. // If a markLine has one dim
  74946. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  74947. var otherDimIndex = 1 - dimIndex;
  74948. var dimName = coordSys.dimensions[dimIndex];
  74949. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex])
  74950. && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
  74951. }
  74952. function markLineFilter(coordSys, item) {
  74953. if (coordSys.type === 'cartesian2d') {
  74954. var fromCoord = item[0].coord;
  74955. var toCoord = item[1].coord;
  74956. // In case
  74957. // {
  74958. // markLine: {
  74959. // data: [{ yAxis: 2 }]
  74960. // }
  74961. // }
  74962. if (
  74963. fromCoord && toCoord
  74964. && (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys)
  74965. || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))
  74966. ) {
  74967. return true;
  74968. }
  74969. }
  74970. return dataFilter$1(coordSys, item[0])
  74971. && dataFilter$1(coordSys, item[1]);
  74972. }
  74973. function updateSingleMarkerEndLayout(
  74974. data, idx, isFrom, seriesModel, api
  74975. ) {
  74976. var coordSys = seriesModel.coordinateSystem;
  74977. var itemModel = data.getItemModel(idx);
  74978. var point;
  74979. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  74980. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  74981. if (!isNaN(xPx) && !isNaN(yPx)) {
  74982. point = [xPx, yPx];
  74983. }
  74984. else {
  74985. // Chart like bar may have there own marker positioning logic
  74986. if (seriesModel.getMarkerPosition) {
  74987. // Use the getMarkerPoisition
  74988. point = seriesModel.getMarkerPosition(
  74989. data.getValues(data.dimensions, idx)
  74990. );
  74991. }
  74992. else {
  74993. var dims = coordSys.dimensions;
  74994. var x = data.get(dims[0], idx);
  74995. var y = data.get(dims[1], idx);
  74996. point = coordSys.dataToPoint([x, y]);
  74997. }
  74998. // Expand line to the edge of grid if value on one axis is Inifnity
  74999. // In case
  75000. // markLine: {
  75001. // data: [{
  75002. // yAxis: 2
  75003. // // or
  75004. // type: 'average'
  75005. // }]
  75006. // }
  75007. if (coordSys.type === 'cartesian2d') {
  75008. var xAxis = coordSys.getAxis('x');
  75009. var yAxis = coordSys.getAxis('y');
  75010. var dims = coordSys.dimensions;
  75011. if (isInifinity(data.get(dims[0], idx))) {
  75012. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
  75013. }
  75014. else if (isInifinity(data.get(dims[1], idx))) {
  75015. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
  75016. }
  75017. }
  75018. // Use x, y if has any
  75019. if (!isNaN(xPx)) {
  75020. point[0] = xPx;
  75021. }
  75022. if (!isNaN(yPx)) {
  75023. point[1] = yPx;
  75024. }
  75025. }
  75026. data.setItemLayout(idx, point);
  75027. }
  75028. MarkerView.extend({
  75029. type: 'markLine',
  75030. // updateLayout: function (markLineModel, ecModel, api) {
  75031. // ecModel.eachSeries(function (seriesModel) {
  75032. // var mlModel = seriesModel.markLineModel;
  75033. // if (mlModel) {
  75034. // var mlData = mlModel.getData();
  75035. // var fromData = mlModel.__from;
  75036. // var toData = mlModel.__to;
  75037. // // Update visual and layout of from symbol and to symbol
  75038. // fromData.each(function (idx) {
  75039. // updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
  75040. // updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
  75041. // });
  75042. // // Update layout of line
  75043. // mlData.each(function (idx) {
  75044. // mlData.setItemLayout(idx, [
  75045. // fromData.getItemLayout(idx),
  75046. // toData.getItemLayout(idx)
  75047. // ]);
  75048. // });
  75049. // this.markerGroupMap.get(seriesModel.id).updateLayout();
  75050. // }
  75051. // }, this);
  75052. // },
  75053. updateTransform: function (markLineModel, ecModel, api) {
  75054. ecModel.eachSeries(function (seriesModel) {
  75055. var mlModel = seriesModel.markLineModel;
  75056. if (mlModel) {
  75057. var mlData = mlModel.getData();
  75058. var fromData = mlModel.__from;
  75059. var toData = mlModel.__to;
  75060. // Update visual and layout of from symbol and to symbol
  75061. fromData.each(function (idx) {
  75062. updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
  75063. updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
  75064. });
  75065. // Update layout of line
  75066. mlData.each(function (idx) {
  75067. mlData.setItemLayout(idx, [
  75068. fromData.getItemLayout(idx),
  75069. toData.getItemLayout(idx)
  75070. ]);
  75071. });
  75072. this.markerGroupMap.get(seriesModel.id).updateLayout();
  75073. }
  75074. }, this);
  75075. },
  75076. renderSeries: function (seriesModel, mlModel, ecModel, api) {
  75077. var coordSys = seriesModel.coordinateSystem;
  75078. var seriesId = seriesModel.id;
  75079. var seriesData = seriesModel.getData();
  75080. var lineDrawMap = this.markerGroupMap;
  75081. var lineDraw = lineDrawMap.get(seriesId)
  75082. || lineDrawMap.set(seriesId, new LineDraw());
  75083. this.group.add(lineDraw.group);
  75084. var mlData = createList$2(coordSys, seriesModel, mlModel);
  75085. var fromData = mlData.from;
  75086. var toData = mlData.to;
  75087. var lineData = mlData.line;
  75088. mlModel.__from = fromData;
  75089. mlModel.__to = toData;
  75090. // Line data for tooltip and formatter
  75091. mlModel.setData(lineData);
  75092. var symbolType = mlModel.get('symbol');
  75093. var symbolSize = mlModel.get('symbolSize');
  75094. if (!isArray(symbolType)) {
  75095. symbolType = [symbolType, symbolType];
  75096. }
  75097. if (typeof symbolSize === 'number') {
  75098. symbolSize = [symbolSize, symbolSize];
  75099. }
  75100. // Update visual and layout of from symbol and to symbol
  75101. mlData.from.each(function (idx) {
  75102. updateDataVisualAndLayout(fromData, idx, true);
  75103. updateDataVisualAndLayout(toData, idx, false);
  75104. });
  75105. // Update visual and layout of line
  75106. lineData.each(function (idx) {
  75107. var lineColor = lineData.getItemModel(idx).get('lineStyle.color');
  75108. lineData.setItemVisual(idx, {
  75109. color: lineColor || fromData.getItemVisual(idx, 'color')
  75110. });
  75111. lineData.setItemLayout(idx, [
  75112. fromData.getItemLayout(idx),
  75113. toData.getItemLayout(idx)
  75114. ]);
  75115. lineData.setItemVisual(idx, {
  75116. 'fromSymbolSize': fromData.getItemVisual(idx, 'symbolSize'),
  75117. 'fromSymbol': fromData.getItemVisual(idx, 'symbol'),
  75118. 'toSymbolSize': toData.getItemVisual(idx, 'symbolSize'),
  75119. 'toSymbol': toData.getItemVisual(idx, 'symbol')
  75120. });
  75121. });
  75122. lineDraw.updateData(lineData);
  75123. // Set host model for tooltip
  75124. // FIXME
  75125. mlData.line.eachItemGraphicEl(function (el, idx) {
  75126. el.traverse(function (child) {
  75127. child.dataModel = mlModel;
  75128. });
  75129. });
  75130. function updateDataVisualAndLayout(data, idx, isFrom) {
  75131. var itemModel = data.getItemModel(idx);
  75132. updateSingleMarkerEndLayout(
  75133. data, idx, isFrom, seriesModel, api
  75134. );
  75135. data.setItemVisual(idx, {
  75136. symbolSize: itemModel.get('symbolSize') || symbolSize[isFrom ? 0 : 1],
  75137. symbol: itemModel.get('symbol', true) || symbolType[isFrom ? 0 : 1],
  75138. color: itemModel.get('itemStyle.color') || seriesData.getVisual('color')
  75139. });
  75140. }
  75141. lineDraw.__keep = true;
  75142. lineDraw.group.silent = mlModel.get('silent') || seriesModel.get('silent');
  75143. }
  75144. });
  75145. /**
  75146. * @inner
  75147. * @param {module:echarts/coord/*} coordSys
  75148. * @param {module:echarts/model/Series} seriesModel
  75149. * @param {module:echarts/model/Model} mpModel
  75150. */
  75151. function createList$2(coordSys, seriesModel, mlModel) {
  75152. var coordDimsInfos;
  75153. if (coordSys) {
  75154. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  75155. var info = seriesModel.getData().getDimensionInfo(
  75156. seriesModel.getData().mapDimension(coordDim)
  75157. ) || {};
  75158. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  75159. return defaults({name: coordDim}, info);
  75160. });
  75161. }
  75162. else {
  75163. coordDimsInfos = [{
  75164. name: 'value',
  75165. type: 'float'
  75166. }];
  75167. }
  75168. var fromData = new List(coordDimsInfos, mlModel);
  75169. var toData = new List(coordDimsInfos, mlModel);
  75170. // No dimensions
  75171. var lineData = new List([], mlModel);
  75172. var optData = map(mlModel.get('data'), curry(
  75173. markLineTransform, seriesModel, coordSys, mlModel
  75174. ));
  75175. if (coordSys) {
  75176. optData = filter(
  75177. optData, curry(markLineFilter, coordSys)
  75178. );
  75179. }
  75180. var dimValueGetter$$1 = coordSys ? dimValueGetter : function (item) {
  75181. return item.value;
  75182. };
  75183. fromData.initData(
  75184. map(optData, function (item) {
  75185. return item[0];
  75186. }),
  75187. null,
  75188. dimValueGetter$$1
  75189. );
  75190. toData.initData(
  75191. map(optData, function (item) {
  75192. return item[1];
  75193. }),
  75194. null,
  75195. dimValueGetter$$1
  75196. );
  75197. lineData.initData(
  75198. map(optData, function (item) {
  75199. return item[2];
  75200. })
  75201. );
  75202. lineData.hasItemOption = true;
  75203. return {
  75204. from: fromData,
  75205. to: toData,
  75206. line: lineData
  75207. };
  75208. }
  75209. /*
  75210. * Licensed to the Apache Software Foundation (ASF) under one
  75211. * or more contributor license agreements. See the NOTICE file
  75212. * distributed with this work for additional information
  75213. * regarding copyright ownership. The ASF licenses this file
  75214. * to you under the Apache License, Version 2.0 (the
  75215. * "License"); you may not use this file except in compliance
  75216. * with the License. You may obtain a copy of the License at
  75217. *
  75218. * http://www.apache.org/licenses/LICENSE-2.0
  75219. *
  75220. * Unless required by applicable law or agreed to in writing,
  75221. * software distributed under the License is distributed on an
  75222. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75223. * KIND, either express or implied. See the License for the
  75224. * specific language governing permissions and limitations
  75225. * under the License.
  75226. */
  75227. registerPreprocessor(function (opt) {
  75228. // Make sure markLine component is enabled
  75229. opt.markLine = opt.markLine || {};
  75230. });
  75231. /*
  75232. * Licensed to the Apache Software Foundation (ASF) under one
  75233. * or more contributor license agreements. See the NOTICE file
  75234. * distributed with this work for additional information
  75235. * regarding copyright ownership. The ASF licenses this file
  75236. * to you under the Apache License, Version 2.0 (the
  75237. * "License"); you may not use this file except in compliance
  75238. * with the License. You may obtain a copy of the License at
  75239. *
  75240. * http://www.apache.org/licenses/LICENSE-2.0
  75241. *
  75242. * Unless required by applicable law or agreed to in writing,
  75243. * software distributed under the License is distributed on an
  75244. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75245. * KIND, either express or implied. See the License for the
  75246. * specific language governing permissions and limitations
  75247. * under the License.
  75248. */
  75249. MarkerModel.extend({
  75250. type: 'markArea',
  75251. defaultOption: {
  75252. zlevel: 0,
  75253. // PENDING
  75254. z: 1,
  75255. tooltip: {
  75256. trigger: 'item'
  75257. },
  75258. // markArea should fixed on the coordinate system
  75259. animation: false,
  75260. label: {
  75261. show: true,
  75262. position: 'top'
  75263. },
  75264. itemStyle: {
  75265. // color and borderColor default to use color from series
  75266. // color: 'auto'
  75267. // borderColor: 'auto'
  75268. borderWidth: 0
  75269. },
  75270. emphasis: {
  75271. label: {
  75272. show: true,
  75273. position: 'top'
  75274. }
  75275. }
  75276. }
  75277. });
  75278. /*
  75279. * Licensed to the Apache Software Foundation (ASF) under one
  75280. * or more contributor license agreements. See the NOTICE file
  75281. * distributed with this work for additional information
  75282. * regarding copyright ownership. The ASF licenses this file
  75283. * to you under the Apache License, Version 2.0 (the
  75284. * "License"); you may not use this file except in compliance
  75285. * with the License. You may obtain a copy of the License at
  75286. *
  75287. * http://www.apache.org/licenses/LICENSE-2.0
  75288. *
  75289. * Unless required by applicable law or agreed to in writing,
  75290. * software distributed under the License is distributed on an
  75291. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75292. * KIND, either express or implied. See the License for the
  75293. * specific language governing permissions and limitations
  75294. * under the License.
  75295. */
  75296. // TODO Better on polar
  75297. var markAreaTransform = function (seriesModel, coordSys, maModel, item) {
  75298. var lt = dataTransform(seriesModel, item[0]);
  75299. var rb = dataTransform(seriesModel, item[1]);
  75300. var retrieve$$1 = retrieve;
  75301. // FIXME make sure lt is less than rb
  75302. var ltCoord = lt.coord;
  75303. var rbCoord = rb.coord;
  75304. ltCoord[0] = retrieve$$1(ltCoord[0], -Infinity);
  75305. ltCoord[1] = retrieve$$1(ltCoord[1], -Infinity);
  75306. rbCoord[0] = retrieve$$1(rbCoord[0], Infinity);
  75307. rbCoord[1] = retrieve$$1(rbCoord[1], Infinity);
  75308. // Merge option into one
  75309. var result = mergeAll([{}, lt, rb]);
  75310. result.coord = [
  75311. lt.coord, rb.coord
  75312. ];
  75313. result.x0 = lt.x;
  75314. result.y0 = lt.y;
  75315. result.x1 = rb.x;
  75316. result.y1 = rb.y;
  75317. return result;
  75318. };
  75319. function isInifinity$1(val) {
  75320. return !isNaN(val) && !isFinite(val);
  75321. }
  75322. // If a markArea has one dim
  75323. function ifMarkLineHasOnlyDim$1(dimIndex, fromCoord, toCoord, coordSys) {
  75324. var otherDimIndex = 1 - dimIndex;
  75325. return isInifinity$1(fromCoord[otherDimIndex]) && isInifinity$1(toCoord[otherDimIndex]);
  75326. }
  75327. function markAreaFilter(coordSys, item) {
  75328. var fromCoord = item.coord[0];
  75329. var toCoord = item.coord[1];
  75330. if (coordSys.type === 'cartesian2d') {
  75331. // In case
  75332. // {
  75333. // markArea: {
  75334. // data: [{ yAxis: 2 }]
  75335. // }
  75336. // }
  75337. if (
  75338. fromCoord && toCoord
  75339. && (ifMarkLineHasOnlyDim$1(1, fromCoord, toCoord, coordSys)
  75340. || ifMarkLineHasOnlyDim$1(0, fromCoord, toCoord, coordSys))
  75341. ) {
  75342. return true;
  75343. }
  75344. }
  75345. return dataFilter$1(coordSys, {
  75346. coord: fromCoord,
  75347. x: item.x0,
  75348. y: item.y0
  75349. })
  75350. || dataFilter$1(coordSys, {
  75351. coord: toCoord,
  75352. x: item.x1,
  75353. y: item.y1
  75354. });
  75355. }
  75356. // dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
  75357. function getSingleMarkerEndPoint(data, idx, dims, seriesModel, api) {
  75358. var coordSys = seriesModel.coordinateSystem;
  75359. var itemModel = data.getItemModel(idx);
  75360. var point;
  75361. var xPx = parsePercent$1(itemModel.get(dims[0]), api.getWidth());
  75362. var yPx = parsePercent$1(itemModel.get(dims[1]), api.getHeight());
  75363. if (!isNaN(xPx) && !isNaN(yPx)) {
  75364. point = [xPx, yPx];
  75365. }
  75366. else {
  75367. // Chart like bar may have there own marker positioning logic
  75368. if (seriesModel.getMarkerPosition) {
  75369. // Use the getMarkerPoisition
  75370. point = seriesModel.getMarkerPosition(
  75371. data.getValues(dims, idx)
  75372. );
  75373. }
  75374. else {
  75375. var x = data.get(dims[0], idx);
  75376. var y = data.get(dims[1], idx);
  75377. var pt = [x, y];
  75378. coordSys.clampData && coordSys.clampData(pt, pt);
  75379. point = coordSys.dataToPoint(pt, true);
  75380. }
  75381. if (coordSys.type === 'cartesian2d') {
  75382. var xAxis = coordSys.getAxis('x');
  75383. var yAxis = coordSys.getAxis('y');
  75384. var x = data.get(dims[0], idx);
  75385. var y = data.get(dims[1], idx);
  75386. if (isInifinity$1(x)) {
  75387. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[dims[0] === 'x0' ? 0 : 1]);
  75388. }
  75389. else if (isInifinity$1(y)) {
  75390. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[dims[1] === 'y0' ? 0 : 1]);
  75391. }
  75392. }
  75393. // Use x, y if has any
  75394. if (!isNaN(xPx)) {
  75395. point[0] = xPx;
  75396. }
  75397. if (!isNaN(yPx)) {
  75398. point[1] = yPx;
  75399. }
  75400. }
  75401. return point;
  75402. }
  75403. var dimPermutations = [['x0', 'y0'], ['x1', 'y0'], ['x1', 'y1'], ['x0', 'y1']];
  75404. MarkerView.extend({
  75405. type: 'markArea',
  75406. // updateLayout: function (markAreaModel, ecModel, api) {
  75407. // ecModel.eachSeries(function (seriesModel) {
  75408. // var maModel = seriesModel.markAreaModel;
  75409. // if (maModel) {
  75410. // var areaData = maModel.getData();
  75411. // areaData.each(function (idx) {
  75412. // var points = zrUtil.map(dimPermutations, function (dim) {
  75413. // return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  75414. // });
  75415. // // Layout
  75416. // areaData.setItemLayout(idx, points);
  75417. // var el = areaData.getItemGraphicEl(idx);
  75418. // el.setShape('points', points);
  75419. // });
  75420. // }
  75421. // }, this);
  75422. // },
  75423. updateTransform: function (markAreaModel, ecModel, api) {
  75424. ecModel.eachSeries(function (seriesModel) {
  75425. var maModel = seriesModel.markAreaModel;
  75426. if (maModel) {
  75427. var areaData = maModel.getData();
  75428. areaData.each(function (idx) {
  75429. var points = map(dimPermutations, function (dim) {
  75430. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  75431. });
  75432. // Layout
  75433. areaData.setItemLayout(idx, points);
  75434. var el = areaData.getItemGraphicEl(idx);
  75435. el.setShape('points', points);
  75436. });
  75437. }
  75438. }, this);
  75439. },
  75440. renderSeries: function (seriesModel, maModel, ecModel, api) {
  75441. var coordSys = seriesModel.coordinateSystem;
  75442. var seriesId = seriesModel.id;
  75443. var seriesData = seriesModel.getData();
  75444. var areaGroupMap = this.markerGroupMap;
  75445. var polygonGroup = areaGroupMap.get(seriesId)
  75446. || areaGroupMap.set(seriesId, {group: new Group()});
  75447. this.group.add(polygonGroup.group);
  75448. polygonGroup.__keep = true;
  75449. var areaData = createList$3(coordSys, seriesModel, maModel);
  75450. // Line data for tooltip and formatter
  75451. maModel.setData(areaData);
  75452. // Update visual and layout of line
  75453. areaData.each(function (idx) {
  75454. // Layout
  75455. areaData.setItemLayout(idx, map(dimPermutations, function (dim) {
  75456. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  75457. }));
  75458. // Visual
  75459. areaData.setItemVisual(idx, {
  75460. color: seriesData.getVisual('color')
  75461. });
  75462. });
  75463. areaData.diff(polygonGroup.__data)
  75464. .add(function (idx) {
  75465. var polygon = new Polygon({
  75466. shape: {
  75467. points: areaData.getItemLayout(idx)
  75468. }
  75469. });
  75470. areaData.setItemGraphicEl(idx, polygon);
  75471. polygonGroup.group.add(polygon);
  75472. })
  75473. .update(function (newIdx, oldIdx) {
  75474. var polygon = polygonGroup.__data.getItemGraphicEl(oldIdx);
  75475. updateProps(polygon, {
  75476. shape: {
  75477. points: areaData.getItemLayout(newIdx)
  75478. }
  75479. }, maModel, newIdx);
  75480. polygonGroup.group.add(polygon);
  75481. areaData.setItemGraphicEl(newIdx, polygon);
  75482. })
  75483. .remove(function (idx) {
  75484. var polygon = polygonGroup.__data.getItemGraphicEl(idx);
  75485. polygonGroup.group.remove(polygon);
  75486. })
  75487. .execute();
  75488. areaData.eachItemGraphicEl(function (polygon, idx) {
  75489. var itemModel = areaData.getItemModel(idx);
  75490. var labelModel = itemModel.getModel('label');
  75491. var labelHoverModel = itemModel.getModel('emphasis.label');
  75492. var color = areaData.getItemVisual(idx, 'color');
  75493. polygon.useStyle(
  75494. defaults(
  75495. itemModel.getModel('itemStyle').getItemStyle(),
  75496. {
  75497. fill: modifyAlpha(color, 0.4),
  75498. stroke: color
  75499. }
  75500. )
  75501. );
  75502. polygon.hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  75503. setLabelStyle(
  75504. polygon.style, polygon.hoverStyle, labelModel, labelHoverModel,
  75505. {
  75506. labelFetcher: maModel,
  75507. labelDataIndex: idx,
  75508. defaultText: areaData.getName(idx) || '',
  75509. isRectText: true,
  75510. autoColor: color
  75511. }
  75512. );
  75513. setHoverStyle(polygon, {});
  75514. polygon.dataModel = maModel;
  75515. });
  75516. polygonGroup.__data = areaData;
  75517. polygonGroup.group.silent = maModel.get('silent') || seriesModel.get('silent');
  75518. }
  75519. });
  75520. /**
  75521. * @inner
  75522. * @param {module:echarts/coord/*} coordSys
  75523. * @param {module:echarts/model/Series} seriesModel
  75524. * @param {module:echarts/model/Model} mpModel
  75525. */
  75526. function createList$3(coordSys, seriesModel, maModel) {
  75527. var coordDimsInfos;
  75528. var areaData;
  75529. var dims = ['x0', 'y0', 'x1', 'y1'];
  75530. if (coordSys) {
  75531. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  75532. var data = seriesModel.getData();
  75533. var info = data.getDimensionInfo(
  75534. data.mapDimension(coordDim)
  75535. ) || {};
  75536. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  75537. return defaults({name: coordDim}, info);
  75538. });
  75539. areaData = new List(map(dims, function (dim, idx) {
  75540. return {
  75541. name: dim,
  75542. type: coordDimsInfos[idx % 2].type
  75543. };
  75544. }), maModel);
  75545. }
  75546. else {
  75547. coordDimsInfos = [{
  75548. name: 'value',
  75549. type: 'float'
  75550. }];
  75551. areaData = new List(coordDimsInfos, maModel);
  75552. }
  75553. var optData = map(maModel.get('data'), curry(
  75554. markAreaTransform, seriesModel, coordSys, maModel
  75555. ));
  75556. if (coordSys) {
  75557. optData = filter(
  75558. optData, curry(markAreaFilter, coordSys)
  75559. );
  75560. }
  75561. var dimValueGetter$$1 = coordSys ? function (item, dimName, dataIndex, dimIndex) {
  75562. return item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
  75563. } : function (item) {
  75564. return item.value;
  75565. };
  75566. areaData.initData(optData, null, dimValueGetter$$1);
  75567. areaData.hasItemOption = true;
  75568. return areaData;
  75569. }
  75570. /*
  75571. * Licensed to the Apache Software Foundation (ASF) under one
  75572. * or more contributor license agreements. See the NOTICE file
  75573. * distributed with this work for additional information
  75574. * regarding copyright ownership. The ASF licenses this file
  75575. * to you under the Apache License, Version 2.0 (the
  75576. * "License"); you may not use this file except in compliance
  75577. * with the License. You may obtain a copy of the License at
  75578. *
  75579. * http://www.apache.org/licenses/LICENSE-2.0
  75580. *
  75581. * Unless required by applicable law or agreed to in writing,
  75582. * software distributed under the License is distributed on an
  75583. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75584. * KIND, either express or implied. See the License for the
  75585. * specific language governing permissions and limitations
  75586. * under the License.
  75587. */
  75588. registerPreprocessor(function (opt) {
  75589. // Make sure markArea component is enabled
  75590. opt.markArea = opt.markArea || {};
  75591. });
  75592. /*
  75593. * Licensed to the Apache Software Foundation (ASF) under one
  75594. * or more contributor license agreements. See the NOTICE file
  75595. * distributed with this work for additional information
  75596. * regarding copyright ownership. The ASF licenses this file
  75597. * to you under the Apache License, Version 2.0 (the
  75598. * "License"); you may not use this file except in compliance
  75599. * with the License. You may obtain a copy of the License at
  75600. *
  75601. * http://www.apache.org/licenses/LICENSE-2.0
  75602. *
  75603. * Unless required by applicable law or agreed to in writing,
  75604. * software distributed under the License is distributed on an
  75605. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75606. * KIND, either express or implied. See the License for the
  75607. * specific language governing permissions and limitations
  75608. * under the License.
  75609. */
  75610. var preprocessor$3 = function (option) {
  75611. var timelineOpt = option && option.timeline;
  75612. if (!isArray(timelineOpt)) {
  75613. timelineOpt = timelineOpt ? [timelineOpt] : [];
  75614. }
  75615. each$1(timelineOpt, function (opt) {
  75616. if (!opt) {
  75617. return;
  75618. }
  75619. compatibleEC2(opt);
  75620. });
  75621. };
  75622. function compatibleEC2(opt) {
  75623. var type = opt.type;
  75624. var ec2Types = {'number': 'value', 'time': 'time'};
  75625. // Compatible with ec2
  75626. if (ec2Types[type]) {
  75627. opt.axisType = ec2Types[type];
  75628. delete opt.type;
  75629. }
  75630. transferItem(opt);
  75631. if (has$2(opt, 'controlPosition')) {
  75632. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  75633. if (!has$2(controlStyle, 'position')) {
  75634. controlStyle.position = opt.controlPosition;
  75635. }
  75636. if (controlStyle.position === 'none' && !has$2(controlStyle, 'show')) {
  75637. controlStyle.show = false;
  75638. delete controlStyle.position;
  75639. }
  75640. delete opt.controlPosition;
  75641. }
  75642. each$1(opt.data || [], function (dataItem) {
  75643. if (isObject$1(dataItem) && !isArray(dataItem)) {
  75644. if (!has$2(dataItem, 'value') && has$2(dataItem, 'name')) {
  75645. // In ec2, using name as value.
  75646. dataItem.value = dataItem.name;
  75647. }
  75648. transferItem(dataItem);
  75649. }
  75650. });
  75651. }
  75652. function transferItem(opt) {
  75653. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  75654. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {});
  75655. // Transfer label out
  75656. var label = opt.label || (opt.label || {});
  75657. var labelNormal = label.normal || (label.normal = {});
  75658. var excludeLabelAttr = {normal: 1, emphasis: 1};
  75659. each$1(label, function (value, name) {
  75660. if (!excludeLabelAttr[name] && !has$2(labelNormal, name)) {
  75661. labelNormal[name] = value;
  75662. }
  75663. });
  75664. if (itemStyleEmphasis.label && !has$2(label, 'emphasis')) {
  75665. label.emphasis = itemStyleEmphasis.label;
  75666. delete itemStyleEmphasis.label;
  75667. }
  75668. }
  75669. function has$2(obj, attr) {
  75670. return obj.hasOwnProperty(attr);
  75671. }
  75672. /*
  75673. * Licensed to the Apache Software Foundation (ASF) under one
  75674. * or more contributor license agreements. See the NOTICE file
  75675. * distributed with this work for additional information
  75676. * regarding copyright ownership. The ASF licenses this file
  75677. * to you under the Apache License, Version 2.0 (the
  75678. * "License"); you may not use this file except in compliance
  75679. * with the License. You may obtain a copy of the License at
  75680. *
  75681. * http://www.apache.org/licenses/LICENSE-2.0
  75682. *
  75683. * Unless required by applicable law or agreed to in writing,
  75684. * software distributed under the License is distributed on an
  75685. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75686. * KIND, either express or implied. See the License for the
  75687. * specific language governing permissions and limitations
  75688. * under the License.
  75689. */
  75690. ComponentModel.registerSubTypeDefaulter('timeline', function () {
  75691. // Only slider now.
  75692. return 'slider';
  75693. });
  75694. /*
  75695. * Licensed to the Apache Software Foundation (ASF) under one
  75696. * or more contributor license agreements. See the NOTICE file
  75697. * distributed with this work for additional information
  75698. * regarding copyright ownership. The ASF licenses this file
  75699. * to you under the Apache License, Version 2.0 (the
  75700. * "License"); you may not use this file except in compliance
  75701. * with the License. You may obtain a copy of the License at
  75702. *
  75703. * http://www.apache.org/licenses/LICENSE-2.0
  75704. *
  75705. * Unless required by applicable law or agreed to in writing,
  75706. * software distributed under the License is distributed on an
  75707. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75708. * KIND, either express or implied. See the License for the
  75709. * specific language governing permissions and limitations
  75710. * under the License.
  75711. */
  75712. registerAction(
  75713. {type: 'timelineChange', event: 'timelineChanged', update: 'prepareAndUpdate'},
  75714. function (payload, ecModel) {
  75715. var timelineModel = ecModel.getComponent('timeline');
  75716. if (timelineModel && payload.currentIndex != null) {
  75717. timelineModel.setCurrentIndex(payload.currentIndex);
  75718. if (!timelineModel.get('loop', true) && timelineModel.isIndexMax()) {
  75719. timelineModel.setPlayState(false);
  75720. }
  75721. }
  75722. // Set normalized currentIndex to payload.
  75723. ecModel.resetOption('timeline');
  75724. return defaults({
  75725. currentIndex: timelineModel.option.currentIndex
  75726. }, payload);
  75727. }
  75728. );
  75729. registerAction(
  75730. {type: 'timelinePlayChange', event: 'timelinePlayChanged', update: 'update'},
  75731. function (payload, ecModel) {
  75732. var timelineModel = ecModel.getComponent('timeline');
  75733. if (timelineModel && payload.playState != null) {
  75734. timelineModel.setPlayState(payload.playState);
  75735. }
  75736. }
  75737. );
  75738. /*
  75739. * Licensed to the Apache Software Foundation (ASF) under one
  75740. * or more contributor license agreements. See the NOTICE file
  75741. * distributed with this work for additional information
  75742. * regarding copyright ownership. The ASF licenses this file
  75743. * to you under the Apache License, Version 2.0 (the
  75744. * "License"); you may not use this file except in compliance
  75745. * with the License. You may obtain a copy of the License at
  75746. *
  75747. * http://www.apache.org/licenses/LICENSE-2.0
  75748. *
  75749. * Unless required by applicable law or agreed to in writing,
  75750. * software distributed under the License is distributed on an
  75751. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75752. * KIND, either express or implied. See the License for the
  75753. * specific language governing permissions and limitations
  75754. * under the License.
  75755. */
  75756. var TimelineModel = ComponentModel.extend({
  75757. type: 'timeline',
  75758. layoutMode: 'box',
  75759. /**
  75760. * @protected
  75761. */
  75762. defaultOption: {
  75763. zlevel: 0, // 一级层叠
  75764. z: 4, // 二级层叠
  75765. show: true,
  75766. axisType: 'time', // 模式是时间类型,支持 value, category
  75767. realtime: true,
  75768. left: '20%',
  75769. top: null,
  75770. right: '20%',
  75771. bottom: 0,
  75772. width: null,
  75773. height: 40,
  75774. padding: 5,
  75775. controlPosition: 'left', // 'left' 'right' 'top' 'bottom' 'none'
  75776. autoPlay: false,
  75777. rewind: false, // 反向播放
  75778. loop: true,
  75779. playInterval: 2000, // 播放时间间隔,单位ms
  75780. currentIndex: 0,
  75781. itemStyle: {},
  75782. label: {
  75783. color: '#000'
  75784. },
  75785. data: []
  75786. },
  75787. /**
  75788. * @override
  75789. */
  75790. init: function (option, parentModel, ecModel) {
  75791. /**
  75792. * @private
  75793. * @type {module:echarts/data/List}
  75794. */
  75795. this._data;
  75796. /**
  75797. * @private
  75798. * @type {Array.<string>}
  75799. */
  75800. this._names;
  75801. this.mergeDefaultAndTheme(option, ecModel);
  75802. this._initData();
  75803. },
  75804. /**
  75805. * @override
  75806. */
  75807. mergeOption: function (option) {
  75808. TimelineModel.superApply(this, 'mergeOption', arguments);
  75809. this._initData();
  75810. },
  75811. /**
  75812. * @param {number} [currentIndex]
  75813. */
  75814. setCurrentIndex: function (currentIndex) {
  75815. if (currentIndex == null) {
  75816. currentIndex = this.option.currentIndex;
  75817. }
  75818. var count = this._data.count();
  75819. if (this.option.loop) {
  75820. currentIndex = (currentIndex % count + count) % count;
  75821. }
  75822. else {
  75823. currentIndex >= count && (currentIndex = count - 1);
  75824. currentIndex < 0 && (currentIndex = 0);
  75825. }
  75826. this.option.currentIndex = currentIndex;
  75827. },
  75828. /**
  75829. * @return {number} currentIndex
  75830. */
  75831. getCurrentIndex: function () {
  75832. return this.option.currentIndex;
  75833. },
  75834. /**
  75835. * @return {boolean}
  75836. */
  75837. isIndexMax: function () {
  75838. return this.getCurrentIndex() >= this._data.count() - 1;
  75839. },
  75840. /**
  75841. * @param {boolean} state true: play, false: stop
  75842. */
  75843. setPlayState: function (state) {
  75844. this.option.autoPlay = !!state;
  75845. },
  75846. /**
  75847. * @return {boolean} true: play, false: stop
  75848. */
  75849. getPlayState: function () {
  75850. return !!this.option.autoPlay;
  75851. },
  75852. /**
  75853. * @private
  75854. */
  75855. _initData: function () {
  75856. var thisOption = this.option;
  75857. var dataArr = thisOption.data || [];
  75858. var axisType = thisOption.axisType;
  75859. var names = this._names = [];
  75860. if (axisType === 'category') {
  75861. var idxArr = [];
  75862. each$1(dataArr, function (item, index) {
  75863. var value = getDataItemValue(item);
  75864. var newItem;
  75865. if (isObject$1(item)) {
  75866. newItem = clone(item);
  75867. newItem.value = index;
  75868. }
  75869. else {
  75870. newItem = index;
  75871. }
  75872. idxArr.push(newItem);
  75873. if (!isString(value) && (value == null || isNaN(value))) {
  75874. value = '';
  75875. }
  75876. names.push(value + '');
  75877. });
  75878. dataArr = idxArr;
  75879. }
  75880. var dimType = ({category: 'ordinal', time: 'time'})[axisType] || 'number';
  75881. var data = this._data = new List([{name: 'value', type: dimType}], this);
  75882. data.initData(dataArr, names);
  75883. },
  75884. getData: function () {
  75885. return this._data;
  75886. },
  75887. /**
  75888. * @public
  75889. * @return {Array.<string>} categoreis
  75890. */
  75891. getCategories: function () {
  75892. if (this.get('axisType') === 'category') {
  75893. return this._names.slice();
  75894. }
  75895. }
  75896. });
  75897. /*
  75898. * Licensed to the Apache Software Foundation (ASF) under one
  75899. * or more contributor license agreements. See the NOTICE file
  75900. * distributed with this work for additional information
  75901. * regarding copyright ownership. The ASF licenses this file
  75902. * to you under the Apache License, Version 2.0 (the
  75903. * "License"); you may not use this file except in compliance
  75904. * with the License. You may obtain a copy of the License at
  75905. *
  75906. * http://www.apache.org/licenses/LICENSE-2.0
  75907. *
  75908. * Unless required by applicable law or agreed to in writing,
  75909. * software distributed under the License is distributed on an
  75910. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75911. * KIND, either express or implied. See the License for the
  75912. * specific language governing permissions and limitations
  75913. * under the License.
  75914. */
  75915. var SliderTimelineModel = TimelineModel.extend({
  75916. type: 'timeline.slider',
  75917. /**
  75918. * @protected
  75919. */
  75920. defaultOption: {
  75921. backgroundColor: 'rgba(0,0,0,0)', // 时间轴背景颜色
  75922. borderColor: '#ccc', // 时间轴边框颜色
  75923. borderWidth: 0, // 时间轴边框线宽,单位px,默认为0(无边框)
  75924. orient: 'horizontal', // 'vertical'
  75925. inverse: false,
  75926. tooltip: { // boolean or Object
  75927. trigger: 'item' // data item may also have tootip attr.
  75928. },
  75929. symbol: 'emptyCircle',
  75930. symbolSize: 10,
  75931. lineStyle: {
  75932. show: true,
  75933. width: 2,
  75934. color: '#304654'
  75935. },
  75936. label: { // 文本标签
  75937. position: 'auto', // auto left right top bottom
  75938. // When using number, label position is not
  75939. // restricted by viewRect.
  75940. // positive: right/bottom, negative: left/top
  75941. show: true,
  75942. interval: 'auto',
  75943. rotate: 0,
  75944. // formatter: null,
  75945. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  75946. color: '#304654'
  75947. },
  75948. itemStyle: {
  75949. color: '#304654',
  75950. borderWidth: 1
  75951. },
  75952. checkpointStyle: {
  75953. symbol: 'circle',
  75954. symbolSize: 13,
  75955. color: '#c23531',
  75956. borderWidth: 5,
  75957. borderColor: 'rgba(194,53,49, 0.5)',
  75958. animation: true,
  75959. animationDuration: 300,
  75960. animationEasing: 'quinticInOut'
  75961. },
  75962. controlStyle: {
  75963. show: true,
  75964. showPlayBtn: true,
  75965. showPrevBtn: true,
  75966. showNextBtn: true,
  75967. itemSize: 22,
  75968. itemGap: 12,
  75969. position: 'left', // 'left' 'right' 'top' 'bottom'
  75970. 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', // jshint ignore:line
  75971. 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', // jshint ignore:line
  75972. 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', // jshint ignore:line
  75973. 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', // jshint ignore:line
  75974. color: '#304654',
  75975. borderColor: '#304654',
  75976. borderWidth: 1
  75977. },
  75978. emphasis: {
  75979. label: {
  75980. show: true,
  75981. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  75982. color: '#c23531'
  75983. },
  75984. itemStyle: {
  75985. color: '#c23531'
  75986. },
  75987. controlStyle: {
  75988. color: '#c23531',
  75989. borderColor: '#c23531',
  75990. borderWidth: 2
  75991. }
  75992. },
  75993. data: []
  75994. }
  75995. });
  75996. mixin(SliderTimelineModel, dataFormatMixin);
  75997. /*
  75998. * Licensed to the Apache Software Foundation (ASF) under one
  75999. * or more contributor license agreements. See the NOTICE file
  76000. * distributed with this work for additional information
  76001. * regarding copyright ownership. The ASF licenses this file
  76002. * to you under the Apache License, Version 2.0 (the
  76003. * "License"); you may not use this file except in compliance
  76004. * with the License. You may obtain a copy of the License at
  76005. *
  76006. * http://www.apache.org/licenses/LICENSE-2.0
  76007. *
  76008. * Unless required by applicable law or agreed to in writing,
  76009. * software distributed under the License is distributed on an
  76010. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76011. * KIND, either express or implied. See the License for the
  76012. * specific language governing permissions and limitations
  76013. * under the License.
  76014. */
  76015. var TimelineView = Component.extend({
  76016. type: 'timeline'
  76017. });
  76018. /*
  76019. * Licensed to the Apache Software Foundation (ASF) under one
  76020. * or more contributor license agreements. See the NOTICE file
  76021. * distributed with this work for additional information
  76022. * regarding copyright ownership. The ASF licenses this file
  76023. * to you under the Apache License, Version 2.0 (the
  76024. * "License"); you may not use this file except in compliance
  76025. * with the License. You may obtain a copy of the License at
  76026. *
  76027. * http://www.apache.org/licenses/LICENSE-2.0
  76028. *
  76029. * Unless required by applicable law or agreed to in writing,
  76030. * software distributed under the License is distributed on an
  76031. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76032. * KIND, either express or implied. See the License for the
  76033. * specific language governing permissions and limitations
  76034. * under the License.
  76035. */
  76036. /**
  76037. * Extend axis 2d
  76038. * @constructor module:echarts/coord/cartesian/Axis2D
  76039. * @extends {module:echarts/coord/cartesian/Axis}
  76040. * @param {string} dim
  76041. * @param {*} scale
  76042. * @param {Array.<number>} coordExtent
  76043. * @param {string} axisType
  76044. * @param {string} position
  76045. */
  76046. var TimelineAxis = function (dim, scale, coordExtent, axisType) {
  76047. Axis.call(this, dim, scale, coordExtent);
  76048. /**
  76049. * Axis type
  76050. * - 'category'
  76051. * - 'value'
  76052. * - 'time'
  76053. * - 'log'
  76054. * @type {string}
  76055. */
  76056. this.type = axisType || 'value';
  76057. /**
  76058. * Axis model
  76059. * @param {module:echarts/component/TimelineModel}
  76060. */
  76061. this.model = null;
  76062. };
  76063. TimelineAxis.prototype = {
  76064. constructor: TimelineAxis,
  76065. /**
  76066. * @override
  76067. */
  76068. getLabelModel: function () {
  76069. return this.model.getModel('label');
  76070. },
  76071. /**
  76072. * @override
  76073. */
  76074. isHorizontal: function () {
  76075. return this.model.get('orient') === 'horizontal';
  76076. }
  76077. };
  76078. inherits(TimelineAxis, Axis);
  76079. /*
  76080. * Licensed to the Apache Software Foundation (ASF) under one
  76081. * or more contributor license agreements. See the NOTICE file
  76082. * distributed with this work for additional information
  76083. * regarding copyright ownership. The ASF licenses this file
  76084. * to you under the Apache License, Version 2.0 (the
  76085. * "License"); you may not use this file except in compliance
  76086. * with the License. You may obtain a copy of the License at
  76087. *
  76088. * http://www.apache.org/licenses/LICENSE-2.0
  76089. *
  76090. * Unless required by applicable law or agreed to in writing,
  76091. * software distributed under the License is distributed on an
  76092. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76093. * KIND, either express or implied. See the License for the
  76094. * specific language governing permissions and limitations
  76095. * under the License.
  76096. */
  76097. var bind$6 = bind;
  76098. var each$27 = each$1;
  76099. var PI$4 = Math.PI;
  76100. TimelineView.extend({
  76101. type: 'timeline.slider',
  76102. init: function (ecModel, api) {
  76103. this.api = api;
  76104. /**
  76105. * @private
  76106. * @type {module:echarts/component/timeline/TimelineAxis}
  76107. */
  76108. this._axis;
  76109. /**
  76110. * @private
  76111. * @type {module:zrender/core/BoundingRect}
  76112. */
  76113. this._viewRect;
  76114. /**
  76115. * @type {number}
  76116. */
  76117. this._timer;
  76118. /**
  76119. * @type {module:zrender/Element}
  76120. */
  76121. this._currentPointer;
  76122. /**
  76123. * @type {module:zrender/container/Group}
  76124. */
  76125. this._mainGroup;
  76126. /**
  76127. * @type {module:zrender/container/Group}
  76128. */
  76129. this._labelGroup;
  76130. },
  76131. /**
  76132. * @override
  76133. */
  76134. render: function (timelineModel, ecModel, api, payload) {
  76135. this.model = timelineModel;
  76136. this.api = api;
  76137. this.ecModel = ecModel;
  76138. this.group.removeAll();
  76139. if (timelineModel.get('show', true)) {
  76140. var layoutInfo = this._layout(timelineModel, api);
  76141. var mainGroup = this._createGroup('mainGroup');
  76142. var labelGroup = this._createGroup('labelGroup');
  76143. /**
  76144. * @private
  76145. * @type {module:echarts/component/timeline/TimelineAxis}
  76146. */
  76147. var axis = this._axis = this._createAxis(layoutInfo, timelineModel);
  76148. timelineModel.formatTooltip = function (dataIndex) {
  76149. return encodeHTML(axis.scale.getLabel(dataIndex));
  76150. };
  76151. each$27(
  76152. ['AxisLine', 'AxisTick', 'Control', 'CurrentPointer'],
  76153. function (name) {
  76154. this['_render' + name](layoutInfo, mainGroup, axis, timelineModel);
  76155. },
  76156. this
  76157. );
  76158. this._renderAxisLabel(layoutInfo, labelGroup, axis, timelineModel);
  76159. this._position(layoutInfo, timelineModel);
  76160. }
  76161. this._doPlayStop();
  76162. },
  76163. /**
  76164. * @override
  76165. */
  76166. remove: function () {
  76167. this._clearTimer();
  76168. this.group.removeAll();
  76169. },
  76170. /**
  76171. * @override
  76172. */
  76173. dispose: function () {
  76174. this._clearTimer();
  76175. },
  76176. _layout: function (timelineModel, api) {
  76177. var labelPosOpt = timelineModel.get('label.position');
  76178. var orient = timelineModel.get('orient');
  76179. var viewRect = getViewRect$4(timelineModel, api);
  76180. // Auto label offset.
  76181. if (labelPosOpt == null || labelPosOpt === 'auto') {
  76182. labelPosOpt = orient === 'horizontal'
  76183. ? ((viewRect.y + viewRect.height / 2) < api.getHeight() / 2 ? '-' : '+')
  76184. : ((viewRect.x + viewRect.width / 2) < api.getWidth() / 2 ? '+' : '-');
  76185. }
  76186. else if (isNaN(labelPosOpt)) {
  76187. labelPosOpt = ({
  76188. horizontal: {top: '-', bottom: '+'},
  76189. vertical: {left: '-', right: '+'}
  76190. })[orient][labelPosOpt];
  76191. }
  76192. var labelAlignMap = {
  76193. horizontal: 'center',
  76194. vertical: (labelPosOpt >= 0 || labelPosOpt === '+') ? 'left' : 'right'
  76195. };
  76196. var labelBaselineMap = {
  76197. horizontal: (labelPosOpt >= 0 || labelPosOpt === '+') ? 'top' : 'bottom',
  76198. vertical: 'middle'
  76199. };
  76200. var rotationMap = {
  76201. horizontal: 0,
  76202. vertical: PI$4 / 2
  76203. };
  76204. // Position
  76205. var mainLength = orient === 'vertical' ? viewRect.height : viewRect.width;
  76206. var controlModel = timelineModel.getModel('controlStyle');
  76207. var showControl = controlModel.get('show', true);
  76208. var controlSize = showControl ? controlModel.get('itemSize') : 0;
  76209. var controlGap = showControl ? controlModel.get('itemGap') : 0;
  76210. var sizePlusGap = controlSize + controlGap;
  76211. // Special label rotate.
  76212. var labelRotation = timelineModel.get('label.rotate') || 0;
  76213. labelRotation = labelRotation * PI$4 / 180; // To radian.
  76214. var playPosition;
  76215. var prevBtnPosition;
  76216. var nextBtnPosition;
  76217. var axisExtent;
  76218. var controlPosition = controlModel.get('position', true);
  76219. var showPlayBtn = showControl && controlModel.get('showPlayBtn', true);
  76220. var showPrevBtn = showControl && controlModel.get('showPrevBtn', true);
  76221. var showNextBtn = showControl && controlModel.get('showNextBtn', true);
  76222. var xLeft = 0;
  76223. var xRight = mainLength;
  76224. // position[0] means left, position[1] means middle.
  76225. if (controlPosition === 'left' || controlPosition === 'bottom') {
  76226. showPlayBtn && (playPosition = [0, 0], xLeft += sizePlusGap);
  76227. showPrevBtn && (prevBtnPosition = [xLeft, 0], xLeft += sizePlusGap);
  76228. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  76229. }
  76230. else { // 'top' 'right'
  76231. showPlayBtn && (playPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  76232. showPrevBtn && (prevBtnPosition = [0, 0], xLeft += sizePlusGap);
  76233. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  76234. }
  76235. axisExtent = [xLeft, xRight];
  76236. if (timelineModel.get('inverse')) {
  76237. axisExtent.reverse();
  76238. }
  76239. return {
  76240. viewRect: viewRect,
  76241. mainLength: mainLength,
  76242. orient: orient,
  76243. rotation: rotationMap[orient],
  76244. labelRotation: labelRotation,
  76245. labelPosOpt: labelPosOpt,
  76246. labelAlign: timelineModel.get('label.align') || labelAlignMap[orient],
  76247. labelBaseline: timelineModel.get('label.verticalAlign')
  76248. || timelineModel.get('label.baseline')
  76249. || labelBaselineMap[orient],
  76250. // Based on mainGroup.
  76251. playPosition: playPosition,
  76252. prevBtnPosition: prevBtnPosition,
  76253. nextBtnPosition: nextBtnPosition,
  76254. axisExtent: axisExtent,
  76255. controlSize: controlSize,
  76256. controlGap: controlGap
  76257. };
  76258. },
  76259. _position: function (layoutInfo, timelineModel) {
  76260. // Position is be called finally, because bounding rect is needed for
  76261. // adapt content to fill viewRect (auto adapt offset).
  76262. // Timeline may be not all in the viewRect when 'offset' is specified
  76263. // as a number, because it is more appropriate that label aligns at
  76264. // 'offset' but not the other edge defined by viewRect.
  76265. var mainGroup = this._mainGroup;
  76266. var labelGroup = this._labelGroup;
  76267. var viewRect = layoutInfo.viewRect;
  76268. if (layoutInfo.orient === 'vertical') {
  76269. // transform to horizontal, inverse rotate by left-top point.
  76270. var m = create$1();
  76271. var rotateOriginX = viewRect.x;
  76272. var rotateOriginY = viewRect.y + viewRect.height;
  76273. translate(m, m, [-rotateOriginX, -rotateOriginY]);
  76274. rotate(m, m, -PI$4 / 2);
  76275. translate(m, m, [rotateOriginX, rotateOriginY]);
  76276. viewRect = viewRect.clone();
  76277. viewRect.applyTransform(m);
  76278. }
  76279. var viewBound = getBound(viewRect);
  76280. var mainBound = getBound(mainGroup.getBoundingRect());
  76281. var labelBound = getBound(labelGroup.getBoundingRect());
  76282. var mainPosition = mainGroup.position;
  76283. var labelsPosition = labelGroup.position;
  76284. labelsPosition[0] = mainPosition[0] = viewBound[0][0];
  76285. var labelPosOpt = layoutInfo.labelPosOpt;
  76286. if (isNaN(labelPosOpt)) { // '+' or '-'
  76287. var mainBoundIdx = labelPosOpt === '+' ? 0 : 1;
  76288. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  76289. toBound(labelsPosition, labelBound, viewBound, 1, 1 - mainBoundIdx);
  76290. }
  76291. else {
  76292. var mainBoundIdx = labelPosOpt >= 0 ? 0 : 1;
  76293. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  76294. labelsPosition[1] = mainPosition[1] + labelPosOpt;
  76295. }
  76296. mainGroup.attr('position', mainPosition);
  76297. labelGroup.attr('position', labelsPosition);
  76298. mainGroup.rotation = labelGroup.rotation = layoutInfo.rotation;
  76299. setOrigin(mainGroup);
  76300. setOrigin(labelGroup);
  76301. function setOrigin(targetGroup) {
  76302. var pos = targetGroup.position;
  76303. targetGroup.origin = [
  76304. viewBound[0][0] - pos[0],
  76305. viewBound[1][0] - pos[1]
  76306. ];
  76307. }
  76308. function getBound(rect) {
  76309. // [[xmin, xmax], [ymin, ymax]]
  76310. return [
  76311. [rect.x, rect.x + rect.width],
  76312. [rect.y, rect.y + rect.height]
  76313. ];
  76314. }
  76315. function toBound(fromPos, from, to, dimIdx, boundIdx) {
  76316. fromPos[dimIdx] += to[dimIdx][boundIdx] - from[dimIdx][boundIdx];
  76317. }
  76318. },
  76319. _createAxis: function (layoutInfo, timelineModel) {
  76320. var data = timelineModel.getData();
  76321. var axisType = timelineModel.get('axisType');
  76322. var scale = createScaleByModel(timelineModel, axisType);
  76323. // Customize scale. The `tickValue` is `dataIndex`.
  76324. scale.getTicks = function () {
  76325. return data.mapArray(['value'], function (value) {
  76326. return value;
  76327. });
  76328. };
  76329. var dataExtent = data.getDataExtent('value');
  76330. scale.setExtent(dataExtent[0], dataExtent[1]);
  76331. scale.niceTicks();
  76332. var axis = new TimelineAxis('value', scale, layoutInfo.axisExtent, axisType);
  76333. axis.model = timelineModel;
  76334. return axis;
  76335. },
  76336. _createGroup: function (name) {
  76337. var newGroup = this['_' + name] = new Group();
  76338. this.group.add(newGroup);
  76339. return newGroup;
  76340. },
  76341. _renderAxisLine: function (layoutInfo, group, axis, timelineModel) {
  76342. var axisExtent = axis.getExtent();
  76343. if (!timelineModel.get('lineStyle.show')) {
  76344. return;
  76345. }
  76346. group.add(new Line({
  76347. shape: {
  76348. x1: axisExtent[0], y1: 0,
  76349. x2: axisExtent[1], y2: 0
  76350. },
  76351. style: extend(
  76352. {lineCap: 'round'},
  76353. timelineModel.getModel('lineStyle').getLineStyle()
  76354. ),
  76355. silent: true,
  76356. z2: 1
  76357. }));
  76358. },
  76359. /**
  76360. * @private
  76361. */
  76362. _renderAxisTick: function (layoutInfo, group, axis, timelineModel) {
  76363. var data = timelineModel.getData();
  76364. // Show all ticks, despite ignoring strategy.
  76365. var ticks = axis.scale.getTicks();
  76366. // The value is dataIndex, see the costomized scale.
  76367. each$27(ticks, function (value) {
  76368. var tickCoord = axis.dataToCoord(value);
  76369. var itemModel = data.getItemModel(value);
  76370. var itemStyleModel = itemModel.getModel('itemStyle');
  76371. var hoverStyleModel = itemModel.getModel('emphasis.itemStyle');
  76372. var symbolOpt = {
  76373. position: [tickCoord, 0],
  76374. onclick: bind$6(this._changeTimeline, this, value)
  76375. };
  76376. var el = giveSymbol(itemModel, itemStyleModel, group, symbolOpt);
  76377. setHoverStyle(el, hoverStyleModel.getItemStyle());
  76378. if (itemModel.get('tooltip')) {
  76379. el.dataIndex = value;
  76380. el.dataModel = timelineModel;
  76381. }
  76382. else {
  76383. el.dataIndex = el.dataModel = null;
  76384. }
  76385. }, this);
  76386. },
  76387. /**
  76388. * @private
  76389. */
  76390. _renderAxisLabel: function (layoutInfo, group, axis, timelineModel) {
  76391. var labelModel = axis.getLabelModel();
  76392. if (!labelModel.get('show')) {
  76393. return;
  76394. }
  76395. var data = timelineModel.getData();
  76396. var labels = axis.getViewLabels();
  76397. each$27(labels, function (labelItem) {
  76398. // The tickValue is dataIndex, see the costomized scale.
  76399. var dataIndex = labelItem.tickValue;
  76400. var itemModel = data.getItemModel(dataIndex);
  76401. var normalLabelModel = itemModel.getModel('label');
  76402. var hoverLabelModel = itemModel.getModel('emphasis.label');
  76403. var tickCoord = axis.dataToCoord(labelItem.tickValue);
  76404. var textEl = new Text({
  76405. position: [tickCoord, 0],
  76406. rotation: layoutInfo.labelRotation - layoutInfo.rotation,
  76407. onclick: bind$6(this._changeTimeline, this, dataIndex),
  76408. silent: false
  76409. });
  76410. setTextStyle(textEl.style, normalLabelModel, {
  76411. text: labelItem.formattedLabel,
  76412. textAlign: layoutInfo.labelAlign,
  76413. textVerticalAlign: layoutInfo.labelBaseline
  76414. });
  76415. group.add(textEl);
  76416. setHoverStyle(
  76417. textEl, setTextStyle({}, hoverLabelModel)
  76418. );
  76419. }, this);
  76420. },
  76421. /**
  76422. * @private
  76423. */
  76424. _renderControl: function (layoutInfo, group, axis, timelineModel) {
  76425. var controlSize = layoutInfo.controlSize;
  76426. var rotation = layoutInfo.rotation;
  76427. var itemStyle = timelineModel.getModel('controlStyle').getItemStyle();
  76428. var hoverStyle = timelineModel.getModel('emphasis.controlStyle').getItemStyle();
  76429. var rect = [0, -controlSize / 2, controlSize, controlSize];
  76430. var playState = timelineModel.getPlayState();
  76431. var inverse = timelineModel.get('inverse', true);
  76432. makeBtn(
  76433. layoutInfo.nextBtnPosition,
  76434. 'controlStyle.nextIcon',
  76435. bind$6(this._changeTimeline, this, inverse ? '-' : '+')
  76436. );
  76437. makeBtn(
  76438. layoutInfo.prevBtnPosition,
  76439. 'controlStyle.prevIcon',
  76440. bind$6(this._changeTimeline, this, inverse ? '+' : '-')
  76441. );
  76442. makeBtn(
  76443. layoutInfo.playPosition,
  76444. 'controlStyle.' + (playState ? 'stopIcon' : 'playIcon'),
  76445. bind$6(this._handlePlayClick, this, !playState),
  76446. true
  76447. );
  76448. function makeBtn(position, iconPath, onclick, willRotate) {
  76449. if (!position) {
  76450. return;
  76451. }
  76452. var opt = {
  76453. position: position,
  76454. origin: [controlSize / 2, 0],
  76455. rotation: willRotate ? -rotation : 0,
  76456. rectHover: true,
  76457. style: itemStyle,
  76458. onclick: onclick
  76459. };
  76460. var btn = makeIcon(timelineModel, iconPath, rect, opt);
  76461. group.add(btn);
  76462. setHoverStyle(btn, hoverStyle);
  76463. }
  76464. },
  76465. _renderCurrentPointer: function (layoutInfo, group, axis, timelineModel) {
  76466. var data = timelineModel.getData();
  76467. var currentIndex = timelineModel.getCurrentIndex();
  76468. var pointerModel = data.getItemModel(currentIndex).getModel('checkpointStyle');
  76469. var me = this;
  76470. var callback = {
  76471. onCreate: function (pointer) {
  76472. pointer.draggable = true;
  76473. pointer.drift = bind$6(me._handlePointerDrag, me);
  76474. pointer.ondragend = bind$6(me._handlePointerDragend, me);
  76475. pointerMoveTo(pointer, currentIndex, axis, timelineModel, true);
  76476. },
  76477. onUpdate: function (pointer) {
  76478. pointerMoveTo(pointer, currentIndex, axis, timelineModel);
  76479. }
  76480. };
  76481. // Reuse when exists, for animation and drag.
  76482. this._currentPointer = giveSymbol(
  76483. pointerModel, pointerModel, this._mainGroup, {}, this._currentPointer, callback
  76484. );
  76485. },
  76486. _handlePlayClick: function (nextState) {
  76487. this._clearTimer();
  76488. this.api.dispatchAction({
  76489. type: 'timelinePlayChange',
  76490. playState: nextState,
  76491. from: this.uid
  76492. });
  76493. },
  76494. _handlePointerDrag: function (dx, dy, e) {
  76495. this._clearTimer();
  76496. this._pointerChangeTimeline([e.offsetX, e.offsetY]);
  76497. },
  76498. _handlePointerDragend: function (e) {
  76499. this._pointerChangeTimeline([e.offsetX, e.offsetY], true);
  76500. },
  76501. _pointerChangeTimeline: function (mousePos, trigger) {
  76502. var toCoord = this._toAxisCoord(mousePos)[0];
  76503. var axis = this._axis;
  76504. var axisExtent = asc(axis.getExtent().slice());
  76505. toCoord > axisExtent[1] && (toCoord = axisExtent[1]);
  76506. toCoord < axisExtent[0] && (toCoord = axisExtent[0]);
  76507. this._currentPointer.position[0] = toCoord;
  76508. this._currentPointer.dirty();
  76509. var targetDataIndex = this._findNearestTick(toCoord);
  76510. var timelineModel = this.model;
  76511. if (trigger || (
  76512. targetDataIndex !== timelineModel.getCurrentIndex()
  76513. && timelineModel.get('realtime')
  76514. )) {
  76515. this._changeTimeline(targetDataIndex);
  76516. }
  76517. },
  76518. _doPlayStop: function () {
  76519. this._clearTimer();
  76520. if (this.model.getPlayState()) {
  76521. this._timer = setTimeout(
  76522. bind$6(handleFrame, this),
  76523. this.model.get('playInterval')
  76524. );
  76525. }
  76526. function handleFrame() {
  76527. // Do not cache
  76528. var timelineModel = this.model;
  76529. this._changeTimeline(
  76530. timelineModel.getCurrentIndex()
  76531. + (timelineModel.get('rewind', true) ? -1 : 1)
  76532. );
  76533. }
  76534. },
  76535. _toAxisCoord: function (vertex) {
  76536. var trans = this._mainGroup.getLocalTransform();
  76537. return applyTransform$1(vertex, trans, true);
  76538. },
  76539. _findNearestTick: function (axisCoord) {
  76540. var data = this.model.getData();
  76541. var dist = Infinity;
  76542. var targetDataIndex;
  76543. var axis = this._axis;
  76544. data.each(['value'], function (value, dataIndex) {
  76545. var coord = axis.dataToCoord(value);
  76546. var d = Math.abs(coord - axisCoord);
  76547. if (d < dist) {
  76548. dist = d;
  76549. targetDataIndex = dataIndex;
  76550. }
  76551. });
  76552. return targetDataIndex;
  76553. },
  76554. _clearTimer: function () {
  76555. if (this._timer) {
  76556. clearTimeout(this._timer);
  76557. this._timer = null;
  76558. }
  76559. },
  76560. _changeTimeline: function (nextIndex) {
  76561. var currentIndex = this.model.getCurrentIndex();
  76562. if (nextIndex === '+') {
  76563. nextIndex = currentIndex + 1;
  76564. }
  76565. else if (nextIndex === '-') {
  76566. nextIndex = currentIndex - 1;
  76567. }
  76568. this.api.dispatchAction({
  76569. type: 'timelineChange',
  76570. currentIndex: nextIndex,
  76571. from: this.uid
  76572. });
  76573. }
  76574. });
  76575. function getViewRect$4(model, api) {
  76576. return getLayoutRect(
  76577. model.getBoxLayoutParams(),
  76578. {
  76579. width: api.getWidth(),
  76580. height: api.getHeight()
  76581. },
  76582. model.get('padding')
  76583. );
  76584. }
  76585. function makeIcon(timelineModel, objPath, rect, opts) {
  76586. var icon = makePath(
  76587. timelineModel.get(objPath).replace(/^path:\/\//, ''),
  76588. clone(opts || {}),
  76589. new BoundingRect(rect[0], rect[1], rect[2], rect[3]),
  76590. 'center'
  76591. );
  76592. return icon;
  76593. }
  76594. /**
  76595. * Create symbol or update symbol
  76596. * opt: basic position and event handlers
  76597. */
  76598. function giveSymbol(hostModel, itemStyleModel, group, opt, symbol, callback) {
  76599. var color = itemStyleModel.get('color');
  76600. if (!symbol) {
  76601. var symbolType = hostModel.get('symbol');
  76602. symbol = createSymbol(symbolType, -1, -1, 2, 2, color);
  76603. symbol.setStyle('strokeNoScale', true);
  76604. group.add(symbol);
  76605. callback && callback.onCreate(symbol);
  76606. }
  76607. else {
  76608. symbol.setColor(color);
  76609. group.add(symbol); // Group may be new, also need to add.
  76610. callback && callback.onUpdate(symbol);
  76611. }
  76612. // Style
  76613. var itemStyle = itemStyleModel.getItemStyle(['color', 'symbol', 'symbolSize']);
  76614. symbol.setStyle(itemStyle);
  76615. // Transform and events.
  76616. opt = merge({
  76617. rectHover: true,
  76618. z2: 100
  76619. }, opt, true);
  76620. var symbolSize = hostModel.get('symbolSize');
  76621. symbolSize = symbolSize instanceof Array
  76622. ? symbolSize.slice()
  76623. : [+symbolSize, +symbolSize];
  76624. symbolSize[0] /= 2;
  76625. symbolSize[1] /= 2;
  76626. opt.scale = symbolSize;
  76627. var symbolOffset = hostModel.get('symbolOffset');
  76628. if (symbolOffset) {
  76629. var pos = opt.position = opt.position || [0, 0];
  76630. pos[0] += parsePercent$1(symbolOffset[0], symbolSize[0]);
  76631. pos[1] += parsePercent$1(symbolOffset[1], symbolSize[1]);
  76632. }
  76633. var symbolRotate = hostModel.get('symbolRotate');
  76634. opt.rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  76635. symbol.attr(opt);
  76636. // FIXME
  76637. // (1) When symbol.style.strokeNoScale is true and updateTransform is not performed,
  76638. // getBoundingRect will return wrong result.
  76639. // (This is supposed to be resolved in zrender, but it is a little difficult to
  76640. // leverage performance and auto updateTransform)
  76641. // (2) All of ancesters of symbol do not scale, so we can just updateTransform symbol.
  76642. symbol.updateTransform();
  76643. return symbol;
  76644. }
  76645. function pointerMoveTo(pointer, dataIndex, axis, timelineModel, noAnimation) {
  76646. if (pointer.dragging) {
  76647. return;
  76648. }
  76649. var pointerModel = timelineModel.getModel('checkpointStyle');
  76650. var toCoord = axis.dataToCoord(timelineModel.getData().get(['value'], dataIndex));
  76651. if (noAnimation || !pointerModel.get('animation', true)) {
  76652. pointer.attr({position: [toCoord, 0]});
  76653. }
  76654. else {
  76655. pointer.stopAnimation(true);
  76656. pointer.animateTo(
  76657. {position: [toCoord, 0]},
  76658. pointerModel.get('animationDuration', true),
  76659. pointerModel.get('animationEasing', true)
  76660. );
  76661. }
  76662. }
  76663. /*
  76664. * Licensed to the Apache Software Foundation (ASF) under one
  76665. * or more contributor license agreements. See the NOTICE file
  76666. * distributed with this work for additional information
  76667. * regarding copyright ownership. The ASF licenses this file
  76668. * to you under the Apache License, Version 2.0 (the
  76669. * "License"); you may not use this file except in compliance
  76670. * with the License. You may obtain a copy of the License at
  76671. *
  76672. * http://www.apache.org/licenses/LICENSE-2.0
  76673. *
  76674. * Unless required by applicable law or agreed to in writing,
  76675. * software distributed under the License is distributed on an
  76676. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76677. * KIND, either express or implied. See the License for the
  76678. * specific language governing permissions and limitations
  76679. * under the License.
  76680. */
  76681. /**
  76682. * DataZoom component entry
  76683. */
  76684. registerPreprocessor(preprocessor$3);
  76685. /*
  76686. * Licensed to the Apache Software Foundation (ASF) under one
  76687. * or more contributor license agreements. See the NOTICE file
  76688. * distributed with this work for additional information
  76689. * regarding copyright ownership. The ASF licenses this file
  76690. * to you under the Apache License, Version 2.0 (the
  76691. * "License"); you may not use this file except in compliance
  76692. * with the License. You may obtain a copy of the License at
  76693. *
  76694. * http://www.apache.org/licenses/LICENSE-2.0
  76695. *
  76696. * Unless required by applicable law or agreed to in writing,
  76697. * software distributed under the License is distributed on an
  76698. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76699. * KIND, either express or implied. See the License for the
  76700. * specific language governing permissions and limitations
  76701. * under the License.
  76702. */
  76703. var ToolboxModel = extendComponentModel({
  76704. type: 'toolbox',
  76705. layoutMode: {
  76706. type: 'box',
  76707. ignoreSize: true
  76708. },
  76709. optionUpdated: function () {
  76710. ToolboxModel.superApply(this, 'optionUpdated', arguments);
  76711. each$1(this.option.feature, function (featureOpt, featureName) {
  76712. var Feature = get$1(featureName);
  76713. Feature && merge(featureOpt, Feature.defaultOption);
  76714. });
  76715. },
  76716. defaultOption: {
  76717. show: true,
  76718. z: 6,
  76719. zlevel: 0,
  76720. orient: 'horizontal',
  76721. left: 'right',
  76722. top: 'top',
  76723. // right
  76724. // bottom
  76725. backgroundColor: 'transparent',
  76726. borderColor: '#ccc',
  76727. borderRadius: 0,
  76728. borderWidth: 0,
  76729. padding: 5,
  76730. itemSize: 15,
  76731. itemGap: 8,
  76732. showTitle: true,
  76733. iconStyle: {
  76734. borderColor: '#666',
  76735. color: 'none'
  76736. },
  76737. emphasis: {
  76738. iconStyle: {
  76739. borderColor: '#3E98C5'
  76740. }
  76741. }
  76742. // textStyle: {},
  76743. // feature
  76744. }
  76745. });
  76746. /*
  76747. * Licensed to the Apache Software Foundation (ASF) under one
  76748. * or more contributor license agreements. See the NOTICE file
  76749. * distributed with this work for additional information
  76750. * regarding copyright ownership. The ASF licenses this file
  76751. * to you under the Apache License, Version 2.0 (the
  76752. * "License"); you may not use this file except in compliance
  76753. * with the License. You may obtain a copy of the License at
  76754. *
  76755. * http://www.apache.org/licenses/LICENSE-2.0
  76756. *
  76757. * Unless required by applicable law or agreed to in writing,
  76758. * software distributed under the License is distributed on an
  76759. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76760. * KIND, either express or implied. See the License for the
  76761. * specific language governing permissions and limitations
  76762. * under the License.
  76763. */
  76764. extendComponentView({
  76765. type: 'toolbox',
  76766. render: function (toolboxModel, ecModel, api, payload) {
  76767. var group = this.group;
  76768. group.removeAll();
  76769. if (!toolboxModel.get('show')) {
  76770. return;
  76771. }
  76772. var itemSize = +toolboxModel.get('itemSize');
  76773. var featureOpts = toolboxModel.get('feature') || {};
  76774. var features = this._features || (this._features = {});
  76775. var featureNames = [];
  76776. each$1(featureOpts, function (opt, name) {
  76777. featureNames.push(name);
  76778. });
  76779. (new DataDiffer(this._featureNames || [], featureNames))
  76780. .add(processFeature)
  76781. .update(processFeature)
  76782. .remove(curry(processFeature, null))
  76783. .execute();
  76784. // Keep for diff.
  76785. this._featureNames = featureNames;
  76786. function processFeature(newIndex, oldIndex) {
  76787. var featureName = featureNames[newIndex];
  76788. var oldName = featureNames[oldIndex];
  76789. var featureOpt = featureOpts[featureName];
  76790. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  76791. var feature;
  76792. if (featureName && !oldName) { // Create
  76793. if (isUserFeatureName(featureName)) {
  76794. feature = {
  76795. model: featureModel,
  76796. onclick: featureModel.option.onclick,
  76797. featureName: featureName
  76798. };
  76799. }
  76800. else {
  76801. var Feature = get$1(featureName);
  76802. if (!Feature) {
  76803. return;
  76804. }
  76805. feature = new Feature(featureModel, ecModel, api);
  76806. }
  76807. features[featureName] = feature;
  76808. }
  76809. else {
  76810. feature = features[oldName];
  76811. // If feature does not exsit.
  76812. if (!feature) {
  76813. return;
  76814. }
  76815. feature.model = featureModel;
  76816. feature.ecModel = ecModel;
  76817. feature.api = api;
  76818. }
  76819. if (!featureName && oldName) {
  76820. feature.dispose && feature.dispose(ecModel, api);
  76821. return;
  76822. }
  76823. if (!featureModel.get('show') || feature.unusable) {
  76824. feature.remove && feature.remove(ecModel, api);
  76825. return;
  76826. }
  76827. createIconPaths(featureModel, feature, featureName);
  76828. featureModel.setIconStatus = function (iconName, status) {
  76829. var option = this.option;
  76830. var iconPaths = this.iconPaths;
  76831. option.iconStatus = option.iconStatus || {};
  76832. option.iconStatus[iconName] = status;
  76833. // FIXME
  76834. iconPaths[iconName] && iconPaths[iconName].trigger(status);
  76835. };
  76836. if (feature.render) {
  76837. feature.render(featureModel, ecModel, api, payload);
  76838. }
  76839. }
  76840. function createIconPaths(featureModel, feature, featureName) {
  76841. var iconStyleModel = featureModel.getModel('iconStyle');
  76842. var iconStyleEmphasisModel = featureModel.getModel('emphasis.iconStyle');
  76843. // If one feature has mutiple icon. they are orginaized as
  76844. // {
  76845. // icon: {
  76846. // foo: '',
  76847. // bar: ''
  76848. // },
  76849. // title: {
  76850. // foo: '',
  76851. // bar: ''
  76852. // }
  76853. // }
  76854. var icons = feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  76855. var titles = featureModel.get('title') || {};
  76856. if (typeof icons === 'string') {
  76857. var icon = icons;
  76858. var title = titles;
  76859. icons = {};
  76860. titles = {};
  76861. icons[featureName] = icon;
  76862. titles[featureName] = title;
  76863. }
  76864. var iconPaths = featureModel.iconPaths = {};
  76865. each$1(icons, function (iconStr, iconName) {
  76866. var path = createIcon(
  76867. iconStr,
  76868. {},
  76869. {
  76870. x: -itemSize / 2,
  76871. y: -itemSize / 2,
  76872. width: itemSize,
  76873. height: itemSize
  76874. }
  76875. );
  76876. path.setStyle(iconStyleModel.getItemStyle());
  76877. path.hoverStyle = iconStyleEmphasisModel.getItemStyle();
  76878. setHoverStyle(path);
  76879. if (toolboxModel.get('showTitle')) {
  76880. path.__title = titles[iconName];
  76881. path.on('mouseover', function () {
  76882. // Should not reuse above hoverStyle, which might be modified.
  76883. var hoverStyle = iconStyleEmphasisModel.getItemStyle();
  76884. path.setStyle({
  76885. text: titles[iconName],
  76886. textPosition: hoverStyle.textPosition || 'bottom',
  76887. textFill: hoverStyle.fill || hoverStyle.stroke || '#000',
  76888. textAlign: hoverStyle.textAlign || 'center'
  76889. });
  76890. })
  76891. .on('mouseout', function () {
  76892. path.setStyle({
  76893. textFill: null
  76894. });
  76895. });
  76896. }
  76897. path.trigger(featureModel.get('iconStatus.' + iconName) || 'normal');
  76898. group.add(path);
  76899. path.on('click', bind(
  76900. feature.onclick, feature, ecModel, api, iconName
  76901. ));
  76902. iconPaths[iconName] = path;
  76903. });
  76904. }
  76905. layout$3(group, toolboxModel, api);
  76906. // Render background after group is layout
  76907. // FIXME
  76908. group.add(makeBackground(group.getBoundingRect(), toolboxModel));
  76909. // Adjust icon title positions to avoid them out of screen
  76910. group.eachChild(function (icon) {
  76911. var titleText = icon.__title;
  76912. var hoverStyle = icon.hoverStyle;
  76913. // May be background element
  76914. if (hoverStyle && titleText) {
  76915. var rect = getBoundingRect(
  76916. titleText, makeFont(hoverStyle)
  76917. );
  76918. var offsetX = icon.position[0] + group.position[0];
  76919. var offsetY = icon.position[1] + group.position[1] + itemSize;
  76920. var needPutOnTop = false;
  76921. if (offsetY + rect.height > api.getHeight()) {
  76922. hoverStyle.textPosition = 'top';
  76923. needPutOnTop = true;
  76924. }
  76925. var topOffset = needPutOnTop ? (-5 - rect.height) : (itemSize + 8);
  76926. if (offsetX + rect.width / 2 > api.getWidth()) {
  76927. hoverStyle.textPosition = ['100%', topOffset];
  76928. hoverStyle.textAlign = 'right';
  76929. }
  76930. else if (offsetX - rect.width / 2 < 0) {
  76931. hoverStyle.textPosition = [0, topOffset];
  76932. hoverStyle.textAlign = 'left';
  76933. }
  76934. }
  76935. });
  76936. },
  76937. updateView: function (toolboxModel, ecModel, api, payload) {
  76938. each$1(this._features, function (feature) {
  76939. feature.updateView && feature.updateView(feature.model, ecModel, api, payload);
  76940. });
  76941. },
  76942. // updateLayout: function (toolboxModel, ecModel, api, payload) {
  76943. // zrUtil.each(this._features, function (feature) {
  76944. // feature.updateLayout && feature.updateLayout(feature.model, ecModel, api, payload);
  76945. // });
  76946. // },
  76947. remove: function (ecModel, api) {
  76948. each$1(this._features, function (feature) {
  76949. feature.remove && feature.remove(ecModel, api);
  76950. });
  76951. this.group.removeAll();
  76952. },
  76953. dispose: function (ecModel, api) {
  76954. each$1(this._features, function (feature) {
  76955. feature.dispose && feature.dispose(ecModel, api);
  76956. });
  76957. }
  76958. });
  76959. function isUserFeatureName(featureName) {
  76960. return featureName.indexOf('my') === 0;
  76961. }
  76962. /*
  76963. * Licensed to the Apache Software Foundation (ASF) under one
  76964. * or more contributor license agreements. See the NOTICE file
  76965. * distributed with this work for additional information
  76966. * regarding copyright ownership. The ASF licenses this file
  76967. * to you under the Apache License, Version 2.0 (the
  76968. * "License"); you may not use this file except in compliance
  76969. * with the License. You may obtain a copy of the License at
  76970. *
  76971. * http://www.apache.org/licenses/LICENSE-2.0
  76972. *
  76973. * Unless required by applicable law or agreed to in writing,
  76974. * software distributed under the License is distributed on an
  76975. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76976. * KIND, either express or implied. See the License for the
  76977. * specific language governing permissions and limitations
  76978. * under the License.
  76979. */
  76980. /* global Uint8Array */
  76981. var saveAsImageLang = lang.toolbox.saveAsImage;
  76982. function SaveAsImage(model) {
  76983. this.model = model;
  76984. }
  76985. SaveAsImage.defaultOption = {
  76986. show: true,
  76987. 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',
  76988. title: saveAsImageLang.title,
  76989. type: 'png',
  76990. // Default use option.backgroundColor
  76991. // backgroundColor: '#fff',
  76992. name: '',
  76993. excludeComponents: ['toolbox'],
  76994. pixelRatio: 1,
  76995. lang: saveAsImageLang.lang.slice()
  76996. };
  76997. SaveAsImage.prototype.unusable = !env$1.canvasSupported;
  76998. var proto$4 = SaveAsImage.prototype;
  76999. proto$4.onclick = function (ecModel, api) {
  77000. var model = this.model;
  77001. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  77002. var $a = document.createElement('a');
  77003. var type = model.get('type', true) || 'png';
  77004. $a.download = title + '.' + type;
  77005. $a.target = '_blank';
  77006. var url = api.getConnectedDataURL({
  77007. type: type,
  77008. backgroundColor: model.get('backgroundColor', true)
  77009. || ecModel.get('backgroundColor') || '#fff',
  77010. excludeComponents: model.get('excludeComponents'),
  77011. pixelRatio: model.get('pixelRatio')
  77012. });
  77013. $a.href = url;
  77014. // Chrome and Firefox
  77015. if (typeof MouseEvent === 'function' && !env$1.browser.ie && !env$1.browser.edge) {
  77016. var evt = new MouseEvent('click', {
  77017. view: window,
  77018. bubbles: true,
  77019. cancelable: false
  77020. });
  77021. $a.dispatchEvent(evt);
  77022. }
  77023. // IE
  77024. else {
  77025. if (window.navigator.msSaveOrOpenBlob) {
  77026. var bstr = atob(url.split(',')[1]);
  77027. var n = bstr.length;
  77028. var u8arr = new Uint8Array(n);
  77029. while (n--) {
  77030. u8arr[n] = bstr.charCodeAt(n);
  77031. }
  77032. var blob = new Blob([u8arr]);
  77033. window.navigator.msSaveOrOpenBlob(blob, title + '.' + type);
  77034. }
  77035. else {
  77036. var lang$$1 = model.get('lang');
  77037. var html = ''
  77038. + '<body style="margin:0;">'
  77039. + '<img src="' + url + '" style="max-width:100%;" title="' + ((lang$$1 && lang$$1[0]) || '') + '" />'
  77040. + '</body>';
  77041. var tab = window.open();
  77042. tab.document.write(html);
  77043. }
  77044. }
  77045. };
  77046. register$1(
  77047. 'saveAsImage', SaveAsImage
  77048. );
  77049. /*
  77050. * Licensed to the Apache Software Foundation (ASF) under one
  77051. * or more contributor license agreements. See the NOTICE file
  77052. * distributed with this work for additional information
  77053. * regarding copyright ownership. The ASF licenses this file
  77054. * to you under the Apache License, Version 2.0 (the
  77055. * "License"); you may not use this file except in compliance
  77056. * with the License. You may obtain a copy of the License at
  77057. *
  77058. * http://www.apache.org/licenses/LICENSE-2.0
  77059. *
  77060. * Unless required by applicable law or agreed to in writing,
  77061. * software distributed under the License is distributed on an
  77062. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77063. * KIND, either express or implied. See the License for the
  77064. * specific language governing permissions and limitations
  77065. * under the License.
  77066. */
  77067. var magicTypeLang = lang.toolbox.magicType;
  77068. function MagicType(model) {
  77069. this.model = model;
  77070. }
  77071. MagicType.defaultOption = {
  77072. show: true,
  77073. type: [],
  77074. // Icon group
  77075. icon: {
  77076. /* eslint-disable */
  77077. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  77078. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  77079. 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
  77080. tiled: 'M2.3,2.2h22.8V25H2.3V2.2z M35,2.2h22.8V25H35V2.2zM2.3,35h22.8v22.8H2.3V35z M35,35h22.8v22.8H35V35z'
  77081. /* eslint-enable */
  77082. },
  77083. // `line`, `bar`, `stack`, `tiled`
  77084. title: clone(magicTypeLang.title),
  77085. option: {},
  77086. seriesIndex: {}
  77087. };
  77088. var proto$5 = MagicType.prototype;
  77089. proto$5.getIcons = function () {
  77090. var model = this.model;
  77091. var availableIcons = model.get('icon');
  77092. var icons = {};
  77093. each$1(model.get('type'), function (type) {
  77094. if (availableIcons[type]) {
  77095. icons[type] = availableIcons[type];
  77096. }
  77097. });
  77098. return icons;
  77099. };
  77100. var seriesOptGenreator = {
  77101. 'line': function (seriesType, seriesId, seriesModel, model) {
  77102. if (seriesType === 'bar') {
  77103. return merge({
  77104. id: seriesId,
  77105. type: 'line',
  77106. // Preserve data related option
  77107. data: seriesModel.get('data'),
  77108. stack: seriesModel.get('stack'),
  77109. markPoint: seriesModel.get('markPoint'),
  77110. markLine: seriesModel.get('markLine')
  77111. }, model.get('option.line') || {}, true);
  77112. }
  77113. },
  77114. 'bar': function (seriesType, seriesId, seriesModel, model) {
  77115. if (seriesType === 'line') {
  77116. return merge({
  77117. id: seriesId,
  77118. type: 'bar',
  77119. // Preserve data related option
  77120. data: seriesModel.get('data'),
  77121. stack: seriesModel.get('stack'),
  77122. markPoint: seriesModel.get('markPoint'),
  77123. markLine: seriesModel.get('markLine')
  77124. }, model.get('option.bar') || {}, true);
  77125. }
  77126. },
  77127. 'stack': function (seriesType, seriesId, seriesModel, model) {
  77128. if (seriesType === 'line' || seriesType === 'bar') {
  77129. return merge({
  77130. id: seriesId,
  77131. stack: '__ec_magicType_stack__'
  77132. }, model.get('option.stack') || {}, true);
  77133. }
  77134. },
  77135. 'tiled': function (seriesType, seriesId, seriesModel, model) {
  77136. if (seriesType === 'line' || seriesType === 'bar') {
  77137. return merge({
  77138. id: seriesId,
  77139. stack: ''
  77140. }, model.get('option.tiled') || {}, true);
  77141. }
  77142. }
  77143. };
  77144. var radioTypes = [
  77145. ['line', 'bar'],
  77146. ['stack', 'tiled']
  77147. ];
  77148. proto$5.onclick = function (ecModel, api, type) {
  77149. var model = this.model;
  77150. var seriesIndex = model.get('seriesIndex.' + type);
  77151. // Not supported magicType
  77152. if (!seriesOptGenreator[type]) {
  77153. return;
  77154. }
  77155. var newOption = {
  77156. series: []
  77157. };
  77158. var generateNewSeriesTypes = function (seriesModel) {
  77159. var seriesType = seriesModel.subType;
  77160. var seriesId = seriesModel.id;
  77161. var newSeriesOpt = seriesOptGenreator[type](
  77162. seriesType, seriesId, seriesModel, model
  77163. );
  77164. if (newSeriesOpt) {
  77165. // PENDING If merge original option?
  77166. defaults(newSeriesOpt, seriesModel.option);
  77167. newOption.series.push(newSeriesOpt);
  77168. }
  77169. // Modify boundaryGap
  77170. var coordSys = seriesModel.coordinateSystem;
  77171. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  77172. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  77173. if (categoryAxis) {
  77174. var axisDim = categoryAxis.dim;
  77175. var axisType = axisDim + 'Axis';
  77176. var axisModel = ecModel.queryComponents({
  77177. mainType: axisType,
  77178. index: seriesModel.get(name + 'Index'),
  77179. id: seriesModel.get(name + 'Id')
  77180. })[0];
  77181. var axisIndex = axisModel.componentIndex;
  77182. newOption[axisType] = newOption[axisType] || [];
  77183. for (var i = 0; i <= axisIndex; i++) {
  77184. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  77185. }
  77186. newOption[axisType][axisIndex].boundaryGap = type === 'bar';
  77187. }
  77188. }
  77189. };
  77190. each$1(radioTypes, function (radio) {
  77191. if (indexOf(radio, type) >= 0) {
  77192. each$1(radio, function (item) {
  77193. model.setIconStatus(item, 'normal');
  77194. });
  77195. }
  77196. });
  77197. model.setIconStatus(type, 'emphasis');
  77198. ecModel.eachComponent(
  77199. {
  77200. mainType: 'series',
  77201. query: seriesIndex == null ? null : {
  77202. seriesIndex: seriesIndex
  77203. }
  77204. }, generateNewSeriesTypes
  77205. );
  77206. api.dispatchAction({
  77207. type: 'changeMagicType',
  77208. currentType: type,
  77209. newOption: newOption
  77210. });
  77211. };
  77212. registerAction({
  77213. type: 'changeMagicType',
  77214. event: 'magicTypeChanged',
  77215. update: 'prepareAndUpdate'
  77216. }, function (payload, ecModel) {
  77217. ecModel.mergeOption(payload.newOption);
  77218. });
  77219. register$1('magicType', MagicType);
  77220. /*
  77221. * Licensed to the Apache Software Foundation (ASF) under one
  77222. * or more contributor license agreements. See the NOTICE file
  77223. * distributed with this work for additional information
  77224. * regarding copyright ownership. The ASF licenses this file
  77225. * to you under the Apache License, Version 2.0 (the
  77226. * "License"); you may not use this file except in compliance
  77227. * with the License. You may obtain a copy of the License at
  77228. *
  77229. * http://www.apache.org/licenses/LICENSE-2.0
  77230. *
  77231. * Unless required by applicable law or agreed to in writing,
  77232. * software distributed under the License is distributed on an
  77233. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77234. * KIND, either express or implied. See the License for the
  77235. * specific language governing permissions and limitations
  77236. * under the License.
  77237. */
  77238. var dataViewLang = lang.toolbox.dataView;
  77239. var BLOCK_SPLITER = new Array(60).join('-');
  77240. var ITEM_SPLITER = '\t';
  77241. /**
  77242. * Group series into two types
  77243. * 1. on category axis, like line, bar
  77244. * 2. others, like scatter, pie
  77245. * @param {module:echarts/model/Global} ecModel
  77246. * @return {Object}
  77247. * @inner
  77248. */
  77249. function groupSeries(ecModel) {
  77250. var seriesGroupByCategoryAxis = {};
  77251. var otherSeries = [];
  77252. var meta = [];
  77253. ecModel.eachRawSeries(function (seriesModel) {
  77254. var coordSys = seriesModel.coordinateSystem;
  77255. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  77256. var baseAxis = coordSys.getBaseAxis();
  77257. if (baseAxis.type === 'category') {
  77258. var key = baseAxis.dim + '_' + baseAxis.index;
  77259. if (!seriesGroupByCategoryAxis[key]) {
  77260. seriesGroupByCategoryAxis[key] = {
  77261. categoryAxis: baseAxis,
  77262. valueAxis: coordSys.getOtherAxis(baseAxis),
  77263. series: []
  77264. };
  77265. meta.push({
  77266. axisDim: baseAxis.dim,
  77267. axisIndex: baseAxis.index
  77268. });
  77269. }
  77270. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  77271. }
  77272. else {
  77273. otherSeries.push(seriesModel);
  77274. }
  77275. }
  77276. else {
  77277. otherSeries.push(seriesModel);
  77278. }
  77279. });
  77280. return {
  77281. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  77282. other: otherSeries,
  77283. meta: meta
  77284. };
  77285. }
  77286. /**
  77287. * Assemble content of series on cateogory axis
  77288. * @param {Array.<module:echarts/model/Series>} series
  77289. * @return {string}
  77290. * @inner
  77291. */
  77292. function assembleSeriesWithCategoryAxis(series) {
  77293. var tables = [];
  77294. each$1(series, function (group, key) {
  77295. var categoryAxis = group.categoryAxis;
  77296. var valueAxis = group.valueAxis;
  77297. var valueAxisDim = valueAxis.dim;
  77298. var headers = [' '].concat(map(group.series, function (series) {
  77299. return series.name;
  77300. }));
  77301. var columns = [categoryAxis.model.getCategories()];
  77302. each$1(group.series, function (series) {
  77303. columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
  77304. return val;
  77305. }));
  77306. });
  77307. // Assemble table content
  77308. var lines = [headers.join(ITEM_SPLITER)];
  77309. for (var i = 0; i < columns[0].length; i++) {
  77310. var items = [];
  77311. for (var j = 0; j < columns.length; j++) {
  77312. items.push(columns[j][i]);
  77313. }
  77314. lines.push(items.join(ITEM_SPLITER));
  77315. }
  77316. tables.push(lines.join('\n'));
  77317. });
  77318. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  77319. }
  77320. /**
  77321. * Assemble content of other series
  77322. * @param {Array.<module:echarts/model/Series>} series
  77323. * @return {string}
  77324. * @inner
  77325. */
  77326. function assembleOtherSeries(series) {
  77327. return map(series, function (series) {
  77328. var data = series.getRawData();
  77329. var lines = [series.name];
  77330. var vals = [];
  77331. data.each(data.dimensions, function () {
  77332. var argLen = arguments.length;
  77333. var dataIndex = arguments[argLen - 1];
  77334. var name = data.getName(dataIndex);
  77335. for (var i = 0; i < argLen - 1; i++) {
  77336. vals[i] = arguments[i];
  77337. }
  77338. lines.push((name ? (name + ITEM_SPLITER) : '') + vals.join(ITEM_SPLITER));
  77339. });
  77340. return lines.join('\n');
  77341. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  77342. }
  77343. /**
  77344. * @param {module:echarts/model/Global}
  77345. * @return {Object}
  77346. * @inner
  77347. */
  77348. function getContentFromModel(ecModel) {
  77349. var result = groupSeries(ecModel);
  77350. return {
  77351. value: filter([
  77352. assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis),
  77353. assembleOtherSeries(result.other)
  77354. ], function (str) {
  77355. return str.replace(/[\n\t\s]/g, '');
  77356. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  77357. meta: result.meta
  77358. };
  77359. }
  77360. function trim$1(str) {
  77361. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  77362. }
  77363. /**
  77364. * If a block is tsv format
  77365. */
  77366. function isTSVFormat(block) {
  77367. // Simple method to find out if a block is tsv format
  77368. var firstLine = block.slice(0, block.indexOf('\n'));
  77369. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  77370. return true;
  77371. }
  77372. }
  77373. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  77374. /**
  77375. * @param {string} tsv
  77376. * @return {Object}
  77377. */
  77378. function parseTSVContents(tsv) {
  77379. var tsvLines = tsv.split(/\n+/g);
  77380. var headers = trim$1(tsvLines.shift()).split(itemSplitRegex);
  77381. var categories = [];
  77382. var series = map(headers, function (header) {
  77383. return {
  77384. name: header,
  77385. data: []
  77386. };
  77387. });
  77388. for (var i = 0; i < tsvLines.length; i++) {
  77389. var items = trim$1(tsvLines[i]).split(itemSplitRegex);
  77390. categories.push(items.shift());
  77391. for (var j = 0; j < items.length; j++) {
  77392. series[j] && (series[j].data[i] = items[j]);
  77393. }
  77394. }
  77395. return {
  77396. series: series,
  77397. categories: categories
  77398. };
  77399. }
  77400. /**
  77401. * @param {string} str
  77402. * @return {Array.<Object>}
  77403. * @inner
  77404. */
  77405. function parseListContents(str) {
  77406. var lines = str.split(/\n+/g);
  77407. var seriesName = trim$1(lines.shift());
  77408. var data = [];
  77409. for (var i = 0; i < lines.length; i++) {
  77410. var items = trim$1(lines[i]).split(itemSplitRegex);
  77411. var name = '';
  77412. var value;
  77413. var hasName = false;
  77414. if (isNaN(items[0])) { // First item is name
  77415. hasName = true;
  77416. name = items[0];
  77417. items = items.slice(1);
  77418. data[i] = {
  77419. name: name,
  77420. value: []
  77421. };
  77422. value = data[i].value;
  77423. }
  77424. else {
  77425. value = data[i] = [];
  77426. }
  77427. for (var j = 0; j < items.length; j++) {
  77428. value.push(+items[j]);
  77429. }
  77430. if (value.length === 1) {
  77431. hasName ? (data[i].value = value[0]) : (data[i] = value[0]);
  77432. }
  77433. }
  77434. return {
  77435. name: seriesName,
  77436. data: data
  77437. };
  77438. }
  77439. /**
  77440. * @param {string} str
  77441. * @param {Array.<Object>} blockMetaList
  77442. * @return {Object}
  77443. * @inner
  77444. */
  77445. function parseContents(str, blockMetaList) {
  77446. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  77447. var newOption = {
  77448. series: []
  77449. };
  77450. each$1(blocks, function (block, idx) {
  77451. if (isTSVFormat(block)) {
  77452. var result = parseTSVContents(block);
  77453. var blockMeta = blockMetaList[idx];
  77454. var axisKey = blockMeta.axisDim + 'Axis';
  77455. if (blockMeta) {
  77456. newOption[axisKey] = newOption[axisKey] || [];
  77457. newOption[axisKey][blockMeta.axisIndex] = {
  77458. data: result.categories
  77459. };
  77460. newOption.series = newOption.series.concat(result.series);
  77461. }
  77462. }
  77463. else {
  77464. var result = parseListContents(block);
  77465. newOption.series.push(result);
  77466. }
  77467. });
  77468. return newOption;
  77469. }
  77470. /**
  77471. * @alias {module:echarts/component/toolbox/feature/DataView}
  77472. * @constructor
  77473. * @param {module:echarts/model/Model} model
  77474. */
  77475. function DataView(model) {
  77476. this._dom = null;
  77477. this.model = model;
  77478. }
  77479. DataView.defaultOption = {
  77480. show: true,
  77481. readOnly: false,
  77482. optionToContent: null,
  77483. contentToOption: null,
  77484. 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',
  77485. title: clone(dataViewLang.title),
  77486. lang: clone(dataViewLang.lang),
  77487. backgroundColor: '#fff',
  77488. textColor: '#000',
  77489. textareaColor: '#fff',
  77490. textareaBorderColor: '#333',
  77491. buttonColor: '#c23531',
  77492. buttonTextColor: '#fff'
  77493. };
  77494. DataView.prototype.onclick = function (ecModel, api) {
  77495. var container = api.getDom();
  77496. var model = this.model;
  77497. if (this._dom) {
  77498. container.removeChild(this._dom);
  77499. }
  77500. var root = document.createElement('div');
  77501. root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
  77502. root.style.backgroundColor = model.get('backgroundColor') || '#fff';
  77503. // Create elements
  77504. var header = document.createElement('h4');
  77505. var lang$$1 = model.get('lang') || [];
  77506. header.innerHTML = lang$$1[0] || model.get('title');
  77507. header.style.cssText = 'margin: 10px 20px;';
  77508. header.style.color = model.get('textColor');
  77509. var viewMain = document.createElement('div');
  77510. var textarea = document.createElement('textarea');
  77511. viewMain.style.cssText = 'display:block;width:100%;overflow:auto;';
  77512. var optionToContent = model.get('optionToContent');
  77513. var contentToOption = model.get('contentToOption');
  77514. var result = getContentFromModel(ecModel);
  77515. if (typeof optionToContent === 'function') {
  77516. var htmlOrDom = optionToContent(api.getOption());
  77517. if (typeof htmlOrDom === 'string') {
  77518. viewMain.innerHTML = htmlOrDom;
  77519. }
  77520. else if (isDom(htmlOrDom)) {
  77521. viewMain.appendChild(htmlOrDom);
  77522. }
  77523. }
  77524. else {
  77525. // Use default textarea
  77526. viewMain.appendChild(textarea);
  77527. textarea.readOnly = model.get('readOnly');
  77528. textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
  77529. textarea.style.color = model.get('textColor');
  77530. textarea.style.borderColor = model.get('textareaBorderColor');
  77531. textarea.style.backgroundColor = model.get('textareaColor');
  77532. textarea.value = result.value;
  77533. }
  77534. var blockMetaList = result.meta;
  77535. var buttonContainer = document.createElement('div');
  77536. buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
  77537. var buttonStyle = 'float:right;margin-right:20px;border:none;'
  77538. + 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  77539. var closeButton = document.createElement('div');
  77540. var refreshButton = document.createElement('div');
  77541. buttonStyle += ';background-color:' + model.get('buttonColor');
  77542. buttonStyle += ';color:' + model.get('buttonTextColor');
  77543. var self = this;
  77544. function close() {
  77545. container.removeChild(root);
  77546. self._dom = null;
  77547. }
  77548. addEventListener(closeButton, 'click', close);
  77549. addEventListener(refreshButton, 'click', function () {
  77550. var newOption;
  77551. try {
  77552. if (typeof contentToOption === 'function') {
  77553. newOption = contentToOption(viewMain, api.getOption());
  77554. }
  77555. else {
  77556. newOption = parseContents(textarea.value, blockMetaList);
  77557. }
  77558. }
  77559. catch (e) {
  77560. close();
  77561. throw new Error('Data view format error ' + e);
  77562. }
  77563. if (newOption) {
  77564. api.dispatchAction({
  77565. type: 'changeDataView',
  77566. newOption: newOption
  77567. });
  77568. }
  77569. close();
  77570. });
  77571. closeButton.innerHTML = lang$$1[1];
  77572. refreshButton.innerHTML = lang$$1[2];
  77573. refreshButton.style.cssText = buttonStyle;
  77574. closeButton.style.cssText = buttonStyle;
  77575. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  77576. buttonContainer.appendChild(closeButton);
  77577. // http://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea
  77578. addEventListener(textarea, 'keydown', function (e) {
  77579. if ((e.keyCode || e.which) === 9) {
  77580. // get caret position/selection
  77581. var val = this.value;
  77582. var start = this.selectionStart;
  77583. var end = this.selectionEnd;
  77584. // set textarea value to: text before caret + tab + text after caret
  77585. this.value = val.substring(0, start) + ITEM_SPLITER + val.substring(end);
  77586. // put caret at right position again
  77587. this.selectionStart = this.selectionEnd = start + 1;
  77588. // prevent the focus lose
  77589. stop(e);
  77590. }
  77591. });
  77592. root.appendChild(header);
  77593. root.appendChild(viewMain);
  77594. root.appendChild(buttonContainer);
  77595. viewMain.style.height = (container.clientHeight - 80) + 'px';
  77596. container.appendChild(root);
  77597. this._dom = root;
  77598. };
  77599. DataView.prototype.remove = function (ecModel, api) {
  77600. this._dom && api.getDom().removeChild(this._dom);
  77601. };
  77602. DataView.prototype.dispose = function (ecModel, api) {
  77603. this.remove(ecModel, api);
  77604. };
  77605. /**
  77606. * @inner
  77607. */
  77608. function tryMergeDataOption(newData, originalData) {
  77609. return map(newData, function (newVal, idx) {
  77610. var original = originalData && originalData[idx];
  77611. if (isObject$1(original) && !isArray(original)) {
  77612. if (isObject$1(newVal) && !isArray(newVal)) {
  77613. newVal = newVal.value;
  77614. }
  77615. // Original data has option
  77616. return defaults({
  77617. value: newVal
  77618. }, original);
  77619. }
  77620. else {
  77621. return newVal;
  77622. }
  77623. });
  77624. }
  77625. register$1('dataView', DataView);
  77626. registerAction({
  77627. type: 'changeDataView',
  77628. event: 'dataViewChanged',
  77629. update: 'prepareAndUpdate'
  77630. }, function (payload, ecModel) {
  77631. var newSeriesOptList = [];
  77632. each$1(payload.newOption.series, function (seriesOpt) {
  77633. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  77634. if (!seriesModel) {
  77635. // New created series
  77636. // Geuss the series type
  77637. newSeriesOptList.push(extend({
  77638. // Default is scatter
  77639. type: 'scatter'
  77640. }, seriesOpt));
  77641. }
  77642. else {
  77643. var originalData = seriesModel.get('data');
  77644. newSeriesOptList.push({
  77645. name: seriesOpt.name,
  77646. data: tryMergeDataOption(seriesOpt.data, originalData)
  77647. });
  77648. }
  77649. });
  77650. ecModel.mergeOption(defaults({
  77651. series: newSeriesOptList
  77652. }, payload.newOption));
  77653. });
  77654. /*
  77655. * Licensed to the Apache Software Foundation (ASF) under one
  77656. * or more contributor license agreements. See the NOTICE file
  77657. * distributed with this work for additional information
  77658. * regarding copyright ownership. The ASF licenses this file
  77659. * to you under the Apache License, Version 2.0 (the
  77660. * "License"); you may not use this file except in compliance
  77661. * with the License. You may obtain a copy of the License at
  77662. *
  77663. * http://www.apache.org/licenses/LICENSE-2.0
  77664. *
  77665. * Unless required by applicable law or agreed to in writing,
  77666. * software distributed under the License is distributed on an
  77667. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77668. * KIND, either express or implied. See the License for the
  77669. * specific language governing permissions and limitations
  77670. * under the License.
  77671. */
  77672. var each$29 = each$1;
  77673. var ATTR$2 = '\0_ec_hist_store';
  77674. /**
  77675. * @param {module:echarts/model/Global} ecModel
  77676. * @param {Object} newSnapshot {dataZoomId, batch: [payloadInfo, ...]}
  77677. */
  77678. function push(ecModel, newSnapshot) {
  77679. var store = giveStore$1(ecModel);
  77680. // If previous dataZoom can not be found,
  77681. // complete an range with current range.
  77682. each$29(newSnapshot, function (batchItem, dataZoomId) {
  77683. var i = store.length - 1;
  77684. for (; i >= 0; i--) {
  77685. var snapshot = store[i];
  77686. if (snapshot[dataZoomId]) {
  77687. break;
  77688. }
  77689. }
  77690. if (i < 0) {
  77691. // No origin range set, create one by current range.
  77692. var dataZoomModel = ecModel.queryComponents(
  77693. {mainType: 'dataZoom', subType: 'select', id: dataZoomId}
  77694. )[0];
  77695. if (dataZoomModel) {
  77696. var percentRange = dataZoomModel.getPercentRange();
  77697. store[0][dataZoomId] = {
  77698. dataZoomId: dataZoomId,
  77699. start: percentRange[0],
  77700. end: percentRange[1]
  77701. };
  77702. }
  77703. }
  77704. });
  77705. store.push(newSnapshot);
  77706. }
  77707. /**
  77708. * @param {module:echarts/model/Global} ecModel
  77709. * @return {Object} snapshot
  77710. */
  77711. function pop(ecModel) {
  77712. var store = giveStore$1(ecModel);
  77713. var head = store[store.length - 1];
  77714. store.length > 1 && store.pop();
  77715. // Find top for all dataZoom.
  77716. var snapshot = {};
  77717. each$29(head, function (batchItem, dataZoomId) {
  77718. for (var i = store.length - 1; i >= 0; i--) {
  77719. var batchItem = store[i][dataZoomId];
  77720. if (batchItem) {
  77721. snapshot[dataZoomId] = batchItem;
  77722. break;
  77723. }
  77724. }
  77725. });
  77726. return snapshot;
  77727. }
  77728. /**
  77729. * @param {module:echarts/model/Global} ecModel
  77730. */
  77731. function clear$1(ecModel) {
  77732. ecModel[ATTR$2] = null;
  77733. }
  77734. /**
  77735. * @param {module:echarts/model/Global} ecModel
  77736. * @return {number} records. always >= 1.
  77737. */
  77738. function count(ecModel) {
  77739. return giveStore$1(ecModel).length;
  77740. }
  77741. /**
  77742. * [{key: dataZoomId, value: {dataZoomId, range}}, ...]
  77743. * History length of each dataZoom may be different.
  77744. * this._history[0] is used to store origin range.
  77745. * @type {Array.<Object>}
  77746. */
  77747. function giveStore$1(ecModel) {
  77748. var store = ecModel[ATTR$2];
  77749. if (!store) {
  77750. store = ecModel[ATTR$2] = [{}];
  77751. }
  77752. return store;
  77753. }
  77754. /*
  77755. * Licensed to the Apache Software Foundation (ASF) under one
  77756. * or more contributor license agreements. See the NOTICE file
  77757. * distributed with this work for additional information
  77758. * regarding copyright ownership. The ASF licenses this file
  77759. * to you under the Apache License, Version 2.0 (the
  77760. * "License"); you may not use this file except in compliance
  77761. * with the License. You may obtain a copy of the License at
  77762. *
  77763. * http://www.apache.org/licenses/LICENSE-2.0
  77764. *
  77765. * Unless required by applicable law or agreed to in writing,
  77766. * software distributed under the License is distributed on an
  77767. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77768. * KIND, either express or implied. See the License for the
  77769. * specific language governing permissions and limitations
  77770. * under the License.
  77771. */
  77772. DataZoomModel.extend({
  77773. type: 'dataZoom.select'
  77774. });
  77775. /*
  77776. * Licensed to the Apache Software Foundation (ASF) under one
  77777. * or more contributor license agreements. See the NOTICE file
  77778. * distributed with this work for additional information
  77779. * regarding copyright ownership. The ASF licenses this file
  77780. * to you under the Apache License, Version 2.0 (the
  77781. * "License"); you may not use this file except in compliance
  77782. * with the License. You may obtain a copy of the License at
  77783. *
  77784. * http://www.apache.org/licenses/LICENSE-2.0
  77785. *
  77786. * Unless required by applicable law or agreed to in writing,
  77787. * software distributed under the License is distributed on an
  77788. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77789. * KIND, either express or implied. See the License for the
  77790. * specific language governing permissions and limitations
  77791. * under the License.
  77792. */
  77793. DataZoomView.extend({
  77794. type: 'dataZoom.select'
  77795. });
  77796. /*
  77797. * Licensed to the Apache Software Foundation (ASF) under one
  77798. * or more contributor license agreements. See the NOTICE file
  77799. * distributed with this work for additional information
  77800. * regarding copyright ownership. The ASF licenses this file
  77801. * to you under the Apache License, Version 2.0 (the
  77802. * "License"); you may not use this file except in compliance
  77803. * with the License. You may obtain a copy of the License at
  77804. *
  77805. * http://www.apache.org/licenses/LICENSE-2.0
  77806. *
  77807. * Unless required by applicable law or agreed to in writing,
  77808. * software distributed under the License is distributed on an
  77809. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77810. * KIND, either express or implied. See the License for the
  77811. * specific language governing permissions and limitations
  77812. * under the License.
  77813. */
  77814. /**
  77815. * DataZoom component entry
  77816. */
  77817. /*
  77818. * Licensed to the Apache Software Foundation (ASF) under one
  77819. * or more contributor license agreements. See the NOTICE file
  77820. * distributed with this work for additional information
  77821. * regarding copyright ownership. The ASF licenses this file
  77822. * to you under the Apache License, Version 2.0 (the
  77823. * "License"); you may not use this file except in compliance
  77824. * with the License. You may obtain a copy of the License at
  77825. *
  77826. * http://www.apache.org/licenses/LICENSE-2.0
  77827. *
  77828. * Unless required by applicable law or agreed to in writing,
  77829. * software distributed under the License is distributed on an
  77830. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77831. * KIND, either express or implied. See the License for the
  77832. * specific language governing permissions and limitations
  77833. * under the License.
  77834. */
  77835. // Use dataZoomSelect
  77836. var dataZoomLang = lang.toolbox.dataZoom;
  77837. var each$28 = each$1;
  77838. // Spectial component id start with \0ec\0, see echarts/model/Global.js~hasInnerId
  77839. var DATA_ZOOM_ID_BASE = '\0_ec_\0toolbox-dataZoom_';
  77840. function DataZoom(model, ecModel, api) {
  77841. /**
  77842. * @private
  77843. * @type {module:echarts/component/helper/BrushController}
  77844. */
  77845. (this._brushController = new BrushController(api.getZr()))
  77846. .on('brush', bind(this._onBrush, this))
  77847. .mount();
  77848. /**
  77849. * @private
  77850. * @type {boolean}
  77851. */
  77852. this._isZoomActive;
  77853. }
  77854. DataZoom.defaultOption = {
  77855. show: true,
  77856. // Icon group
  77857. icon: {
  77858. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  77859. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  77860. },
  77861. // `zoom`, `back`
  77862. title: clone(dataZoomLang.title)
  77863. };
  77864. var proto$6 = DataZoom.prototype;
  77865. proto$6.render = function (featureModel, ecModel, api, payload) {
  77866. this.model = featureModel;
  77867. this.ecModel = ecModel;
  77868. this.api = api;
  77869. updateZoomBtnStatus(featureModel, ecModel, this, payload, api);
  77870. updateBackBtnStatus(featureModel, ecModel);
  77871. };
  77872. proto$6.onclick = function (ecModel, api, type) {
  77873. handlers$1[type].call(this);
  77874. };
  77875. proto$6.remove = function (ecModel, api) {
  77876. this._brushController.unmount();
  77877. };
  77878. proto$6.dispose = function (ecModel, api) {
  77879. this._brushController.dispose();
  77880. };
  77881. /**
  77882. * @private
  77883. */
  77884. var handlers$1 = {
  77885. zoom: function () {
  77886. var nextActive = !this._isZoomActive;
  77887. this.api.dispatchAction({
  77888. type: 'takeGlobalCursor',
  77889. key: 'dataZoomSelect',
  77890. dataZoomSelectActive: nextActive
  77891. });
  77892. },
  77893. back: function () {
  77894. this._dispatchZoomAction(pop(this.ecModel));
  77895. }
  77896. };
  77897. /**
  77898. * @private
  77899. */
  77900. proto$6._onBrush = function (areas, opt) {
  77901. if (!opt.isEnd || !areas.length) {
  77902. return;
  77903. }
  77904. var snapshot = {};
  77905. var ecModel = this.ecModel;
  77906. this._brushController.updateCovers([]); // remove cover
  77907. var brushTargetManager = new BrushTargetManager(
  77908. retrieveAxisSetting(this.model.option), ecModel, {include: ['grid']}
  77909. );
  77910. brushTargetManager.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  77911. if (coordSys.type !== 'cartesian2d') {
  77912. return;
  77913. }
  77914. var brushType = area.brushType;
  77915. if (brushType === 'rect') {
  77916. setBatch('x', coordSys, coordRange[0]);
  77917. setBatch('y', coordSys, coordRange[1]);
  77918. }
  77919. else {
  77920. setBatch(({lineX: 'x', lineY: 'y'})[brushType], coordSys, coordRange);
  77921. }
  77922. });
  77923. push(ecModel, snapshot);
  77924. this._dispatchZoomAction(snapshot);
  77925. function setBatch(dimName, coordSys, minMax) {
  77926. var axis = coordSys.getAxis(dimName);
  77927. var axisModel = axis.model;
  77928. var dataZoomModel = findDataZoom(dimName, axisModel, ecModel);
  77929. // Restrict range.
  77930. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy(axisModel).getMinMaxSpan();
  77931. if (minMaxSpan.minValueSpan != null || minMaxSpan.maxValueSpan != null) {
  77932. minMax = sliderMove(
  77933. 0, minMax.slice(), axis.scale.getExtent(), 0,
  77934. minMaxSpan.minValueSpan, minMaxSpan.maxValueSpan
  77935. );
  77936. }
  77937. dataZoomModel && (snapshot[dataZoomModel.id] = {
  77938. dataZoomId: dataZoomModel.id,
  77939. startValue: minMax[0],
  77940. endValue: minMax[1]
  77941. });
  77942. }
  77943. function findDataZoom(dimName, axisModel, ecModel) {
  77944. var found;
  77945. ecModel.eachComponent({mainType: 'dataZoom', subType: 'select'}, function (dzModel) {
  77946. var has = dzModel.getAxisModel(dimName, axisModel.componentIndex);
  77947. has && (found = dzModel);
  77948. });
  77949. return found;
  77950. }
  77951. };
  77952. /**
  77953. * @private
  77954. */
  77955. proto$6._dispatchZoomAction = function (snapshot) {
  77956. var batch = [];
  77957. // Convert from hash map to array.
  77958. each$28(snapshot, function (batchItem, dataZoomId) {
  77959. batch.push(clone(batchItem));
  77960. });
  77961. batch.length && this.api.dispatchAction({
  77962. type: 'dataZoom',
  77963. from: this.uid,
  77964. batch: batch
  77965. });
  77966. };
  77967. function retrieveAxisSetting(option) {
  77968. var setting = {};
  77969. // Compatible with previous setting: null => all axis, false => no axis.
  77970. each$1(['xAxisIndex', 'yAxisIndex'], function (name) {
  77971. setting[name] = option[name];
  77972. setting[name] == null && (setting[name] = 'all');
  77973. (setting[name] === false || setting[name] === 'none') && (setting[name] = []);
  77974. });
  77975. return setting;
  77976. }
  77977. function updateBackBtnStatus(featureModel, ecModel) {
  77978. featureModel.setIconStatus(
  77979. 'back',
  77980. count(ecModel) > 1 ? 'emphasis' : 'normal'
  77981. );
  77982. }
  77983. function updateZoomBtnStatus(featureModel, ecModel, view, payload, api) {
  77984. var zoomActive = view._isZoomActive;
  77985. if (payload && payload.type === 'takeGlobalCursor') {
  77986. zoomActive = payload.key === 'dataZoomSelect'
  77987. ? payload.dataZoomSelectActive : false;
  77988. }
  77989. view._isZoomActive = zoomActive;
  77990. featureModel.setIconStatus('zoom', zoomActive ? 'emphasis' : 'normal');
  77991. var brushTargetManager = new BrushTargetManager(
  77992. retrieveAxisSetting(featureModel.option), ecModel, {include: ['grid']}
  77993. );
  77994. view._brushController
  77995. .setPanels(brushTargetManager.makePanelOpts(api, function (targetInfo) {
  77996. return (targetInfo.xAxisDeclared && !targetInfo.yAxisDeclared)
  77997. ? 'lineX'
  77998. : (!targetInfo.xAxisDeclared && targetInfo.yAxisDeclared)
  77999. ? 'lineY'
  78000. : 'rect';
  78001. }))
  78002. .enableBrush(
  78003. zoomActive
  78004. ? {
  78005. brushType: 'auto',
  78006. brushStyle: {
  78007. // FIXME user customized?
  78008. lineWidth: 0,
  78009. fill: 'rgba(0,0,0,0.2)'
  78010. }
  78011. }
  78012. : false
  78013. );
  78014. }
  78015. register$1('dataZoom', DataZoom);
  78016. // Create special dataZoom option for select
  78017. // FIXME consider the case of merge option, where axes options are not exists.
  78018. registerPreprocessor(function (option) {
  78019. if (!option) {
  78020. return;
  78021. }
  78022. var dataZoomOpts = option.dataZoom || (option.dataZoom = []);
  78023. if (!isArray(dataZoomOpts)) {
  78024. option.dataZoom = dataZoomOpts = [dataZoomOpts];
  78025. }
  78026. var toolboxOpt = option.toolbox;
  78027. if (toolboxOpt) {
  78028. // Assume there is only one toolbox
  78029. if (isArray(toolboxOpt)) {
  78030. toolboxOpt = toolboxOpt[0];
  78031. }
  78032. if (toolboxOpt && toolboxOpt.feature) {
  78033. var dataZoomOpt = toolboxOpt.feature.dataZoom;
  78034. // FIXME: If add dataZoom when setOption in merge mode,
  78035. // no axis info to be added. See `test/dataZoom-extreme.html`
  78036. addForAxis('xAxis', dataZoomOpt);
  78037. addForAxis('yAxis', dataZoomOpt);
  78038. }
  78039. }
  78040. function addForAxis(axisName, dataZoomOpt) {
  78041. if (!dataZoomOpt) {
  78042. return;
  78043. }
  78044. // Try not to modify model, because it is not merged yet.
  78045. var axisIndicesName = axisName + 'Index';
  78046. var givenAxisIndices = dataZoomOpt[axisIndicesName];
  78047. if (givenAxisIndices != null
  78048. && givenAxisIndices !== 'all'
  78049. && !isArray(givenAxisIndices)
  78050. ) {
  78051. givenAxisIndices = (givenAxisIndices === false || givenAxisIndices === 'none') ? [] : [givenAxisIndices];
  78052. }
  78053. forEachComponent(axisName, function (axisOpt, axisIndex) {
  78054. if (givenAxisIndices != null
  78055. && givenAxisIndices !== 'all'
  78056. && indexOf(givenAxisIndices, axisIndex) === -1
  78057. ) {
  78058. return;
  78059. }
  78060. var newOpt = {
  78061. type: 'select',
  78062. $fromToolbox: true,
  78063. // Id for merge mapping.
  78064. id: DATA_ZOOM_ID_BASE + axisName + axisIndex
  78065. };
  78066. // FIXME
  78067. // Only support one axis now.
  78068. newOpt[axisIndicesName] = axisIndex;
  78069. dataZoomOpts.push(newOpt);
  78070. });
  78071. }
  78072. function forEachComponent(mainType, cb) {
  78073. var opts = option[mainType];
  78074. if (!isArray(opts)) {
  78075. opts = opts ? [opts] : [];
  78076. }
  78077. each$28(opts, cb);
  78078. }
  78079. });
  78080. /*
  78081. * Licensed to the Apache Software Foundation (ASF) under one
  78082. * or more contributor license agreements. See the NOTICE file
  78083. * distributed with this work for additional information
  78084. * regarding copyright ownership. The ASF licenses this file
  78085. * to you under the Apache License, Version 2.0 (the
  78086. * "License"); you may not use this file except in compliance
  78087. * with the License. You may obtain a copy of the License at
  78088. *
  78089. * http://www.apache.org/licenses/LICENSE-2.0
  78090. *
  78091. * Unless required by applicable law or agreed to in writing,
  78092. * software distributed under the License is distributed on an
  78093. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  78094. * KIND, either express or implied. See the License for the
  78095. * specific language governing permissions and limitations
  78096. * under the License.
  78097. */
  78098. var restoreLang = lang.toolbox.restore;
  78099. function Restore(model) {
  78100. this.model = model;
  78101. }
  78102. Restore.defaultOption = {
  78103. show: true,
  78104. /* eslint-disable */
  78105. 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',
  78106. /* eslint-enable */
  78107. title: restoreLang.title
  78108. };
  78109. var proto$7 = Restore.prototype;
  78110. proto$7.onclick = function (ecModel, api, type) {
  78111. clear$1(ecModel);
  78112. api.dispatchAction({
  78113. type: 'restore',
  78114. from: this.uid
  78115. });
  78116. };
  78117. register$1('restore', Restore);
  78118. registerAction(
  78119. {type: 'restore', event: 'restore', update: 'prepareAndUpdate'},
  78120. function (payload, ecModel) {
  78121. ecModel.resetOption('recreate');
  78122. }
  78123. );
  78124. /*
  78125. * Licensed to the Apache Software Foundation (ASF) under one
  78126. * or more contributor license agreements. See the NOTICE file
  78127. * distributed with this work for additional information
  78128. * regarding copyright ownership. The ASF licenses this file
  78129. * to you under the Apache License, Version 2.0 (the
  78130. * "License"); you may not use this file except in compliance
  78131. * with the License. You may obtain a copy of the License at
  78132. *
  78133. * http://www.apache.org/licenses/LICENSE-2.0
  78134. *
  78135. * Unless required by applicable law or agreed to in writing,
  78136. * software distributed under the License is distributed on an
  78137. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  78138. * KIND, either express or implied. See the License for the
  78139. * specific language governing permissions and limitations
  78140. * under the License.
  78141. */
  78142. var urn = 'urn:schemas-microsoft-com:vml';
  78143. var win = typeof window === 'undefined' ? null : window;
  78144. var vmlInited = false;
  78145. var doc = win && win.document;
  78146. function createNode(tagName) {
  78147. return doCreateNode(tagName);
  78148. }
  78149. // Avoid assign to an exported variable, for transforming to cjs.
  78150. var doCreateNode;
  78151. if (doc && !env$1.canvasSupported) {
  78152. try {
  78153. !doc.namespaces.zrvml && doc.namespaces.add('zrvml', urn);
  78154. doCreateNode = function (tagName) {
  78155. return doc.createElement('<zrvml:' + tagName + ' class="zrvml">');
  78156. };
  78157. }
  78158. catch (e) {
  78159. doCreateNode = function (tagName) {
  78160. return doc.createElement('<' + tagName + ' xmlns="' + urn + '" class="zrvml">');
  78161. };
  78162. }
  78163. }
  78164. // From raphael
  78165. function initVML() {
  78166. if (vmlInited || !doc) {
  78167. return;
  78168. }
  78169. vmlInited = true;
  78170. var styleSheets = doc.styleSheets;
  78171. if (styleSheets.length < 31) {
  78172. doc.createStyleSheet().addRule('.zrvml', 'behavior:url(#default#VML)');
  78173. }
  78174. else {
  78175. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  78176. styleSheets[0].addRule('.zrvml', 'behavior:url(#default#VML)');
  78177. }
  78178. }
  78179. // http://www.w3.org/TR/NOTE-VML
  78180. // TODO Use proxy like svg instead of overwrite brush methods
  78181. var CMD$3 = PathProxy.CMD;
  78182. var round$4 = Math.round;
  78183. var sqrt = Math.sqrt;
  78184. var abs$1 = Math.abs;
  78185. var cos = Math.cos;
  78186. var sin = Math.sin;
  78187. var mathMax$8 = Math.max;
  78188. if (!env$1.canvasSupported) {
  78189. var comma = ',';
  78190. var imageTransformPrefix = 'progid:DXImageTransform.Microsoft';
  78191. var Z = 21600;
  78192. var Z2 = Z / 2;
  78193. var ZLEVEL_BASE = 100000;
  78194. var Z_BASE$1 = 1000;
  78195. var initRootElStyle = function (el) {
  78196. el.style.cssText = 'position:absolute;left:0;top:0;width:1px;height:1px;';
  78197. el.coordsize = Z + ',' + Z;
  78198. el.coordorigin = '0,0';
  78199. };
  78200. var encodeHtmlAttribute = function (s) {
  78201. return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
  78202. };
  78203. var rgb2Str = function (r, g, b) {
  78204. return 'rgb(' + [r, g, b].join(',') + ')';
  78205. };
  78206. var append = function (parent, child) {
  78207. if (child && parent && child.parentNode !== parent) {
  78208. parent.appendChild(child);
  78209. }
  78210. };
  78211. var remove = function (parent, child) {
  78212. if (child && parent && child.parentNode === parent) {
  78213. parent.removeChild(child);
  78214. }
  78215. };
  78216. var getZIndex = function (zlevel, z, z2) {
  78217. // z 的取值范围为 [0, 1000]
  78218. return (parseFloat(zlevel) || 0) * ZLEVEL_BASE + (parseFloat(z) || 0) * Z_BASE$1 + z2;
  78219. };
  78220. var parsePercent$3 = function (value, maxValue) {
  78221. if (typeof value === 'string') {
  78222. if (value.lastIndexOf('%') >= 0) {
  78223. return parseFloat(value) / 100 * maxValue;
  78224. }
  78225. return parseFloat(value);
  78226. }
  78227. return value;
  78228. };
  78229. /***************************************************
  78230. * PATH
  78231. **************************************************/
  78232. var setColorAndOpacity = function (el, color, opacity) {
  78233. var colorArr = parse(color);
  78234. opacity = +opacity;
  78235. if (isNaN(opacity)) {
  78236. opacity = 1;
  78237. }
  78238. if (colorArr) {
  78239. el.color = rgb2Str(colorArr[0], colorArr[1], colorArr[2]);
  78240. el.opacity = opacity * colorArr[3];
  78241. }
  78242. };
  78243. var getColorAndAlpha = function (color) {
  78244. var colorArr = parse(color);
  78245. return [
  78246. rgb2Str(colorArr[0], colorArr[1], colorArr[2]),
  78247. colorArr[3]
  78248. ];
  78249. };
  78250. var updateFillNode = function (el, style, zrEl) {
  78251. // TODO pattern
  78252. var fill = style.fill;
  78253. if (fill != null) {
  78254. // Modified from excanvas
  78255. if (fill instanceof Gradient) {
  78256. var gradientType;
  78257. var angle = 0;
  78258. var focus = [0, 0];
  78259. // additional offset
  78260. var shift = 0;
  78261. // scale factor for offset
  78262. var expansion = 1;
  78263. var rect = zrEl.getBoundingRect();
  78264. var rectWidth = rect.width;
  78265. var rectHeight = rect.height;
  78266. if (fill.type === 'linear') {
  78267. gradientType = 'gradient';
  78268. var transform = zrEl.transform;
  78269. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  78270. var p1 = [fill.x2 * rectWidth, fill.y2 * rectHeight];
  78271. if (transform) {
  78272. applyTransform(p0, p0, transform);
  78273. applyTransform(p1, p1, transform);
  78274. }
  78275. var dx = p1[0] - p0[0];
  78276. var dy = p1[1] - p0[1];
  78277. angle = Math.atan2(dx, dy) * 180 / Math.PI;
  78278. // The angle should be a non-negative number.
  78279. if (angle < 0) {
  78280. angle += 360;
  78281. }
  78282. // Very small angles produce an unexpected result because they are
  78283. // converted to a scientific notation string.
  78284. if (angle < 1e-6) {
  78285. angle = 0;
  78286. }
  78287. }
  78288. else {
  78289. gradientType = 'gradientradial';
  78290. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  78291. var transform = zrEl.transform;
  78292. var scale$$1 = zrEl.scale;
  78293. var width = rectWidth;
  78294. var height = rectHeight;
  78295. focus = [
  78296. // Percent in bounding rect
  78297. (p0[0] - rect.x) / width,
  78298. (p0[1] - rect.y) / height
  78299. ];
  78300. if (transform) {
  78301. applyTransform(p0, p0, transform);
  78302. }
  78303. width /= scale$$1[0] * Z;
  78304. height /= scale$$1[1] * Z;
  78305. var dimension = mathMax$8(width, height);
  78306. shift = 2 * 0 / dimension;
  78307. expansion = 2 * fill.r / dimension - shift;
  78308. }
  78309. // We need to sort the color stops in ascending order by offset,
  78310. // otherwise IE won't interpret it correctly.
  78311. var stops = fill.colorStops.slice();
  78312. stops.sort(function (cs1, cs2) {
  78313. return cs1.offset - cs2.offset;
  78314. });
  78315. var length$$1 = stops.length;
  78316. // Color and alpha list of first and last stop
  78317. var colorAndAlphaList = [];
  78318. var colors = [];
  78319. for (var i = 0; i < length$$1; i++) {
  78320. var stop = stops[i];
  78321. var colorAndAlpha = getColorAndAlpha(stop.color);
  78322. colors.push(stop.offset * expansion + shift + ' ' + colorAndAlpha[0]);
  78323. if (i === 0 || i === length$$1 - 1) {
  78324. colorAndAlphaList.push(colorAndAlpha);
  78325. }
  78326. }
  78327. if (length$$1 >= 2) {
  78328. var color1 = colorAndAlphaList[0][0];
  78329. var color2 = colorAndAlphaList[1][0];
  78330. var opacity1 = colorAndAlphaList[0][1] * style.opacity;
  78331. var opacity2 = colorAndAlphaList[1][1] * style.opacity;
  78332. el.type = gradientType;
  78333. el.method = 'none';
  78334. el.focus = '100%';
  78335. el.angle = angle;
  78336. el.color = color1;
  78337. el.color2 = color2;
  78338. el.colors = colors.join(',');
  78339. // When colors attribute is used, the meanings of opacity and o:opacity2
  78340. // are reversed.
  78341. el.opacity = opacity2;
  78342. // FIXME g_o_:opacity ?
  78343. el.opacity2 = opacity1;
  78344. }
  78345. if (gradientType === 'radial') {
  78346. el.focusposition = focus.join(',');
  78347. }
  78348. }
  78349. else {
  78350. // FIXME Change from Gradient fill to color fill
  78351. setColorAndOpacity(el, fill, style.opacity);
  78352. }
  78353. }
  78354. };
  78355. var updateStrokeNode = function (el, style) {
  78356. // if (style.lineJoin != null) {
  78357. // el.joinstyle = style.lineJoin;
  78358. // }
  78359. // if (style.miterLimit != null) {
  78360. // el.miterlimit = style.miterLimit * Z;
  78361. // }
  78362. // if (style.lineCap != null) {
  78363. // el.endcap = style.lineCap;
  78364. // }
  78365. if (style.lineDash != null) {
  78366. el.dashstyle = style.lineDash.join(' ');
  78367. }
  78368. if (style.stroke != null && !(style.stroke instanceof Gradient)) {
  78369. setColorAndOpacity(el, style.stroke, style.opacity);
  78370. }
  78371. };
  78372. var updateFillAndStroke = function (vmlEl, type, style, zrEl) {
  78373. var isFill = type === 'fill';
  78374. var el = vmlEl.getElementsByTagName(type)[0];
  78375. // Stroke must have lineWidth
  78376. if (style[type] != null && style[type] !== 'none' && (isFill || (!isFill && style.lineWidth))) {
  78377. vmlEl[isFill ? 'filled' : 'stroked'] = 'true';
  78378. // FIXME Remove before updating, or set `colors` will throw error
  78379. if (style[type] instanceof Gradient) {
  78380. remove(vmlEl, el);
  78381. }
  78382. if (!el) {
  78383. el = createNode(type);
  78384. }
  78385. isFill ? updateFillNode(el, style, zrEl) : updateStrokeNode(el, style);
  78386. append(vmlEl, el);
  78387. }
  78388. else {
  78389. vmlEl[isFill ? 'filled' : 'stroked'] = 'false';
  78390. remove(vmlEl, el);
  78391. }
  78392. };
  78393. var points$3 = [[], [], []];
  78394. var pathDataToString = function (path, m) {
  78395. var M = CMD$3.M;
  78396. var C = CMD$3.C;
  78397. var L = CMD$3.L;
  78398. var A = CMD$3.A;
  78399. var Q = CMD$3.Q;
  78400. var str = [];
  78401. var nPoint;
  78402. var cmdStr;
  78403. var cmd;
  78404. var i;
  78405. var xi;
  78406. var yi;
  78407. var data = path.data;
  78408. var dataLength = path.len();
  78409. for (i = 0; i < dataLength;) {
  78410. cmd = data[i++];
  78411. cmdStr = '';
  78412. nPoint = 0;
  78413. switch (cmd) {
  78414. case M:
  78415. cmdStr = ' m ';
  78416. nPoint = 1;
  78417. xi = data[i++];
  78418. yi = data[i++];
  78419. points$3[0][0] = xi;
  78420. points$3[0][1] = yi;
  78421. break;
  78422. case L:
  78423. cmdStr = ' l ';
  78424. nPoint = 1;
  78425. xi = data[i++];
  78426. yi = data[i++];
  78427. points$3[0][0] = xi;
  78428. points$3[0][1] = yi;
  78429. break;
  78430. case Q:
  78431. case C:
  78432. cmdStr = ' c ';
  78433. nPoint = 3;
  78434. var x1 = data[i++];
  78435. var y1 = data[i++];
  78436. var x2 = data[i++];
  78437. var y2 = data[i++];
  78438. var x3;
  78439. var y3;
  78440. if (cmd === Q) {
  78441. // Convert quadratic to cubic using degree elevation
  78442. x3 = x2;
  78443. y3 = y2;
  78444. x2 = (x2 + 2 * x1) / 3;
  78445. y2 = (y2 + 2 * y1) / 3;
  78446. x1 = (xi + 2 * x1) / 3;
  78447. y1 = (yi + 2 * y1) / 3;
  78448. }
  78449. else {
  78450. x3 = data[i++];
  78451. y3 = data[i++];
  78452. }
  78453. points$3[0][0] = x1;
  78454. points$3[0][1] = y1;
  78455. points$3[1][0] = x2;
  78456. points$3[1][1] = y2;
  78457. points$3[2][0] = x3;
  78458. points$3[2][1] = y3;
  78459. xi = x3;
  78460. yi = y3;
  78461. break;
  78462. case A:
  78463. var x = 0;
  78464. var y = 0;
  78465. var sx = 1;
  78466. var sy = 1;
  78467. var angle = 0;
  78468. if (m) {
  78469. // Extract SRT from matrix
  78470. x = m[4];
  78471. y = m[5];
  78472. sx = sqrt(m[0] * m[0] + m[1] * m[1]);
  78473. sy = sqrt(m[2] * m[2] + m[3] * m[3]);
  78474. angle = Math.atan2(-m[1] / sy, m[0] / sx);
  78475. }
  78476. var cx = data[i++];
  78477. var cy = data[i++];
  78478. var rx = data[i++];
  78479. var ry = data[i++];
  78480. var startAngle = data[i++] + angle;
  78481. var endAngle = data[i++] + startAngle + angle;
  78482. // FIXME
  78483. // var psi = data[i++];
  78484. i++;
  78485. var clockwise = data[i++];
  78486. var x0 = cx + cos(startAngle) * rx;
  78487. var y0 = cy + sin(startAngle) * ry;
  78488. var x1 = cx + cos(endAngle) * rx;
  78489. var y1 = cy + sin(endAngle) * ry;
  78490. var type = clockwise ? ' wa ' : ' at ';
  78491. if (Math.abs(x0 - x1) < 1e-4) {
  78492. // IE won't render arches drawn counter clockwise if x0 == x1.
  78493. if (Math.abs(endAngle - startAngle) > 1e-2) {
  78494. // Offset x0 by 1/80 of a pixel. Use something
  78495. // that can be represented in binary
  78496. if (clockwise) {
  78497. x0 += 270 / Z;
  78498. }
  78499. }
  78500. else {
  78501. // Avoid case draw full circle
  78502. if (Math.abs(y0 - cy) < 1e-4) {
  78503. if ((clockwise && x0 < cx) || (!clockwise && x0 > cx)) {
  78504. y1 -= 270 / Z;
  78505. }
  78506. else {
  78507. y1 += 270 / Z;
  78508. }
  78509. }
  78510. else if ((clockwise && y0 < cy) || (!clockwise && y0 > cy)) {
  78511. x1 += 270 / Z;
  78512. }
  78513. else {
  78514. x1 -= 270 / Z;
  78515. }
  78516. }
  78517. }
  78518. str.push(
  78519. type,
  78520. round$4(((cx - rx) * sx + x) * Z - Z2), comma,
  78521. round$4(((cy - ry) * sy + y) * Z - Z2), comma,
  78522. round$4(((cx + rx) * sx + x) * Z - Z2), comma,
  78523. round$4(((cy + ry) * sy + y) * Z - Z2), comma,
  78524. round$4((x0 * sx + x) * Z - Z2), comma,
  78525. round$4((y0 * sy + y) * Z - Z2), comma,
  78526. round$4((x1 * sx + x) * Z - Z2), comma,
  78527. round$4((y1 * sy + y) * Z - Z2)
  78528. );
  78529. xi = x1;
  78530. yi = y1;
  78531. break;
  78532. case CMD$3.R:
  78533. var p0 = points$3[0];
  78534. var p1 = points$3[1];
  78535. // x0, y0
  78536. p0[0] = data[i++];
  78537. p0[1] = data[i++];
  78538. // x1, y1
  78539. p1[0] = p0[0] + data[i++];
  78540. p1[1] = p0[1] + data[i++];
  78541. if (m) {
  78542. applyTransform(p0, p0, m);
  78543. applyTransform(p1, p1, m);
  78544. }
  78545. p0[0] = round$4(p0[0] * Z - Z2);
  78546. p1[0] = round$4(p1[0] * Z - Z2);
  78547. p0[1] = round$4(p0[1] * Z - Z2);
  78548. p1[1] = round$4(p1[1] * Z - Z2);
  78549. str.push(
  78550. // x0, y0
  78551. ' m ', p0[0], comma, p0[1],
  78552. // x1, y0
  78553. ' l ', p1[0], comma, p0[1],
  78554. // x1, y1
  78555. ' l ', p1[0], comma, p1[1],
  78556. // x0, y1
  78557. ' l ', p0[0], comma, p1[1]
  78558. );
  78559. break;
  78560. case CMD$3.Z:
  78561. // FIXME Update xi, yi
  78562. str.push(' x ');
  78563. }
  78564. if (nPoint > 0) {
  78565. str.push(cmdStr);
  78566. for (var k = 0; k < nPoint; k++) {
  78567. var p = points$3[k];
  78568. m && applyTransform(p, p, m);
  78569. // 不 round 会非常慢
  78570. str.push(
  78571. round$4(p[0] * Z - Z2), comma, round$4(p[1] * Z - Z2),
  78572. k < nPoint - 1 ? comma : ''
  78573. );
  78574. }
  78575. }
  78576. }
  78577. return str.join('');
  78578. };
  78579. // Rewrite the original path method
  78580. Path.prototype.brushVML = function (vmlRoot) {
  78581. var style = this.style;
  78582. var vmlEl = this._vmlEl;
  78583. if (!vmlEl) {
  78584. vmlEl = createNode('shape');
  78585. initRootElStyle(vmlEl);
  78586. this._vmlEl = vmlEl;
  78587. }
  78588. updateFillAndStroke(vmlEl, 'fill', style, this);
  78589. updateFillAndStroke(vmlEl, 'stroke', style, this);
  78590. var m = this.transform;
  78591. var needTransform = m != null;
  78592. var strokeEl = vmlEl.getElementsByTagName('stroke')[0];
  78593. if (strokeEl) {
  78594. var lineWidth = style.lineWidth;
  78595. // Get the line scale.
  78596. // Determinant of this.m_ means how much the area is enlarged by the
  78597. // transformation. So its square root can be used as a scale factor
  78598. // for width.
  78599. if (needTransform && !style.strokeNoScale) {
  78600. var det = m[0] * m[3] - m[1] * m[2];
  78601. lineWidth *= sqrt(abs$1(det));
  78602. }
  78603. strokeEl.weight = lineWidth + 'px';
  78604. }
  78605. var path = this.path || (this.path = new PathProxy());
  78606. if (this.__dirtyPath) {
  78607. path.beginPath();
  78608. path.subPixelOptimize = false;
  78609. this.buildPath(path, this.shape);
  78610. path.toStatic();
  78611. this.__dirtyPath = false;
  78612. }
  78613. vmlEl.path = pathDataToString(path, this.transform);
  78614. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  78615. // Append to root
  78616. append(vmlRoot, vmlEl);
  78617. // Text
  78618. if (style.text != null) {
  78619. this.drawRectText(vmlRoot, this.getBoundingRect());
  78620. }
  78621. else {
  78622. this.removeRectText(vmlRoot);
  78623. }
  78624. };
  78625. Path.prototype.onRemove = function (vmlRoot) {
  78626. remove(vmlRoot, this._vmlEl);
  78627. this.removeRectText(vmlRoot);
  78628. };
  78629. Path.prototype.onAdd = function (vmlRoot) {
  78630. append(vmlRoot, this._vmlEl);
  78631. this.appendRectText(vmlRoot);
  78632. };
  78633. /***************************************************
  78634. * IMAGE
  78635. **************************************************/
  78636. var isImage = function (img) {
  78637. // FIXME img instanceof Image 如果 img 是一个字符串的时候,IE8 下会报错
  78638. return (typeof img === 'object') && img.tagName && img.tagName.toUpperCase() === 'IMG';
  78639. // return img instanceof Image;
  78640. };
  78641. // Rewrite the original path method
  78642. ZImage.prototype.brushVML = function (vmlRoot) {
  78643. var style = this.style;
  78644. var image = style.image;
  78645. // Image original width, height
  78646. var ow;
  78647. var oh;
  78648. if (isImage(image)) {
  78649. var src = image.src;
  78650. if (src === this._imageSrc) {
  78651. ow = this._imageWidth;
  78652. oh = this._imageHeight;
  78653. }
  78654. else {
  78655. var imageRuntimeStyle = image.runtimeStyle;
  78656. var oldRuntimeWidth = imageRuntimeStyle.width;
  78657. var oldRuntimeHeight = imageRuntimeStyle.height;
  78658. imageRuntimeStyle.width = 'auto';
  78659. imageRuntimeStyle.height = 'auto';
  78660. // get the original size
  78661. ow = image.width;
  78662. oh = image.height;
  78663. // and remove overides
  78664. imageRuntimeStyle.width = oldRuntimeWidth;
  78665. imageRuntimeStyle.height = oldRuntimeHeight;
  78666. // Caching image original width, height and src
  78667. this._imageSrc = src;
  78668. this._imageWidth = ow;
  78669. this._imageHeight = oh;
  78670. }
  78671. image = src;
  78672. }
  78673. else {
  78674. if (image === this._imageSrc) {
  78675. ow = this._imageWidth;
  78676. oh = this._imageHeight;
  78677. }
  78678. }
  78679. if (!image) {
  78680. return;
  78681. }
  78682. var x = style.x || 0;
  78683. var y = style.y || 0;
  78684. var dw = style.width;
  78685. var dh = style.height;
  78686. var sw = style.sWidth;
  78687. var sh = style.sHeight;
  78688. var sx = style.sx || 0;
  78689. var sy = style.sy || 0;
  78690. var hasCrop = sw && sh;
  78691. var vmlEl = this._vmlEl;
  78692. if (!vmlEl) {
  78693. // FIXME 使用 group 在 left, top 都不是 0 的时候就无法显示了。
  78694. // vmlEl = vmlCore.createNode('group');
  78695. vmlEl = doc.createElement('div');
  78696. initRootElStyle(vmlEl);
  78697. this._vmlEl = vmlEl;
  78698. }
  78699. var vmlElStyle = vmlEl.style;
  78700. var hasRotation = false;
  78701. var m;
  78702. var scaleX = 1;
  78703. var scaleY = 1;
  78704. if (this.transform) {
  78705. m = this.transform;
  78706. scaleX = sqrt(m[0] * m[0] + m[1] * m[1]);
  78707. scaleY = sqrt(m[2] * m[2] + m[3] * m[3]);
  78708. hasRotation = m[1] || m[2];
  78709. }
  78710. if (hasRotation) {
  78711. // If filters are necessary (rotation exists), create them
  78712. // filters are bog-slow, so only create them if abbsolutely necessary
  78713. // The following check doesn't account for skews (which don't exist
  78714. // in the canvas spec (yet) anyway.
  78715. // From excanvas
  78716. var p0 = [x, y];
  78717. var p1 = [x + dw, y];
  78718. var p2 = [x, y + dh];
  78719. var p3 = [x + dw, y + dh];
  78720. applyTransform(p0, p0, m);
  78721. applyTransform(p1, p1, m);
  78722. applyTransform(p2, p2, m);
  78723. applyTransform(p3, p3, m);
  78724. var maxX = mathMax$8(p0[0], p1[0], p2[0], p3[0]);
  78725. var maxY = mathMax$8(p0[1], p1[1], p2[1], p3[1]);
  78726. var transformFilter = [];
  78727. transformFilter.push('M11=', m[0] / scaleX, comma,
  78728. 'M12=', m[2] / scaleY, comma,
  78729. 'M21=', m[1] / scaleX, comma,
  78730. 'M22=', m[3] / scaleY, comma,
  78731. 'Dx=', round$4(x * scaleX + m[4]), comma,
  78732. 'Dy=', round$4(y * scaleY + m[5]));
  78733. vmlElStyle.padding = '0 ' + round$4(maxX) + 'px ' + round$4(maxY) + 'px 0';
  78734. // FIXME DXImageTransform 在 IE11 的兼容模式下不起作用
  78735. vmlElStyle.filter = imageTransformPrefix + '.Matrix('
  78736. + transformFilter.join('') + ', SizingMethod=clip)';
  78737. }
  78738. else {
  78739. if (m) {
  78740. x = x * scaleX + m[4];
  78741. y = y * scaleY + m[5];
  78742. }
  78743. vmlElStyle.filter = '';
  78744. vmlElStyle.left = round$4(x) + 'px';
  78745. vmlElStyle.top = round$4(y) + 'px';
  78746. }
  78747. var imageEl = this._imageEl;
  78748. var cropEl = this._cropEl;
  78749. if (!imageEl) {
  78750. imageEl = doc.createElement('div');
  78751. this._imageEl = imageEl;
  78752. }
  78753. var imageELStyle = imageEl.style;
  78754. if (hasCrop) {
  78755. // Needs know image original width and height
  78756. if (!(ow && oh)) {
  78757. var tmpImage = new Image();
  78758. var self = this;
  78759. tmpImage.onload = function () {
  78760. tmpImage.onload = null;
  78761. ow = tmpImage.width;
  78762. oh = tmpImage.height;
  78763. // Adjust image width and height to fit the ratio destinationSize / sourceSize
  78764. imageELStyle.width = round$4(scaleX * ow * dw / sw) + 'px';
  78765. imageELStyle.height = round$4(scaleY * oh * dh / sh) + 'px';
  78766. // Caching image original width, height and src
  78767. self._imageWidth = ow;
  78768. self._imageHeight = oh;
  78769. self._imageSrc = image;
  78770. };
  78771. tmpImage.src = image;
  78772. }
  78773. else {
  78774. imageELStyle.width = round$4(scaleX * ow * dw / sw) + 'px';
  78775. imageELStyle.height = round$4(scaleY * oh * dh / sh) + 'px';
  78776. }
  78777. if (!cropEl) {
  78778. cropEl = doc.createElement('div');
  78779. cropEl.style.overflow = 'hidden';
  78780. this._cropEl = cropEl;
  78781. }
  78782. var cropElStyle = cropEl.style;
  78783. cropElStyle.width = round$4((dw + sx * dw / sw) * scaleX);
  78784. cropElStyle.height = round$4((dh + sy * dh / sh) * scaleY);
  78785. cropElStyle.filter = imageTransformPrefix + '.Matrix(Dx='
  78786. + (-sx * dw / sw * scaleX) + ',Dy=' + (-sy * dh / sh * scaleY) + ')';
  78787. if (!cropEl.parentNode) {
  78788. vmlEl.appendChild(cropEl);
  78789. }
  78790. if (imageEl.parentNode !== cropEl) {
  78791. cropEl.appendChild(imageEl);
  78792. }
  78793. }
  78794. else {
  78795. imageELStyle.width = round$4(scaleX * dw) + 'px';
  78796. imageELStyle.height = round$4(scaleY * dh) + 'px';
  78797. vmlEl.appendChild(imageEl);
  78798. if (cropEl && cropEl.parentNode) {
  78799. vmlEl.removeChild(cropEl);
  78800. this._cropEl = null;
  78801. }
  78802. }
  78803. var filterStr = '';
  78804. var alpha = style.opacity;
  78805. if (alpha < 1) {
  78806. filterStr += '.Alpha(opacity=' + round$4(alpha * 100) + ') ';
  78807. }
  78808. filterStr += imageTransformPrefix + '.AlphaImageLoader(src=' + image + ', SizingMethod=scale)';
  78809. imageELStyle.filter = filterStr;
  78810. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  78811. // Append to root
  78812. append(vmlRoot, vmlEl);
  78813. // Text
  78814. if (style.text != null) {
  78815. this.drawRectText(vmlRoot, this.getBoundingRect());
  78816. }
  78817. };
  78818. ZImage.prototype.onRemove = function (vmlRoot) {
  78819. remove(vmlRoot, this._vmlEl);
  78820. this._vmlEl = null;
  78821. this._cropEl = null;
  78822. this._imageEl = null;
  78823. this.removeRectText(vmlRoot);
  78824. };
  78825. ZImage.prototype.onAdd = function (vmlRoot) {
  78826. append(vmlRoot, this._vmlEl);
  78827. this.appendRectText(vmlRoot);
  78828. };
  78829. /***************************************************
  78830. * TEXT
  78831. **************************************************/
  78832. var DEFAULT_STYLE_NORMAL = 'normal';
  78833. var fontStyleCache = {};
  78834. var fontStyleCacheCount = 0;
  78835. var MAX_FONT_CACHE_SIZE = 100;
  78836. var fontEl = document.createElement('div');
  78837. var getFontStyle = function (fontString) {
  78838. var fontStyle = fontStyleCache[fontString];
  78839. if (!fontStyle) {
  78840. // Clear cache
  78841. if (fontStyleCacheCount > MAX_FONT_CACHE_SIZE) {
  78842. fontStyleCacheCount = 0;
  78843. fontStyleCache = {};
  78844. }
  78845. var style = fontEl.style;
  78846. var fontFamily;
  78847. try {
  78848. style.font = fontString;
  78849. fontFamily = style.fontFamily.split(',')[0];
  78850. }
  78851. catch (e) {
  78852. }
  78853. fontStyle = {
  78854. style: style.fontStyle || DEFAULT_STYLE_NORMAL,
  78855. variant: style.fontVariant || DEFAULT_STYLE_NORMAL,
  78856. weight: style.fontWeight || DEFAULT_STYLE_NORMAL,
  78857. size: parseFloat(style.fontSize || 12) | 0,
  78858. family: fontFamily || 'Microsoft YaHei'
  78859. };
  78860. fontStyleCache[fontString] = fontStyle;
  78861. fontStyleCacheCount++;
  78862. }
  78863. return fontStyle;
  78864. };
  78865. var textMeasureEl;
  78866. // Overwrite measure text method
  78867. $override$1('measureText', function (text, textFont) {
  78868. var doc$$1 = doc;
  78869. if (!textMeasureEl) {
  78870. textMeasureEl = doc$$1.createElement('div');
  78871. textMeasureEl.style.cssText = 'position:absolute;top:-20000px;left:0;'
  78872. + 'padding:0;margin:0;border:none;white-space:pre;';
  78873. doc.body.appendChild(textMeasureEl);
  78874. }
  78875. try {
  78876. textMeasureEl.style.font = textFont;
  78877. }
  78878. catch (ex) {
  78879. // Ignore failures to set to invalid font.
  78880. }
  78881. textMeasureEl.innerHTML = '';
  78882. // Don't use innerHTML or innerText because they allow markup/whitespace.
  78883. textMeasureEl.appendChild(doc$$1.createTextNode(text));
  78884. return {
  78885. width: textMeasureEl.offsetWidth
  78886. };
  78887. });
  78888. var tmpRect$2 = new BoundingRect();
  78889. var drawRectText = function (vmlRoot, rect, textRect, fromTextEl) {
  78890. var style = this.style;
  78891. // Optimize, avoid normalize every time.
  78892. this.__dirty && normalizeTextStyle(style, true);
  78893. var text = style.text;
  78894. // Convert to string
  78895. text != null && (text += '');
  78896. if (!text) {
  78897. return;
  78898. }
  78899. // Convert rich text to plain text. Rich text is not supported in
  78900. // IE8-, but tags in rich text template will be removed.
  78901. if (style.rich) {
  78902. var contentBlock = parseRichText(text, style);
  78903. text = [];
  78904. for (var i = 0; i < contentBlock.lines.length; i++) {
  78905. var tokens = contentBlock.lines[i].tokens;
  78906. var textLine = [];
  78907. for (var j = 0; j < tokens.length; j++) {
  78908. textLine.push(tokens[j].text);
  78909. }
  78910. text.push(textLine.join(''));
  78911. }
  78912. text = text.join('\n');
  78913. }
  78914. var x;
  78915. var y;
  78916. var align = style.textAlign;
  78917. var verticalAlign = style.textVerticalAlign;
  78918. var fontStyle = getFontStyle(style.font);
  78919. // FIXME encodeHtmlAttribute ?
  78920. var font = fontStyle.style + ' ' + fontStyle.variant + ' ' + fontStyle.weight + ' '
  78921. + fontStyle.size + 'px "' + fontStyle.family + '"';
  78922. textRect = textRect || getBoundingRect(
  78923. text, font, align, verticalAlign, style.textPadding, style.textLineHeight
  78924. );
  78925. // Transform rect to view space
  78926. var m = this.transform;
  78927. // Ignore transform for text in other element
  78928. if (m && !fromTextEl) {
  78929. tmpRect$2.copy(rect);
  78930. tmpRect$2.applyTransform(m);
  78931. rect = tmpRect$2;
  78932. }
  78933. if (!fromTextEl) {
  78934. var textPosition = style.textPosition;
  78935. var distance$$1 = style.textDistance;
  78936. // Text position represented by coord
  78937. if (textPosition instanceof Array) {
  78938. x = rect.x + parsePercent$3(textPosition[0], rect.width);
  78939. y = rect.y + parsePercent$3(textPosition[1], rect.height);
  78940. align = align || 'left';
  78941. }
  78942. else {
  78943. var res = adjustTextPositionOnRect(
  78944. textPosition, rect, distance$$1
  78945. );
  78946. x = res.x;
  78947. y = res.y;
  78948. // Default align and baseline when has textPosition
  78949. align = align || res.textAlign;
  78950. verticalAlign = verticalAlign || res.textVerticalAlign;
  78951. }
  78952. }
  78953. else {
  78954. x = rect.x;
  78955. y = rect.y;
  78956. }
  78957. x = adjustTextX(x, textRect.width, align);
  78958. y = adjustTextY(y, textRect.height, verticalAlign);
  78959. // Force baseline 'middle'
  78960. y += textRect.height / 2;
  78961. // var fontSize = fontStyle.size;
  78962. // 1.75 is an arbitrary number, as there is no info about the text baseline
  78963. // switch (baseline) {
  78964. // case 'hanging':
  78965. // case 'top':
  78966. // y += fontSize / 1.75;
  78967. // break;
  78968. // case 'middle':
  78969. // break;
  78970. // default:
  78971. // // case null:
  78972. // // case 'alphabetic':
  78973. // // case 'ideographic':
  78974. // // case 'bottom':
  78975. // y -= fontSize / 2.25;
  78976. // break;
  78977. // }
  78978. // switch (align) {
  78979. // case 'left':
  78980. // break;
  78981. // case 'center':
  78982. // x -= textRect.width / 2;
  78983. // break;
  78984. // case 'right':
  78985. // x -= textRect.width;
  78986. // break;
  78987. // case 'end':
  78988. // align = elementStyle.direction == 'ltr' ? 'right' : 'left';
  78989. // break;
  78990. // case 'start':
  78991. // align = elementStyle.direction == 'rtl' ? 'right' : 'left';
  78992. // break;
  78993. // default:
  78994. // align = 'left';
  78995. // }
  78996. var createNode$$1 = createNode;
  78997. var textVmlEl = this._textVmlEl;
  78998. var pathEl;
  78999. var textPathEl;
  79000. var skewEl;
  79001. if (!textVmlEl) {
  79002. textVmlEl = createNode$$1('line');
  79003. pathEl = createNode$$1('path');
  79004. textPathEl = createNode$$1('textpath');
  79005. skewEl = createNode$$1('skew');
  79006. // FIXME Why here is not cammel case
  79007. // Align 'center' seems wrong
  79008. textPathEl.style['v-text-align'] = 'left';
  79009. initRootElStyle(textVmlEl);
  79010. pathEl.textpathok = true;
  79011. textPathEl.on = true;
  79012. textVmlEl.from = '0 0';
  79013. textVmlEl.to = '1000 0.05';
  79014. append(textVmlEl, skewEl);
  79015. append(textVmlEl, pathEl);
  79016. append(textVmlEl, textPathEl);
  79017. this._textVmlEl = textVmlEl;
  79018. }
  79019. else {
  79020. // 这里是在前面 appendChild 保证顺序的前提下
  79021. skewEl = textVmlEl.firstChild;
  79022. pathEl = skewEl.nextSibling;
  79023. textPathEl = pathEl.nextSibling;
  79024. }
  79025. var coords = [x, y];
  79026. var textVmlElStyle = textVmlEl.style;
  79027. // Ignore transform for text in other element
  79028. if (m && fromTextEl) {
  79029. applyTransform(coords, coords, m);
  79030. skewEl.on = true;
  79031. skewEl.matrix = m[0].toFixed(3) + comma + m[2].toFixed(3) + comma
  79032. + m[1].toFixed(3) + comma + m[3].toFixed(3) + ',0,0';
  79033. // Text position
  79034. skewEl.offset = (round$4(coords[0]) || 0) + ',' + (round$4(coords[1]) || 0);
  79035. // Left top point as origin
  79036. skewEl.origin = '0 0';
  79037. textVmlElStyle.left = '0px';
  79038. textVmlElStyle.top = '0px';
  79039. }
  79040. else {
  79041. skewEl.on = false;
  79042. textVmlElStyle.left = round$4(x) + 'px';
  79043. textVmlElStyle.top = round$4(y) + 'px';
  79044. }
  79045. textPathEl.string = encodeHtmlAttribute(text);
  79046. // TODO
  79047. try {
  79048. textPathEl.style.font = font;
  79049. }
  79050. // Error font format
  79051. catch (e) {}
  79052. updateFillAndStroke(textVmlEl, 'fill', {
  79053. fill: style.textFill,
  79054. opacity: style.opacity
  79055. }, this);
  79056. updateFillAndStroke(textVmlEl, 'stroke', {
  79057. stroke: style.textStroke,
  79058. opacity: style.opacity,
  79059. lineDash: style.lineDash
  79060. }, this);
  79061. textVmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  79062. // Attached to root
  79063. append(vmlRoot, textVmlEl);
  79064. };
  79065. var removeRectText = function (vmlRoot) {
  79066. remove(vmlRoot, this._textVmlEl);
  79067. this._textVmlEl = null;
  79068. };
  79069. var appendRectText = function (vmlRoot) {
  79070. append(vmlRoot, this._textVmlEl);
  79071. };
  79072. var list = [RectText, Displayable, ZImage, Path, Text];
  79073. // In case Displayable has been mixed in RectText
  79074. for (var i$3 = 0; i$3 < list.length; i$3++) {
  79075. var proto$8 = list[i$3].prototype;
  79076. proto$8.drawRectText = drawRectText;
  79077. proto$8.removeRectText = removeRectText;
  79078. proto$8.appendRectText = appendRectText;
  79079. }
  79080. Text.prototype.brushVML = function (vmlRoot) {
  79081. var style = this.style;
  79082. if (style.text != null) {
  79083. this.drawRectText(vmlRoot, {
  79084. x: style.x || 0, y: style.y || 0,
  79085. width: 0, height: 0
  79086. }, this.getBoundingRect(), true);
  79087. }
  79088. else {
  79089. this.removeRectText(vmlRoot);
  79090. }
  79091. };
  79092. Text.prototype.onRemove = function (vmlRoot) {
  79093. this.removeRectText(vmlRoot);
  79094. };
  79095. Text.prototype.onAdd = function (vmlRoot) {
  79096. this.appendRectText(vmlRoot);
  79097. };
  79098. }
  79099. /**
  79100. * VML Painter.
  79101. *
  79102. * @module zrender/vml/Painter
  79103. */
  79104. function parseInt10$1(val) {
  79105. return parseInt(val, 10);
  79106. }
  79107. /**
  79108. * @alias module:zrender/vml/Painter
  79109. */
  79110. function VMLPainter(root, storage) {
  79111. initVML();
  79112. this.root = root;
  79113. this.storage = storage;
  79114. var vmlViewport = document.createElement('div');
  79115. var vmlRoot = document.createElement('div');
  79116. vmlViewport.style.cssText = 'display:inline-block;overflow:hidden;position:relative;width:300px;height:150px;';
  79117. vmlRoot.style.cssText = 'position:absolute;left:0;top:0;';
  79118. root.appendChild(vmlViewport);
  79119. this._vmlRoot = vmlRoot;
  79120. this._vmlViewport = vmlViewport;
  79121. this.resize();
  79122. // Modify storage
  79123. var oldDelFromStorage = storage.delFromStorage;
  79124. var oldAddToStorage = storage.addToStorage;
  79125. storage.delFromStorage = function (el) {
  79126. oldDelFromStorage.call(storage, el);
  79127. if (el) {
  79128. el.onRemove && el.onRemove(vmlRoot);
  79129. }
  79130. };
  79131. storage.addToStorage = function (el) {
  79132. // Displayable already has a vml node
  79133. el.onAdd && el.onAdd(vmlRoot);
  79134. oldAddToStorage.call(storage, el);
  79135. };
  79136. this._firstPaint = true;
  79137. }
  79138. VMLPainter.prototype = {
  79139. constructor: VMLPainter,
  79140. getType: function () {
  79141. return 'vml';
  79142. },
  79143. /**
  79144. * @return {HTMLDivElement}
  79145. */
  79146. getViewportRoot: function () {
  79147. return this._vmlViewport;
  79148. },
  79149. getViewportRootOffset: function () {
  79150. var viewportRoot = this.getViewportRoot();
  79151. if (viewportRoot) {
  79152. return {
  79153. offsetLeft: viewportRoot.offsetLeft || 0,
  79154. offsetTop: viewportRoot.offsetTop || 0
  79155. };
  79156. }
  79157. },
  79158. /**
  79159. * 刷新
  79160. */
  79161. refresh: function () {
  79162. var list = this.storage.getDisplayList(true, true);
  79163. this._paintList(list);
  79164. },
  79165. _paintList: function (list) {
  79166. var vmlRoot = this._vmlRoot;
  79167. for (var i = 0; i < list.length; i++) {
  79168. var el = list[i];
  79169. if (el.invisible || el.ignore) {
  79170. if (!el.__alreadyNotVisible) {
  79171. el.onRemove(vmlRoot);
  79172. }
  79173. // Set as already invisible
  79174. el.__alreadyNotVisible = true;
  79175. }
  79176. else {
  79177. if (el.__alreadyNotVisible) {
  79178. el.onAdd(vmlRoot);
  79179. }
  79180. el.__alreadyNotVisible = false;
  79181. if (el.__dirty) {
  79182. el.beforeBrush && el.beforeBrush();
  79183. (el.brushVML || el.brush).call(el, vmlRoot);
  79184. el.afterBrush && el.afterBrush();
  79185. }
  79186. }
  79187. el.__dirty = false;
  79188. }
  79189. if (this._firstPaint) {
  79190. // Detached from document at first time
  79191. // to avoid page refreshing too many times
  79192. // FIXME 如果每次都先 removeChild 可能会导致一些填充和描边的效果改变
  79193. this._vmlViewport.appendChild(vmlRoot);
  79194. this._firstPaint = false;
  79195. }
  79196. },
  79197. resize: function (width, height) {
  79198. var width = width == null ? this._getWidth() : width;
  79199. var height = height == null ? this._getHeight() : height;
  79200. if (this._width !== width || this._height !== height) {
  79201. this._width = width;
  79202. this._height = height;
  79203. var vmlViewportStyle = this._vmlViewport.style;
  79204. vmlViewportStyle.width = width + 'px';
  79205. vmlViewportStyle.height = height + 'px';
  79206. }
  79207. },
  79208. dispose: function () {
  79209. this.root.innerHTML = '';
  79210. this._vmlRoot =
  79211. this._vmlViewport =
  79212. this.storage = null;
  79213. },
  79214. getWidth: function () {
  79215. return this._width;
  79216. },
  79217. getHeight: function () {
  79218. return this._height;
  79219. },
  79220. clear: function () {
  79221. if (this._vmlViewport) {
  79222. this.root.removeChild(this._vmlViewport);
  79223. }
  79224. },
  79225. _getWidth: function () {
  79226. var root = this.root;
  79227. var stl = root.currentStyle;
  79228. return ((root.clientWidth || parseInt10$1(stl.width))
  79229. - parseInt10$1(stl.paddingLeft)
  79230. - parseInt10$1(stl.paddingRight)) | 0;
  79231. },
  79232. _getHeight: function () {
  79233. var root = this.root;
  79234. var stl = root.currentStyle;
  79235. return ((root.clientHeight || parseInt10$1(stl.height))
  79236. - parseInt10$1(stl.paddingTop)
  79237. - parseInt10$1(stl.paddingBottom)) | 0;
  79238. }
  79239. };
  79240. // Not supported methods
  79241. function createMethodNotSupport(method) {
  79242. return function () {
  79243. zrLog('In IE8.0 VML mode painter not support method "' + method + '"');
  79244. };
  79245. }
  79246. // Unsupported methods
  79247. each$1([
  79248. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuiltinLayer', 'eachOtherLayer', 'getLayers',
  79249. 'modLayer', 'delLayer', 'clearLayer', 'toDataURL', 'pathToImage'
  79250. ], function (name) {
  79251. VMLPainter.prototype[name] = createMethodNotSupport(name);
  79252. });
  79253. registerPainter('vml', VMLPainter);
  79254. var svgURI = 'http://www.w3.org/2000/svg';
  79255. function createElement(name) {
  79256. return document.createElementNS(svgURI, name);
  79257. }
  79258. // TODO
  79259. // 1. shadow
  79260. // 2. Image: sx, sy, sw, sh
  79261. var CMD$4 = PathProxy.CMD;
  79262. var arrayJoin = Array.prototype.join;
  79263. var NONE = 'none';
  79264. var mathRound = Math.round;
  79265. var mathSin$3 = Math.sin;
  79266. var mathCos$3 = Math.cos;
  79267. var PI$5 = Math.PI;
  79268. var PI2$7 = Math.PI * 2;
  79269. var degree = 180 / PI$5;
  79270. var EPSILON$4 = 1e-4;
  79271. function round4(val) {
  79272. return mathRound(val * 1e4) / 1e4;
  79273. }
  79274. function isAroundZero$1(val) {
  79275. return val < EPSILON$4 && val > -EPSILON$4;
  79276. }
  79277. function pathHasFill(style, isText) {
  79278. var fill = isText ? style.textFill : style.fill;
  79279. return fill != null && fill !== NONE;
  79280. }
  79281. function pathHasStroke(style, isText) {
  79282. var stroke = isText ? style.textStroke : style.stroke;
  79283. return stroke != null && stroke !== NONE;
  79284. }
  79285. function setTransform(svgEl, m) {
  79286. if (m) {
  79287. attr(svgEl, 'transform', 'matrix(' + arrayJoin.call(m, ',') + ')');
  79288. }
  79289. }
  79290. function attr(el, key, val) {
  79291. if (!val || val.type !== 'linear' && val.type !== 'radial') {
  79292. // Don't set attribute for gradient, since it need new dom nodes
  79293. el.setAttribute(key, val);
  79294. }
  79295. }
  79296. function attrXLink(el, key, val) {
  79297. el.setAttributeNS('http://www.w3.org/1999/xlink', key, val);
  79298. }
  79299. function bindStyle(svgEl, style, isText, el) {
  79300. if (pathHasFill(style, isText)) {
  79301. var fill = isText ? style.textFill : style.fill;
  79302. fill = fill === 'transparent' ? NONE : fill;
  79303. /**
  79304. * FIXME:
  79305. * This is a temporary fix for Chrome's clipping bug
  79306. * that happens when a clip-path is referring another one.
  79307. * This fix should be used before Chrome's bug is fixed.
  79308. * For an element that has clip-path, and fill is none,
  79309. * set it to be "rgba(0, 0, 0, 0.002)" will hide the element.
  79310. * Otherwise, it will show black fill color.
  79311. * 0.002 is used because this won't work for alpha values smaller
  79312. * than 0.002.
  79313. *
  79314. * See
  79315. * https://bugs.chromium.org/p/chromium/issues/detail?id=659790
  79316. * for more information.
  79317. */
  79318. if (svgEl.getAttribute('clip-path') !== 'none' && fill === NONE) {
  79319. fill = 'rgba(0, 0, 0, 0.002)';
  79320. }
  79321. attr(svgEl, 'fill', fill);
  79322. attr(svgEl, 'fill-opacity', style.fillOpacity != null ? style.fillOpacity * style.opacity : style.opacity);
  79323. }
  79324. else {
  79325. attr(svgEl, 'fill', NONE);
  79326. }
  79327. if (pathHasStroke(style, isText)) {
  79328. var stroke = isText ? style.textStroke : style.stroke;
  79329. stroke = stroke === 'transparent' ? NONE : stroke;
  79330. attr(svgEl, 'stroke', stroke);
  79331. var strokeWidth = isText
  79332. ? style.textStrokeWidth
  79333. : style.lineWidth;
  79334. var strokeScale = !isText && style.strokeNoScale
  79335. ? el.getLineScale()
  79336. : 1;
  79337. attr(svgEl, 'stroke-width', strokeWidth / strokeScale);
  79338. // stroke then fill for text; fill then stroke for others
  79339. attr(svgEl, 'paint-order', isText ? 'stroke' : 'fill');
  79340. attr(svgEl, 'stroke-opacity', style.strokeOpacity != null ? style.strokeOpacity : style.opacity);
  79341. var lineDash = style.lineDash;
  79342. if (lineDash) {
  79343. attr(svgEl, 'stroke-dasharray', style.lineDash.join(','));
  79344. attr(svgEl, 'stroke-dashoffset', mathRound(style.lineDashOffset || 0));
  79345. }
  79346. else {
  79347. attr(svgEl, 'stroke-dasharray', '');
  79348. }
  79349. // PENDING
  79350. style.lineCap && attr(svgEl, 'stroke-linecap', style.lineCap);
  79351. style.lineJoin && attr(svgEl, 'stroke-linejoin', style.lineJoin);
  79352. style.miterLimit && attr(svgEl, 'stroke-miterlimit', style.miterLimit);
  79353. }
  79354. else {
  79355. attr(svgEl, 'stroke', NONE);
  79356. }
  79357. }
  79358. /***************************************************
  79359. * PATH
  79360. **************************************************/
  79361. function pathDataToString$1(path) {
  79362. var str = [];
  79363. var data = path.data;
  79364. var dataLength = path.len();
  79365. for (var i = 0; i < dataLength;) {
  79366. var cmd = data[i++];
  79367. var cmdStr = '';
  79368. var nData = 0;
  79369. switch (cmd) {
  79370. case CMD$4.M:
  79371. cmdStr = 'M';
  79372. nData = 2;
  79373. break;
  79374. case CMD$4.L:
  79375. cmdStr = 'L';
  79376. nData = 2;
  79377. break;
  79378. case CMD$4.Q:
  79379. cmdStr = 'Q';
  79380. nData = 4;
  79381. break;
  79382. case CMD$4.C:
  79383. cmdStr = 'C';
  79384. nData = 6;
  79385. break;
  79386. case CMD$4.A:
  79387. var cx = data[i++];
  79388. var cy = data[i++];
  79389. var rx = data[i++];
  79390. var ry = data[i++];
  79391. var theta = data[i++];
  79392. var dTheta = data[i++];
  79393. var psi = data[i++];
  79394. var clockwise = data[i++];
  79395. var dThetaPositive = Math.abs(dTheta);
  79396. var isCircle = isAroundZero$1(dThetaPositive - PI2$7)
  79397. && !isAroundZero$1(dThetaPositive);
  79398. var large = false;
  79399. if (dThetaPositive >= PI2$7) {
  79400. large = true;
  79401. }
  79402. else if (isAroundZero$1(dThetaPositive)) {
  79403. large = false;
  79404. }
  79405. else {
  79406. large = (dTheta > -PI$5 && dTheta < 0 || dTheta > PI$5)
  79407. === !!clockwise;
  79408. }
  79409. var x0 = round4(cx + rx * mathCos$3(theta));
  79410. var y0 = round4(cy + ry * mathSin$3(theta));
  79411. // It will not draw if start point and end point are exactly the same
  79412. // We need to shift the end point with a small value
  79413. // FIXME A better way to draw circle ?
  79414. if (isCircle) {
  79415. if (clockwise) {
  79416. dTheta = PI2$7 - 1e-4;
  79417. }
  79418. else {
  79419. dTheta = -PI2$7 + 1e-4;
  79420. }
  79421. large = true;
  79422. if (i === 9) {
  79423. // Move to (x0, y0) only when CMD.A comes at the
  79424. // first position of a shape.
  79425. // For instance, when drawing a ring, CMD.A comes
  79426. // after CMD.M, so it's unnecessary to move to
  79427. // (x0, y0).
  79428. str.push('M', x0, y0);
  79429. }
  79430. }
  79431. var x = round4(cx + rx * mathCos$3(theta + dTheta));
  79432. var y = round4(cy + ry * mathSin$3(theta + dTheta));
  79433. // FIXME Ellipse
  79434. str.push('A', round4(rx), round4(ry),
  79435. mathRound(psi * degree), +large, +clockwise, x, y);
  79436. break;
  79437. case CMD$4.Z:
  79438. cmdStr = 'Z';
  79439. break;
  79440. case CMD$4.R:
  79441. var x = round4(data[i++]);
  79442. var y = round4(data[i++]);
  79443. var w = round4(data[i++]);
  79444. var h = round4(data[i++]);
  79445. str.push(
  79446. 'M', x, y,
  79447. 'L', x + w, y,
  79448. 'L', x + w, y + h,
  79449. 'L', x, y + h,
  79450. 'L', x, y
  79451. );
  79452. break;
  79453. }
  79454. cmdStr && str.push(cmdStr);
  79455. for (var j = 0; j < nData; j++) {
  79456. // PENDING With scale
  79457. str.push(round4(data[i++]));
  79458. }
  79459. }
  79460. return str.join(' ');
  79461. }
  79462. var svgPath = {};
  79463. svgPath.brush = function (el) {
  79464. var style = el.style;
  79465. var svgEl = el.__svgEl;
  79466. if (!svgEl) {
  79467. svgEl = createElement('path');
  79468. el.__svgEl = svgEl;
  79469. }
  79470. if (!el.path) {
  79471. el.createPathProxy();
  79472. }
  79473. var path = el.path;
  79474. if (el.__dirtyPath) {
  79475. path.beginPath();
  79476. path.subPixelOptimize = false;
  79477. el.buildPath(path, el.shape);
  79478. el.__dirtyPath = false;
  79479. var pathStr = pathDataToString$1(path);
  79480. if (pathStr.indexOf('NaN') < 0) {
  79481. // Ignore illegal path, which may happen such in out-of-range
  79482. // data in Calendar series.
  79483. attr(svgEl, 'd', pathStr);
  79484. }
  79485. }
  79486. bindStyle(svgEl, style, false, el);
  79487. setTransform(svgEl, el.transform);
  79488. if (style.text != null) {
  79489. svgTextDrawRectText(el, el.getBoundingRect());
  79490. }
  79491. };
  79492. /***************************************************
  79493. * IMAGE
  79494. **************************************************/
  79495. var svgImage = {};
  79496. svgImage.brush = function (el) {
  79497. var style = el.style;
  79498. var image = style.image;
  79499. if (image instanceof HTMLImageElement) {
  79500. var src = image.src;
  79501. image = src;
  79502. }
  79503. if (!image) {
  79504. return;
  79505. }
  79506. var x = style.x || 0;
  79507. var y = style.y || 0;
  79508. var dw = style.width;
  79509. var dh = style.height;
  79510. var svgEl = el.__svgEl;
  79511. if (!svgEl) {
  79512. svgEl = createElement('image');
  79513. el.__svgEl = svgEl;
  79514. }
  79515. if (image !== el.__imageSrc) {
  79516. attrXLink(svgEl, 'href', image);
  79517. // Caching image src
  79518. el.__imageSrc = image;
  79519. }
  79520. attr(svgEl, 'width', dw);
  79521. attr(svgEl, 'height', dh);
  79522. attr(svgEl, 'x', x);
  79523. attr(svgEl, 'y', y);
  79524. setTransform(svgEl, el.transform);
  79525. if (style.text != null) {
  79526. svgTextDrawRectText(el, el.getBoundingRect());
  79527. }
  79528. };
  79529. /***************************************************
  79530. * TEXT
  79531. **************************************************/
  79532. var svgText = {};
  79533. var tmpRect$3 = new BoundingRect();
  79534. var svgTextDrawRectText = function (el, rect, textRect) {
  79535. var style = el.style;
  79536. el.__dirty && normalizeTextStyle(style, true);
  79537. var text = style.text;
  79538. // Convert to string
  79539. if (text == null) {
  79540. // Draw no text only when text is set to null, but not ''
  79541. return;
  79542. }
  79543. else {
  79544. text += '';
  79545. }
  79546. var textSvgEl = el.__textSvgEl;
  79547. if (!textSvgEl) {
  79548. textSvgEl = createElement('text');
  79549. el.__textSvgEl = textSvgEl;
  79550. }
  79551. var x;
  79552. var y;
  79553. var textPosition = style.textPosition;
  79554. var distance = style.textDistance;
  79555. var align = style.textAlign || 'left';
  79556. if (typeof style.fontSize === 'number') {
  79557. style.fontSize += 'px';
  79558. }
  79559. var font = style.font
  79560. || [
  79561. style.fontStyle || '',
  79562. style.fontWeight || '',
  79563. style.fontSize || '',
  79564. style.fontFamily || ''
  79565. ].join(' ')
  79566. || DEFAULT_FONT$1;
  79567. var verticalAlign = getVerticalAlignForSvg(style.textVerticalAlign);
  79568. textRect = getBoundingRect(
  79569. text, font, align,
  79570. verticalAlign, style.textPadding, style.textLineHeight
  79571. );
  79572. var lineHeight = textRect.lineHeight;
  79573. // Text position represented by coord
  79574. if (textPosition instanceof Array) {
  79575. x = rect.x + textPosition[0];
  79576. y = rect.y + textPosition[1];
  79577. }
  79578. else {
  79579. var newPos = adjustTextPositionOnRect(
  79580. textPosition, rect, distance
  79581. );
  79582. x = newPos.x;
  79583. y = newPos.y;
  79584. verticalAlign = getVerticalAlignForSvg(newPos.textVerticalAlign);
  79585. align = newPos.textAlign;
  79586. }
  79587. attr(textSvgEl, 'alignment-baseline', verticalAlign);
  79588. if (font) {
  79589. textSvgEl.style.font = font;
  79590. }
  79591. var textPadding = style.textPadding;
  79592. // Make baseline top
  79593. attr(textSvgEl, 'x', x);
  79594. attr(textSvgEl, 'y', y);
  79595. bindStyle(textSvgEl, style, true, el);
  79596. if (el instanceof Text || el.style.transformText) {
  79597. // Transform text with element
  79598. setTransform(textSvgEl, el.transform);
  79599. }
  79600. else {
  79601. if (el.transform) {
  79602. tmpRect$3.copy(rect);
  79603. tmpRect$3.applyTransform(el.transform);
  79604. rect = tmpRect$3;
  79605. }
  79606. else {
  79607. var pos = el.transformCoordToGlobal(rect.x, rect.y);
  79608. rect.x = pos[0];
  79609. rect.y = pos[1];
  79610. el.transform = identity(create$1());
  79611. }
  79612. // Text rotation, but no element transform
  79613. var origin = style.textOrigin;
  79614. if (origin === 'center') {
  79615. x = textRect.width / 2 + x;
  79616. y = textRect.height / 2 + y;
  79617. }
  79618. else if (origin) {
  79619. x = origin[0] + x;
  79620. y = origin[1] + y;
  79621. }
  79622. var rotate$$1 = -style.textRotation || 0;
  79623. var transform = create$1();
  79624. // Apply textRotate to element matrix
  79625. rotate(transform, transform, rotate$$1);
  79626. var pos = [el.transform[4], el.transform[5]];
  79627. translate(transform, transform, pos);
  79628. setTransform(textSvgEl, transform);
  79629. }
  79630. var textLines = text.split('\n');
  79631. var nTextLines = textLines.length;
  79632. var textAnchor = align;
  79633. // PENDING
  79634. if (textAnchor === 'left') {
  79635. textAnchor = 'start';
  79636. textPadding && (x += textPadding[3]);
  79637. }
  79638. else if (textAnchor === 'right') {
  79639. textAnchor = 'end';
  79640. textPadding && (x -= textPadding[1]);
  79641. }
  79642. else if (textAnchor === 'center') {
  79643. textAnchor = 'middle';
  79644. textPadding && (x += (textPadding[3] - textPadding[1]) / 2);
  79645. }
  79646. var dy = 0;
  79647. if (verticalAlign === 'after-edge') {
  79648. dy = -textRect.height + lineHeight;
  79649. textPadding && (dy -= textPadding[2]);
  79650. }
  79651. else if (verticalAlign === 'middle') {
  79652. dy = (-textRect.height + lineHeight) / 2;
  79653. textPadding && (y += (textPadding[0] - textPadding[2]) / 2);
  79654. }
  79655. else {
  79656. textPadding && (dy += textPadding[0]);
  79657. }
  79658. // Font may affect position of each tspan elements
  79659. if (el.__text !== text || el.__textFont !== font) {
  79660. var tspanList = el.__tspanList || [];
  79661. el.__tspanList = tspanList;
  79662. for (var i = 0; i < nTextLines; i++) {
  79663. // Using cached tspan elements
  79664. var tspan = tspanList[i];
  79665. if (!tspan) {
  79666. tspan = tspanList[i] = createElement('tspan');
  79667. textSvgEl.appendChild(tspan);
  79668. attr(tspan, 'alignment-baseline', verticalAlign);
  79669. attr(tspan, 'text-anchor', textAnchor);
  79670. }
  79671. else {
  79672. tspan.innerHTML = '';
  79673. }
  79674. attr(tspan, 'x', x);
  79675. attr(tspan, 'y', y + i * lineHeight + dy);
  79676. tspan.appendChild(document.createTextNode(textLines[i]));
  79677. }
  79678. // Remove unsed tspan elements
  79679. for (; i < tspanList.length; i++) {
  79680. textSvgEl.removeChild(tspanList[i]);
  79681. }
  79682. tspanList.length = nTextLines;
  79683. el.__text = text;
  79684. el.__textFont = font;
  79685. }
  79686. else if (el.__tspanList.length) {
  79687. // Update span x and y
  79688. var len = el.__tspanList.length;
  79689. for (var i = 0; i < len; ++i) {
  79690. var tspan = el.__tspanList[i];
  79691. if (tspan) {
  79692. attr(tspan, 'x', x);
  79693. attr(tspan, 'y', y + i * lineHeight + dy);
  79694. }
  79695. }
  79696. }
  79697. };
  79698. function getVerticalAlignForSvg(verticalAlign) {
  79699. if (verticalAlign === 'middle') {
  79700. return 'middle';
  79701. }
  79702. else if (verticalAlign === 'bottom') {
  79703. return 'after-edge';
  79704. }
  79705. else {
  79706. return 'hanging';
  79707. }
  79708. }
  79709. svgText.drawRectText = svgTextDrawRectText;
  79710. svgText.brush = function (el) {
  79711. var style = el.style;
  79712. if (style.text != null) {
  79713. // 强制设置 textPosition
  79714. style.textPosition = [0, 0];
  79715. svgTextDrawRectText(el, {
  79716. x: style.x || 0, y: style.y || 0,
  79717. width: 0, height: 0
  79718. }, el.getBoundingRect());
  79719. }
  79720. };
  79721. // Myers' Diff Algorithm
  79722. // Modified from https://github.com/kpdecker/jsdiff/blob/master/src/diff/base.js
  79723. function Diff() {}
  79724. Diff.prototype = {
  79725. diff: function (oldArr, newArr, equals) {
  79726. if (!equals) {
  79727. equals = function (a, b) {
  79728. return a === b;
  79729. };
  79730. }
  79731. this.equals = equals;
  79732. var self = this;
  79733. oldArr = oldArr.slice();
  79734. newArr = newArr.slice();
  79735. // Allow subclasses to massage the input prior to running
  79736. var newLen = newArr.length;
  79737. var oldLen = oldArr.length;
  79738. var editLength = 1;
  79739. var maxEditLength = newLen + oldLen;
  79740. var bestPath = [{ newPos: -1, components: [] }];
  79741. // Seed editLength = 0, i.e. the content starts with the same values
  79742. var oldPos = this.extractCommon(bestPath[0], newArr, oldArr, 0);
  79743. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  79744. var indices = [];
  79745. for (var i = 0; i < newArr.length; i++) {
  79746. indices.push(i);
  79747. }
  79748. // Identity per the equality and tokenizer
  79749. return [{
  79750. indices: indices, count: newArr.length
  79751. }];
  79752. }
  79753. // Main worker method. checks all permutations of a given edit length for acceptance.
  79754. function execEditLength() {
  79755. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  79756. var basePath;
  79757. var addPath = bestPath[diagonalPath - 1];
  79758. var removePath = bestPath[diagonalPath + 1];
  79759. var oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  79760. if (addPath) {
  79761. // No one else is going to attempt to use this value, clear it
  79762. bestPath[diagonalPath - 1] = undefined;
  79763. }
  79764. var canAdd = addPath && addPath.newPos + 1 < newLen;
  79765. var canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  79766. if (!canAdd && !canRemove) {
  79767. // If this path is a terminal then prune
  79768. bestPath[diagonalPath] = undefined;
  79769. continue;
  79770. }
  79771. // Select the diagonal that we want to branch from. We select the prior
  79772. // path whose position in the new string is the farthest from the origin
  79773. // and does not pass the bounds of the diff graph
  79774. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  79775. basePath = clonePath(removePath);
  79776. self.pushComponent(basePath.components, undefined, true);
  79777. }
  79778. else {
  79779. basePath = addPath; // No need to clone, we've pulled it from the list
  79780. basePath.newPos++;
  79781. self.pushComponent(basePath.components, true, undefined);
  79782. }
  79783. oldPos = self.extractCommon(basePath, newArr, oldArr, diagonalPath);
  79784. // If we have hit the end of both strings, then we are done
  79785. if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  79786. return buildValues(self, basePath.components, newArr, oldArr);
  79787. }
  79788. else {
  79789. // Otherwise track this path as a potential candidate and continue.
  79790. bestPath[diagonalPath] = basePath;
  79791. }
  79792. }
  79793. editLength++;
  79794. }
  79795. while (editLength <= maxEditLength) {
  79796. var ret = execEditLength();
  79797. if (ret) {
  79798. return ret;
  79799. }
  79800. }
  79801. },
  79802. pushComponent: function (components, added, removed) {
  79803. var last = components[components.length - 1];
  79804. if (last && last.added === added && last.removed === removed) {
  79805. // We need to clone here as the component clone operation is just
  79806. // as shallow array clone
  79807. components[components.length - 1] = {count: last.count + 1, added: added, removed: removed };
  79808. }
  79809. else {
  79810. components.push({count: 1, added: added, removed: removed });
  79811. }
  79812. },
  79813. extractCommon: function (basePath, newArr, oldArr, diagonalPath) {
  79814. var newLen = newArr.length;
  79815. var oldLen = oldArr.length;
  79816. var newPos = basePath.newPos;
  79817. var oldPos = newPos - diagonalPath;
  79818. var commonCount = 0;
  79819. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newArr[newPos + 1], oldArr[oldPos + 1])) {
  79820. newPos++;
  79821. oldPos++;
  79822. commonCount++;
  79823. }
  79824. if (commonCount) {
  79825. basePath.components.push({count: commonCount});
  79826. }
  79827. basePath.newPos = newPos;
  79828. return oldPos;
  79829. },
  79830. tokenize: function (value) {
  79831. return value.slice();
  79832. },
  79833. join: function (value) {
  79834. return value.slice();
  79835. }
  79836. };
  79837. function buildValues(diff, components, newArr, oldArr) {
  79838. var componentPos = 0;
  79839. var componentLen = components.length;
  79840. var newPos = 0;
  79841. var oldPos = 0;
  79842. for (; componentPos < componentLen; componentPos++) {
  79843. var component = components[componentPos];
  79844. if (!component.removed) {
  79845. var indices = [];
  79846. for (var i = newPos; i < newPos + component.count; i++) {
  79847. indices.push(i);
  79848. }
  79849. component.indices = indices;
  79850. newPos += component.count;
  79851. // Common case
  79852. if (!component.added) {
  79853. oldPos += component.count;
  79854. }
  79855. }
  79856. else {
  79857. var indices = [];
  79858. for (var i = oldPos; i < oldPos + component.count; i++) {
  79859. indices.push(i);
  79860. }
  79861. component.indices = indices;
  79862. oldPos += component.count;
  79863. }
  79864. }
  79865. return components;
  79866. }
  79867. function clonePath(path) {
  79868. return { newPos: path.newPos, components: path.components.slice(0) };
  79869. }
  79870. var arrayDiff = new Diff();
  79871. var arrayDiff$1 = function (oldArr, newArr, callback) {
  79872. return arrayDiff.diff(oldArr, newArr, callback);
  79873. };
  79874. /**
  79875. * @file Manages elements that can be defined in <defs> in SVG,
  79876. * e.g., gradients, clip path, etc.
  79877. * @author Zhang Wenli
  79878. */
  79879. var MARK_UNUSED = '0';
  79880. var MARK_USED = '1';
  79881. /**
  79882. * Manages elements that can be defined in <defs> in SVG,
  79883. * e.g., gradients, clip path, etc.
  79884. *
  79885. * @class
  79886. * @param {number} zrId zrender instance id
  79887. * @param {SVGElement} svgRoot root of SVG document
  79888. * @param {string|string[]} tagNames possible tag names
  79889. * @param {string} markLabel label name to make if the element
  79890. * is used
  79891. */
  79892. function Definable(
  79893. zrId,
  79894. svgRoot,
  79895. tagNames,
  79896. markLabel,
  79897. domName
  79898. ) {
  79899. this._zrId = zrId;
  79900. this._svgRoot = svgRoot;
  79901. this._tagNames = typeof tagNames === 'string' ? [tagNames] : tagNames;
  79902. this._markLabel = markLabel;
  79903. this._domName = domName || '_dom';
  79904. this.nextId = 0;
  79905. }
  79906. Definable.prototype.createElement = createElement;
  79907. /**
  79908. * Get the <defs> tag for svgRoot; optionally creates one if not exists.
  79909. *
  79910. * @param {boolean} isForceCreating if need to create when not exists
  79911. * @return {SVGDefsElement} SVG <defs> element, null if it doesn't
  79912. * exist and isForceCreating is false
  79913. */
  79914. Definable.prototype.getDefs = function (isForceCreating) {
  79915. var svgRoot = this._svgRoot;
  79916. var defs = this._svgRoot.getElementsByTagName('defs');
  79917. if (defs.length === 0) {
  79918. // Not exist
  79919. if (isForceCreating) {
  79920. defs = svgRoot.insertBefore(
  79921. this.createElement('defs'), // Create new tag
  79922. svgRoot.firstChild // Insert in the front of svg
  79923. );
  79924. if (!defs.contains) {
  79925. // IE doesn't support contains method
  79926. defs.contains = function (el) {
  79927. var children = defs.children;
  79928. if (!children) {
  79929. return false;
  79930. }
  79931. for (var i = children.length - 1; i >= 0; --i) {
  79932. if (children[i] === el) {
  79933. return true;
  79934. }
  79935. }
  79936. return false;
  79937. };
  79938. }
  79939. return defs;
  79940. }
  79941. else {
  79942. return null;
  79943. }
  79944. }
  79945. else {
  79946. return defs[0];
  79947. }
  79948. };
  79949. /**
  79950. * Update DOM element if necessary.
  79951. *
  79952. * @param {Object|string} element style element. e.g., for gradient,
  79953. * it may be '#ccc' or {type: 'linear', ...}
  79954. * @param {Function|undefined} onUpdate update callback
  79955. */
  79956. Definable.prototype.update = function (element, onUpdate) {
  79957. if (!element) {
  79958. return;
  79959. }
  79960. var defs = this.getDefs(false);
  79961. if (element[this._domName] && defs.contains(element[this._domName])) {
  79962. // Update DOM
  79963. if (typeof onUpdate === 'function') {
  79964. onUpdate(element);
  79965. }
  79966. }
  79967. else {
  79968. // No previous dom, create new
  79969. var dom = this.add(element);
  79970. if (dom) {
  79971. element[this._domName] = dom;
  79972. }
  79973. }
  79974. };
  79975. /**
  79976. * Add gradient dom to defs
  79977. *
  79978. * @param {SVGElement} dom DOM to be added to <defs>
  79979. */
  79980. Definable.prototype.addDom = function (dom) {
  79981. var defs = this.getDefs(true);
  79982. defs.appendChild(dom);
  79983. };
  79984. /**
  79985. * Remove DOM of a given element.
  79986. *
  79987. * @param {SVGElement} element element to remove dom
  79988. */
  79989. Definable.prototype.removeDom = function (element) {
  79990. var defs = this.getDefs(false);
  79991. if (defs && element[this._domName]) {
  79992. defs.removeChild(element[this._domName]);
  79993. element[this._domName] = null;
  79994. }
  79995. };
  79996. /**
  79997. * Get DOMs of this element.
  79998. *
  79999. * @return {HTMLDomElement} doms of this defineable elements in <defs>
  80000. */
  80001. Definable.prototype.getDoms = function () {
  80002. var defs = this.getDefs(false);
  80003. if (!defs) {
  80004. // No dom when defs is not defined
  80005. return [];
  80006. }
  80007. var doms = [];
  80008. each$1(this._tagNames, function (tagName) {
  80009. var tags = defs.getElementsByTagName(tagName);
  80010. // Note that tags is HTMLCollection, which is array-like
  80011. // rather than real array.
  80012. // So `doms.concat(tags)` add tags as one object.
  80013. doms = doms.concat([].slice.call(tags));
  80014. });
  80015. return doms;
  80016. };
  80017. /**
  80018. * Mark DOMs to be unused before painting, and clear unused ones at the end
  80019. * of the painting.
  80020. */
  80021. Definable.prototype.markAllUnused = function () {
  80022. var doms = this.getDoms();
  80023. var that = this;
  80024. each$1(doms, function (dom) {
  80025. dom[that._markLabel] = MARK_UNUSED;
  80026. });
  80027. };
  80028. /**
  80029. * Mark a single DOM to be used.
  80030. *
  80031. * @param {SVGElement} dom DOM to mark
  80032. */
  80033. Definable.prototype.markUsed = function (dom) {
  80034. if (dom) {
  80035. dom[this._markLabel] = MARK_USED;
  80036. }
  80037. };
  80038. /**
  80039. * Remove unused DOMs defined in <defs>
  80040. */
  80041. Definable.prototype.removeUnused = function () {
  80042. var defs = this.getDefs(false);
  80043. if (!defs) {
  80044. // Nothing to remove
  80045. return;
  80046. }
  80047. var doms = this.getDoms();
  80048. var that = this;
  80049. each$1(doms, function (dom) {
  80050. if (dom[that._markLabel] !== MARK_USED) {
  80051. // Remove gradient
  80052. defs.removeChild(dom);
  80053. }
  80054. });
  80055. };
  80056. /**
  80057. * Get SVG proxy.
  80058. *
  80059. * @param {Displayable} displayable displayable element
  80060. * @return {Path|Image|Text} svg proxy of given element
  80061. */
  80062. Definable.prototype.getSvgProxy = function (displayable) {
  80063. if (displayable instanceof Path) {
  80064. return svgPath;
  80065. }
  80066. else if (displayable instanceof ZImage) {
  80067. return svgImage;
  80068. }
  80069. else if (displayable instanceof Text) {
  80070. return svgText;
  80071. }
  80072. else {
  80073. return svgPath;
  80074. }
  80075. };
  80076. /**
  80077. * Get text SVG element.
  80078. *
  80079. * @param {Displayable} displayable displayable element
  80080. * @return {SVGElement} SVG element of text
  80081. */
  80082. Definable.prototype.getTextSvgElement = function (displayable) {
  80083. return displayable.__textSvgEl;
  80084. };
  80085. /**
  80086. * Get SVG element.
  80087. *
  80088. * @param {Displayable} displayable displayable element
  80089. * @return {SVGElement} SVG element
  80090. */
  80091. Definable.prototype.getSvgElement = function (displayable) {
  80092. return displayable.__svgEl;
  80093. };
  80094. /**
  80095. * @file Manages SVG gradient elements.
  80096. * @author Zhang Wenli
  80097. */
  80098. /**
  80099. * Manages SVG gradient elements.
  80100. *
  80101. * @class
  80102. * @extends Definable
  80103. * @param {number} zrId zrender instance id
  80104. * @param {SVGElement} svgRoot root of SVG document
  80105. */
  80106. function GradientManager(zrId, svgRoot) {
  80107. Definable.call(
  80108. this,
  80109. zrId,
  80110. svgRoot,
  80111. ['linearGradient', 'radialGradient'],
  80112. '__gradient_in_use__'
  80113. );
  80114. }
  80115. inherits(GradientManager, Definable);
  80116. /**
  80117. * Create new gradient DOM for fill or stroke if not exist,
  80118. * but will not update gradient if exists.
  80119. *
  80120. * @param {SvgElement} svgElement SVG element to paint
  80121. * @param {Displayable} displayable zrender displayable element
  80122. */
  80123. GradientManager.prototype.addWithoutUpdate = function (
  80124. svgElement,
  80125. displayable
  80126. ) {
  80127. if (displayable && displayable.style) {
  80128. var that = this;
  80129. each$1(['fill', 'stroke'], function (fillOrStroke) {
  80130. if (displayable.style[fillOrStroke]
  80131. && (displayable.style[fillOrStroke].type === 'linear'
  80132. || displayable.style[fillOrStroke].type === 'radial')
  80133. ) {
  80134. var gradient = displayable.style[fillOrStroke];
  80135. var defs = that.getDefs(true);
  80136. // Create dom in <defs> if not exists
  80137. var dom;
  80138. if (gradient._dom) {
  80139. // Gradient exists
  80140. dom = gradient._dom;
  80141. if (!defs.contains(gradient._dom)) {
  80142. // _dom is no longer in defs, recreate
  80143. that.addDom(dom);
  80144. }
  80145. }
  80146. else {
  80147. // New dom
  80148. dom = that.add(gradient);
  80149. }
  80150. that.markUsed(displayable);
  80151. var id = dom.getAttribute('id');
  80152. svgElement.setAttribute(fillOrStroke, 'url(#' + id + ')');
  80153. }
  80154. });
  80155. }
  80156. };
  80157. /**
  80158. * Add a new gradient tag in <defs>
  80159. *
  80160. * @param {Gradient} gradient zr gradient instance
  80161. * @return {SVGLinearGradientElement | SVGRadialGradientElement}
  80162. * created DOM
  80163. */
  80164. GradientManager.prototype.add = function (gradient) {
  80165. var dom;
  80166. if (gradient.type === 'linear') {
  80167. dom = this.createElement('linearGradient');
  80168. }
  80169. else if (gradient.type === 'radial') {
  80170. dom = this.createElement('radialGradient');
  80171. }
  80172. else {
  80173. zrLog('Illegal gradient type.');
  80174. return null;
  80175. }
  80176. // Set dom id with gradient id, since each gradient instance
  80177. // will have no more than one dom element.
  80178. // id may exists before for those dirty elements, in which case
  80179. // id should remain the same, and other attributes should be
  80180. // updated.
  80181. gradient.id = gradient.id || this.nextId++;
  80182. dom.setAttribute('id', 'zr' + this._zrId
  80183. + '-gradient-' + gradient.id);
  80184. this.updateDom(gradient, dom);
  80185. this.addDom(dom);
  80186. return dom;
  80187. };
  80188. /**
  80189. * Update gradient.
  80190. *
  80191. * @param {Gradient} gradient zr gradient instance
  80192. */
  80193. GradientManager.prototype.update = function (gradient) {
  80194. var that = this;
  80195. Definable.prototype.update.call(this, gradient, function () {
  80196. var type = gradient.type;
  80197. var tagName = gradient._dom.tagName;
  80198. if (type === 'linear' && tagName === 'linearGradient'
  80199. || type === 'radial' && tagName === 'radialGradient'
  80200. ) {
  80201. // Gradient type is not changed, update gradient
  80202. that.updateDom(gradient, gradient._dom);
  80203. }
  80204. else {
  80205. // Remove and re-create if type is changed
  80206. that.removeDom(gradient);
  80207. that.add(gradient);
  80208. }
  80209. });
  80210. };
  80211. /**
  80212. * Update gradient dom
  80213. *
  80214. * @param {Gradient} gradient zr gradient instance
  80215. * @param {SVGLinearGradientElement | SVGRadialGradientElement} dom
  80216. * DOM to update
  80217. */
  80218. GradientManager.prototype.updateDom = function (gradient, dom) {
  80219. if (gradient.type === 'linear') {
  80220. dom.setAttribute('x1', gradient.x);
  80221. dom.setAttribute('y1', gradient.y);
  80222. dom.setAttribute('x2', gradient.x2);
  80223. dom.setAttribute('y2', gradient.y2);
  80224. }
  80225. else if (gradient.type === 'radial') {
  80226. dom.setAttribute('cx', gradient.x);
  80227. dom.setAttribute('cy', gradient.y);
  80228. dom.setAttribute('r', gradient.r);
  80229. }
  80230. else {
  80231. zrLog('Illegal gradient type.');
  80232. return;
  80233. }
  80234. if (gradient.global) {
  80235. // x1, x2, y1, y2 in range of 0 to canvas width or height
  80236. dom.setAttribute('gradientUnits', 'userSpaceOnUse');
  80237. }
  80238. else {
  80239. // x1, x2, y1, y2 in range of 0 to 1
  80240. dom.setAttribute('gradientUnits', 'objectBoundingBox');
  80241. }
  80242. // Remove color stops if exists
  80243. dom.innerHTML = '';
  80244. // Add color stops
  80245. var colors = gradient.colorStops;
  80246. for (var i = 0, len = colors.length; i < len; ++i) {
  80247. var stop = this.createElement('stop');
  80248. stop.setAttribute('offset', colors[i].offset * 100 + '%');
  80249. var color = colors[i].color;
  80250. if (color.indexOf('rgba' > -1)) {
  80251. // Fix Safari bug that stop-color not recognizing alpha #9014
  80252. var opacity = parse(color)[3];
  80253. var hex = toHex(color);
  80254. // stop-color cannot be color, since:
  80255. // The opacity value used for the gradient calculation is the
  80256. // *product* of the value of stop-opacity and the opacity of the
  80257. // value of stop-color.
  80258. // See https://www.w3.org/TR/SVG2/pservers.html#StopOpacityProperty
  80259. stop.setAttribute('stop-color', '#' + hex);
  80260. stop.setAttribute('stop-opacity', opacity);
  80261. }
  80262. else {
  80263. stop.setAttribute('stop-color', colors[i].color);
  80264. }
  80265. dom.appendChild(stop);
  80266. }
  80267. // Store dom element in gradient, to avoid creating multiple
  80268. // dom instances for the same gradient element
  80269. gradient._dom = dom;
  80270. };
  80271. /**
  80272. * Mark a single gradient to be used
  80273. *
  80274. * @param {Displayable} displayable displayable element
  80275. */
  80276. GradientManager.prototype.markUsed = function (displayable) {
  80277. if (displayable.style) {
  80278. var gradient = displayable.style.fill;
  80279. if (gradient && gradient._dom) {
  80280. Definable.prototype.markUsed.call(this, gradient._dom);
  80281. }
  80282. gradient = displayable.style.stroke;
  80283. if (gradient && gradient._dom) {
  80284. Definable.prototype.markUsed.call(this, gradient._dom);
  80285. }
  80286. }
  80287. };
  80288. /**
  80289. * @file Manages SVG clipPath elements.
  80290. * @author Zhang Wenli
  80291. */
  80292. /**
  80293. * Manages SVG clipPath elements.
  80294. *
  80295. * @class
  80296. * @extends Definable
  80297. * @param {number} zrId zrender instance id
  80298. * @param {SVGElement} svgRoot root of SVG document
  80299. */
  80300. function ClippathManager(zrId, svgRoot) {
  80301. Definable.call(this, zrId, svgRoot, 'clipPath', '__clippath_in_use__');
  80302. }
  80303. inherits(ClippathManager, Definable);
  80304. /**
  80305. * Update clipPath.
  80306. *
  80307. * @param {Displayable} displayable displayable element
  80308. */
  80309. ClippathManager.prototype.update = function (displayable) {
  80310. var svgEl = this.getSvgElement(displayable);
  80311. if (svgEl) {
  80312. this.updateDom(svgEl, displayable.__clipPaths, false);
  80313. }
  80314. var textEl = this.getTextSvgElement(displayable);
  80315. if (textEl) {
  80316. // Make another clipPath for text, since it's transform
  80317. // matrix is not the same with svgElement
  80318. this.updateDom(textEl, displayable.__clipPaths, true);
  80319. }
  80320. this.markUsed(displayable);
  80321. };
  80322. /**
  80323. * Create an SVGElement of displayable and create a <clipPath> of its
  80324. * clipPath
  80325. *
  80326. * @param {Displayable} parentEl parent element
  80327. * @param {ClipPath[]} clipPaths clipPaths of parent element
  80328. * @param {boolean} isText if parent element is Text
  80329. */
  80330. ClippathManager.prototype.updateDom = function (
  80331. parentEl,
  80332. clipPaths,
  80333. isText
  80334. ) {
  80335. if (clipPaths && clipPaths.length > 0) {
  80336. // Has clipPath, create <clipPath> with the first clipPath
  80337. var defs = this.getDefs(true);
  80338. var clipPath = clipPaths[0];
  80339. var clipPathEl;
  80340. var id;
  80341. var dom = isText ? '_textDom' : '_dom';
  80342. if (clipPath[dom]) {
  80343. // Use a dom that is already in <defs>
  80344. id = clipPath[dom].getAttribute('id');
  80345. clipPathEl = clipPath[dom];
  80346. // Use a dom that is already in <defs>
  80347. if (!defs.contains(clipPathEl)) {
  80348. // This happens when set old clipPath that has
  80349. // been previously removed
  80350. defs.appendChild(clipPathEl);
  80351. }
  80352. }
  80353. else {
  80354. // New <clipPath>
  80355. id = 'zr' + this._zrId + '-clip-' + this.nextId;
  80356. ++this.nextId;
  80357. clipPathEl = this.createElement('clipPath');
  80358. clipPathEl.setAttribute('id', id);
  80359. defs.appendChild(clipPathEl);
  80360. clipPath[dom] = clipPathEl;
  80361. }
  80362. // Build path and add to <clipPath>
  80363. var svgProxy = this.getSvgProxy(clipPath);
  80364. if (clipPath.transform
  80365. && clipPath.parent.invTransform
  80366. && !isText
  80367. ) {
  80368. /**
  80369. * If a clipPath has a parent with transform, the transform
  80370. * of parent should not be considered when setting transform
  80371. * of clipPath. So we need to transform back from parent's
  80372. * transform, which is done by multiplying parent's inverse
  80373. * transform.
  80374. */
  80375. // Store old transform
  80376. var transform = Array.prototype.slice.call(
  80377. clipPath.transform
  80378. );
  80379. // Transform back from parent, and brush path
  80380. mul$1(
  80381. clipPath.transform,
  80382. clipPath.parent.invTransform,
  80383. clipPath.transform
  80384. );
  80385. svgProxy.brush(clipPath);
  80386. // Set back transform of clipPath
  80387. clipPath.transform = transform;
  80388. }
  80389. else {
  80390. svgProxy.brush(clipPath);
  80391. }
  80392. var pathEl = this.getSvgElement(clipPath);
  80393. clipPathEl.innerHTML = '';
  80394. /**
  80395. * Use `cloneNode()` here to appendChild to multiple parents,
  80396. * which may happend when Text and other shapes are using the same
  80397. * clipPath. Since Text will create an extra clipPath DOM due to
  80398. * different transform rules.
  80399. */
  80400. clipPathEl.appendChild(pathEl.cloneNode());
  80401. parentEl.setAttribute('clip-path', 'url(#' + id + ')');
  80402. if (clipPaths.length > 1) {
  80403. // Make the other clipPaths recursively
  80404. this.updateDom(clipPathEl, clipPaths.slice(1), isText);
  80405. }
  80406. }
  80407. else {
  80408. // No clipPath
  80409. if (parentEl) {
  80410. parentEl.setAttribute('clip-path', 'none');
  80411. }
  80412. }
  80413. };
  80414. /**
  80415. * Mark a single clipPath to be used
  80416. *
  80417. * @param {Displayable} displayable displayable element
  80418. */
  80419. ClippathManager.prototype.markUsed = function (displayable) {
  80420. var that = this;
  80421. if (displayable.__clipPaths && displayable.__clipPaths.length > 0) {
  80422. each$1(displayable.__clipPaths, function (clipPath) {
  80423. if (clipPath._dom) {
  80424. Definable.prototype.markUsed.call(that, clipPath._dom);
  80425. }
  80426. if (clipPath._textDom) {
  80427. Definable.prototype.markUsed.call(that, clipPath._textDom);
  80428. }
  80429. });
  80430. }
  80431. };
  80432. /**
  80433. * @file Manages SVG shadow elements.
  80434. * @author Zhang Wenli
  80435. */
  80436. /**
  80437. * Manages SVG shadow elements.
  80438. *
  80439. * @class
  80440. * @extends Definable
  80441. * @param {number} zrId zrender instance id
  80442. * @param {SVGElement} svgRoot root of SVG document
  80443. */
  80444. function ShadowManager(zrId, svgRoot) {
  80445. Definable.call(
  80446. this,
  80447. zrId,
  80448. svgRoot,
  80449. ['filter'],
  80450. '__filter_in_use__',
  80451. '_shadowDom'
  80452. );
  80453. }
  80454. inherits(ShadowManager, Definable);
  80455. /**
  80456. * Create new shadow DOM for fill or stroke if not exist,
  80457. * but will not update shadow if exists.
  80458. *
  80459. * @param {SvgElement} svgElement SVG element to paint
  80460. * @param {Displayable} displayable zrender displayable element
  80461. */
  80462. ShadowManager.prototype.addWithoutUpdate = function (
  80463. svgElement,
  80464. displayable
  80465. ) {
  80466. if (displayable && hasShadow(displayable.style)) {
  80467. var style = displayable.style;
  80468. // Create dom in <defs> if not exists
  80469. var dom;
  80470. if (style._shadowDom) {
  80471. // Gradient exists
  80472. dom = style._shadowDom;
  80473. var defs = this.getDefs(true);
  80474. if (!defs.contains(style._shadowDom)) {
  80475. // _shadowDom is no longer in defs, recreate
  80476. this.addDom(dom);
  80477. }
  80478. }
  80479. else {
  80480. // New dom
  80481. dom = this.add(displayable);
  80482. }
  80483. this.markUsed(displayable);
  80484. var id = dom.getAttribute('id');
  80485. svgElement.style.filter = 'url(#' + id + ')';
  80486. }
  80487. };
  80488. /**
  80489. * Add a new shadow tag in <defs>
  80490. *
  80491. * @param {Displayable} displayable zrender displayable element
  80492. * @return {SVGFilterElement} created DOM
  80493. */
  80494. ShadowManager.prototype.add = function (displayable) {
  80495. var dom = this.createElement('filter');
  80496. var style = displayable.style;
  80497. // Set dom id with shadow id, since each shadow instance
  80498. // will have no more than one dom element.
  80499. // id may exists before for those dirty elements, in which case
  80500. // id should remain the same, and other attributes should be
  80501. // updated.
  80502. style._shadowDomId = style._shadowDomId || this.nextId++;
  80503. dom.setAttribute('id', 'zr' + this._zrId
  80504. + '-shadow-' + style._shadowDomId);
  80505. this.updateDom(displayable, dom);
  80506. this.addDom(dom);
  80507. return dom;
  80508. };
  80509. /**
  80510. * Update shadow.
  80511. *
  80512. * @param {Displayable} displayable zrender displayable element
  80513. */
  80514. ShadowManager.prototype.update = function (svgElement, displayable) {
  80515. var style = displayable.style;
  80516. if (hasShadow(style)) {
  80517. var that = this;
  80518. Definable.prototype.update.call(this, displayable, function (style) {
  80519. that.updateDom(displayable, style._shadowDom);
  80520. });
  80521. }
  80522. else {
  80523. // Remove shadow
  80524. this.remove(svgElement, style);
  80525. }
  80526. };
  80527. /**
  80528. * Remove DOM and clear parent filter
  80529. */
  80530. ShadowManager.prototype.remove = function (svgElement, style) {
  80531. if (style._shadowDomId != null) {
  80532. this.removeDom(style);
  80533. svgElement.style.filter = '';
  80534. }
  80535. };
  80536. /**
  80537. * Update shadow dom
  80538. *
  80539. * @param {Displayable} displayable zrender displayable element
  80540. * @param {SVGFilterElement} dom DOM to update
  80541. */
  80542. ShadowManager.prototype.updateDom = function (displayable, dom) {
  80543. var domChild = dom.getElementsByTagName('feDropShadow');
  80544. if (domChild.length === 0) {
  80545. domChild = this.createElement('feDropShadow');
  80546. }
  80547. else {
  80548. domChild = domChild[0];
  80549. }
  80550. var style = displayable.style;
  80551. var scaleX = displayable.scale ? (displayable.scale[0] || 1) : 1;
  80552. var scaleY = displayable.scale ? (displayable.scale[1] || 1) : 1;
  80553. // TODO: textBoxShadowBlur is not supported yet
  80554. var offsetX, offsetY, blur, color;
  80555. if (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY) {
  80556. offsetX = style.shadowOffsetX || 0;
  80557. offsetY = style.shadowOffsetY || 0;
  80558. blur = style.shadowBlur;
  80559. color = style.shadowColor;
  80560. }
  80561. else if (style.textShadowBlur) {
  80562. offsetX = style.textShadowOffsetX || 0;
  80563. offsetY = style.textShadowOffsetY || 0;
  80564. blur = style.textShadowBlur;
  80565. color = style.textShadowColor;
  80566. }
  80567. else {
  80568. // Remove shadow
  80569. this.removeDom(dom, style);
  80570. return;
  80571. }
  80572. domChild.setAttribute('dx', offsetX / scaleX);
  80573. domChild.setAttribute('dy', offsetY / scaleY);
  80574. domChild.setAttribute('flood-color', color);
  80575. // Divide by two here so that it looks the same as in canvas
  80576. // See: https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowblur
  80577. var stdDx = blur / 2 / scaleX;
  80578. var stdDy = blur / 2 / scaleY;
  80579. var stdDeviation = stdDx + ' ' + stdDy;
  80580. domChild.setAttribute('stdDeviation', stdDeviation);
  80581. // Fix filter clipping problem
  80582. dom.setAttribute('x', '-100%');
  80583. dom.setAttribute('y', '-100%');
  80584. dom.setAttribute('width', Math.ceil(blur / 2 * 200) + '%');
  80585. dom.setAttribute('height', Math.ceil(blur / 2 * 200) + '%');
  80586. dom.appendChild(domChild);
  80587. // Store dom element in shadow, to avoid creating multiple
  80588. // dom instances for the same shadow element
  80589. style._shadowDom = dom;
  80590. };
  80591. /**
  80592. * Mark a single shadow to be used
  80593. *
  80594. * @param {Displayable} displayable displayable element
  80595. */
  80596. ShadowManager.prototype.markUsed = function (displayable) {
  80597. var style = displayable.style;
  80598. if (style && style._shadowDom) {
  80599. Definable.prototype.markUsed.call(this, style._shadowDom);
  80600. }
  80601. };
  80602. function hasShadow(style) {
  80603. // TODO: textBoxShadowBlur is not supported yet
  80604. return style
  80605. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY
  80606. || style.textShadowBlur || style.textShadowOffsetX
  80607. || style.textShadowOffsetY);
  80608. }
  80609. /**
  80610. * SVG Painter
  80611. * @module zrender/svg/Painter
  80612. */
  80613. function parseInt10$2(val) {
  80614. return parseInt(val, 10);
  80615. }
  80616. function getSvgProxy(el) {
  80617. if (el instanceof Path) {
  80618. return svgPath;
  80619. }
  80620. else if (el instanceof ZImage) {
  80621. return svgImage;
  80622. }
  80623. else if (el instanceof Text) {
  80624. return svgText;
  80625. }
  80626. else {
  80627. return svgPath;
  80628. }
  80629. }
  80630. function checkParentAvailable(parent, child) {
  80631. return child && parent && child.parentNode !== parent;
  80632. }
  80633. function insertAfter(parent, child, prevSibling) {
  80634. if (checkParentAvailable(parent, child) && prevSibling) {
  80635. var nextSibling = prevSibling.nextSibling;
  80636. nextSibling ? parent.insertBefore(child, nextSibling)
  80637. : parent.appendChild(child);
  80638. }
  80639. }
  80640. function prepend(parent, child) {
  80641. if (checkParentAvailable(parent, child)) {
  80642. var firstChild = parent.firstChild;
  80643. firstChild ? parent.insertBefore(child, firstChild)
  80644. : parent.appendChild(child);
  80645. }
  80646. }
  80647. function remove$1(parent, child) {
  80648. if (child && parent && child.parentNode === parent) {
  80649. parent.removeChild(child);
  80650. }
  80651. }
  80652. function getTextSvgElement(displayable) {
  80653. return displayable.__textSvgEl;
  80654. }
  80655. function getSvgElement(displayable) {
  80656. return displayable.__svgEl;
  80657. }
  80658. /**
  80659. * @alias module:zrender/svg/Painter
  80660. * @constructor
  80661. * @param {HTMLElement} root 绘图容器
  80662. * @param {module:zrender/Storage} storage
  80663. * @param {Object} opts
  80664. */
  80665. var SVGPainter = function (root, storage, opts, zrId) {
  80666. this.root = root;
  80667. this.storage = storage;
  80668. this._opts = opts = extend({}, opts || {});
  80669. var svgRoot = createElement('svg');
  80670. svgRoot.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  80671. svgRoot.setAttribute('version', '1.1');
  80672. svgRoot.setAttribute('baseProfile', 'full');
  80673. svgRoot.style.cssText = 'user-select:none;position:absolute;left:0;top:0;';
  80674. this.gradientManager = new GradientManager(zrId, svgRoot);
  80675. this.clipPathManager = new ClippathManager(zrId, svgRoot);
  80676. this.shadowManager = new ShadowManager(zrId, svgRoot);
  80677. var viewport = document.createElement('div');
  80678. viewport.style.cssText = 'overflow:hidden;position:relative';
  80679. this._svgRoot = svgRoot;
  80680. this._viewport = viewport;
  80681. root.appendChild(viewport);
  80682. viewport.appendChild(svgRoot);
  80683. this.resize(opts.width, opts.height);
  80684. this._visibleList = [];
  80685. };
  80686. SVGPainter.prototype = {
  80687. constructor: SVGPainter,
  80688. getType: function () {
  80689. return 'svg';
  80690. },
  80691. getViewportRoot: function () {
  80692. return this._viewport;
  80693. },
  80694. getViewportRootOffset: function () {
  80695. var viewportRoot = this.getViewportRoot();
  80696. if (viewportRoot) {
  80697. return {
  80698. offsetLeft: viewportRoot.offsetLeft || 0,
  80699. offsetTop: viewportRoot.offsetTop || 0
  80700. };
  80701. }
  80702. },
  80703. refresh: function () {
  80704. var list = this.storage.getDisplayList(true);
  80705. this._paintList(list);
  80706. },
  80707. setBackgroundColor: function (backgroundColor) {
  80708. // TODO gradient
  80709. this._viewport.style.background = backgroundColor;
  80710. },
  80711. _paintList: function (list) {
  80712. this.gradientManager.markAllUnused();
  80713. this.clipPathManager.markAllUnused();
  80714. this.shadowManager.markAllUnused();
  80715. var svgRoot = this._svgRoot;
  80716. var visibleList = this._visibleList;
  80717. var listLen = list.length;
  80718. var newVisibleList = [];
  80719. var i;
  80720. for (i = 0; i < listLen; i++) {
  80721. var displayable = list[i];
  80722. var svgProxy = getSvgProxy(displayable);
  80723. var svgElement = getSvgElement(displayable)
  80724. || getTextSvgElement(displayable);
  80725. if (!displayable.invisible) {
  80726. if (displayable.__dirty) {
  80727. svgProxy && svgProxy.brush(displayable);
  80728. // Update clipPath
  80729. this.clipPathManager.update(displayable);
  80730. // Update gradient and shadow
  80731. if (displayable.style) {
  80732. this.gradientManager
  80733. .update(displayable.style.fill);
  80734. this.gradientManager
  80735. .update(displayable.style.stroke);
  80736. this.shadowManager
  80737. .update(svgElement, displayable);
  80738. }
  80739. displayable.__dirty = false;
  80740. }
  80741. newVisibleList.push(displayable);
  80742. }
  80743. }
  80744. var diff = arrayDiff$1(visibleList, newVisibleList);
  80745. var prevSvgElement;
  80746. // First do remove, in case element moved to the head and do remove
  80747. // after add
  80748. for (i = 0; i < diff.length; i++) {
  80749. var item = diff[i];
  80750. if (item.removed) {
  80751. for (var k = 0; k < item.count; k++) {
  80752. var displayable = visibleList[item.indices[k]];
  80753. var svgElement = getSvgElement(displayable);
  80754. var textSvgElement = getTextSvgElement(displayable);
  80755. remove$1(svgRoot, svgElement);
  80756. remove$1(svgRoot, textSvgElement);
  80757. }
  80758. }
  80759. }
  80760. for (i = 0; i < diff.length; i++) {
  80761. var item = diff[i];
  80762. if (item.added) {
  80763. for (var k = 0; k < item.count; k++) {
  80764. var displayable = newVisibleList[item.indices[k]];
  80765. var svgElement = getSvgElement(displayable);
  80766. var textSvgElement = getTextSvgElement(displayable);
  80767. prevSvgElement
  80768. ? insertAfter(svgRoot, svgElement, prevSvgElement)
  80769. : prepend(svgRoot, svgElement);
  80770. if (svgElement) {
  80771. insertAfter(svgRoot, textSvgElement, svgElement);
  80772. }
  80773. else if (prevSvgElement) {
  80774. insertAfter(
  80775. svgRoot, textSvgElement, prevSvgElement
  80776. );
  80777. }
  80778. else {
  80779. prepend(svgRoot, textSvgElement);
  80780. }
  80781. // Insert text
  80782. insertAfter(svgRoot, textSvgElement, svgElement);
  80783. prevSvgElement = textSvgElement || svgElement
  80784. || prevSvgElement;
  80785. this.gradientManager
  80786. .addWithoutUpdate(svgElement, displayable);
  80787. this.shadowManager
  80788. .addWithoutUpdate(prevSvgElement, displayable);
  80789. this.clipPathManager.markUsed(displayable);
  80790. }
  80791. }
  80792. else if (!item.removed) {
  80793. for (var k = 0; k < item.count; k++) {
  80794. var displayable = newVisibleList[item.indices[k]];
  80795. prevSvgElement =
  80796. svgElement =
  80797. getTextSvgElement(displayable)
  80798. || getSvgElement(displayable)
  80799. || prevSvgElement;
  80800. this.gradientManager.markUsed(displayable);
  80801. this.gradientManager
  80802. .addWithoutUpdate(svgElement, displayable);
  80803. this.shadowManager.markUsed(displayable);
  80804. this.shadowManager
  80805. .addWithoutUpdate(svgElement, displayable);
  80806. this.clipPathManager.markUsed(displayable);
  80807. }
  80808. }
  80809. }
  80810. this.gradientManager.removeUnused();
  80811. this.clipPathManager.removeUnused();
  80812. this.shadowManager.removeUnused();
  80813. this._visibleList = newVisibleList;
  80814. },
  80815. _getDefs: function (isForceCreating) {
  80816. var svgRoot = this._svgRoot;
  80817. var defs = this._svgRoot.getElementsByTagName('defs');
  80818. if (defs.length === 0) {
  80819. // Not exist
  80820. if (isForceCreating) {
  80821. var defs = svgRoot.insertBefore(
  80822. createElement('defs'), // Create new tag
  80823. svgRoot.firstChild // Insert in the front of svg
  80824. );
  80825. if (!defs.contains) {
  80826. // IE doesn't support contains method
  80827. defs.contains = function (el) {
  80828. var children = defs.children;
  80829. if (!children) {
  80830. return false;
  80831. }
  80832. for (var i = children.length - 1; i >= 0; --i) {
  80833. if (children[i] === el) {
  80834. return true;
  80835. }
  80836. }
  80837. return false;
  80838. };
  80839. }
  80840. return defs;
  80841. }
  80842. else {
  80843. return null;
  80844. }
  80845. }
  80846. else {
  80847. return defs[0];
  80848. }
  80849. },
  80850. resize: function (width, height) {
  80851. var viewport = this._viewport;
  80852. // FIXME Why ?
  80853. viewport.style.display = 'none';
  80854. // Save input w/h
  80855. var opts = this._opts;
  80856. width != null && (opts.width = width);
  80857. height != null && (opts.height = height);
  80858. width = this._getSize(0);
  80859. height = this._getSize(1);
  80860. viewport.style.display = '';
  80861. if (this._width !== width || this._height !== height) {
  80862. this._width = width;
  80863. this._height = height;
  80864. var viewportStyle = viewport.style;
  80865. viewportStyle.width = width + 'px';
  80866. viewportStyle.height = height + 'px';
  80867. var svgRoot = this._svgRoot;
  80868. // Set width by 'svgRoot.width = width' is invalid
  80869. svgRoot.setAttribute('width', width);
  80870. svgRoot.setAttribute('height', height);
  80871. }
  80872. },
  80873. /**
  80874. * 获取绘图区域宽度
  80875. */
  80876. getWidth: function () {
  80877. return this._width;
  80878. },
  80879. /**
  80880. * 获取绘图区域高度
  80881. */
  80882. getHeight: function () {
  80883. return this._height;
  80884. },
  80885. _getSize: function (whIdx) {
  80886. var opts = this._opts;
  80887. var wh = ['width', 'height'][whIdx];
  80888. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  80889. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  80890. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  80891. if (opts[wh] != null && opts[wh] !== 'auto') {
  80892. return parseFloat(opts[wh]);
  80893. }
  80894. var root = this.root;
  80895. // IE8 does not support getComputedStyle, but it use VML.
  80896. var stl = document.defaultView.getComputedStyle(root);
  80897. return (
  80898. (root[cwh] || parseInt10$2(stl[wh]) || parseInt10$2(root.style[wh]))
  80899. - (parseInt10$2(stl[plt]) || 0)
  80900. - (parseInt10$2(stl[prb]) || 0)
  80901. ) | 0;
  80902. },
  80903. dispose: function () {
  80904. this.root.innerHTML = '';
  80905. this._svgRoot =
  80906. this._viewport =
  80907. this.storage =
  80908. null;
  80909. },
  80910. clear: function () {
  80911. if (this._viewport) {
  80912. this.root.removeChild(this._viewport);
  80913. }
  80914. },
  80915. pathToDataUrl: function () {
  80916. this.refresh();
  80917. var html = this._svgRoot.outerHTML;
  80918. return 'data:image/svg+xml;charset=UTF-8,' + html;
  80919. }
  80920. };
  80921. // Not supported methods
  80922. function createMethodNotSupport$1(method) {
  80923. return function () {
  80924. zrLog('In SVG mode painter not support method "' + method + '"');
  80925. };
  80926. }
  80927. // Unsuppoted methods
  80928. each$1([
  80929. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuiltinLayer',
  80930. 'eachOtherLayer', 'getLayers', 'modLayer', 'delLayer', 'clearLayer',
  80931. 'toDataURL', 'pathToImage'
  80932. ], function (name) {
  80933. SVGPainter.prototype[name] = createMethodNotSupport$1(name);
  80934. });
  80935. registerPainter('svg', SVGPainter);
  80936. /*
  80937. * Licensed to the Apache Software Foundation (ASF) under one
  80938. * or more contributor license agreements. See the NOTICE file
  80939. * distributed with this work for additional information
  80940. * regarding copyright ownership. The ASF licenses this file
  80941. * to you under the Apache License, Version 2.0 (the
  80942. * "License"); you may not use this file except in compliance
  80943. * with the License. You may obtain a copy of the License at
  80944. *
  80945. * http://www.apache.org/licenses/LICENSE-2.0
  80946. *
  80947. * Unless required by applicable law or agreed to in writing,
  80948. * software distributed under the License is distributed on an
  80949. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  80950. * KIND, either express or implied. See the License for the
  80951. * specific language governing permissions and limitations
  80952. * under the License.
  80953. */
  80954. // Import all charts and components
  80955. exports.version = version;
  80956. exports.dependencies = dependencies;
  80957. exports.PRIORITY = PRIORITY;
  80958. exports.init = init;
  80959. exports.connect = connect;
  80960. exports.disConnect = disConnect;
  80961. exports.disconnect = disconnect;
  80962. exports.dispose = dispose;
  80963. exports.getInstanceByDom = getInstanceByDom;
  80964. exports.getInstanceById = getInstanceById;
  80965. exports.registerTheme = registerTheme;
  80966. exports.registerPreprocessor = registerPreprocessor;
  80967. exports.registerProcessor = registerProcessor;
  80968. exports.registerPostUpdate = registerPostUpdate;
  80969. exports.registerAction = registerAction;
  80970. exports.registerCoordinateSystem = registerCoordinateSystem;
  80971. exports.getCoordinateSystemDimensions = getCoordinateSystemDimensions;
  80972. exports.registerLayout = registerLayout;
  80973. exports.registerVisual = registerVisual;
  80974. exports.registerLoading = registerLoading;
  80975. exports.extendComponentModel = extendComponentModel;
  80976. exports.extendComponentView = extendComponentView;
  80977. exports.extendSeriesModel = extendSeriesModel;
  80978. exports.extendChartView = extendChartView;
  80979. exports.setCanvasCreator = setCanvasCreator;
  80980. exports.registerMap = registerMap;
  80981. exports.getMap = getMap;
  80982. exports.dataTool = dataTool;
  80983. exports.zrender = zrender;
  80984. exports.number = number;
  80985. exports.format = format;
  80986. exports.throttle = throttle;
  80987. exports.helper = helper;
  80988. exports.matrix = matrix;
  80989. exports.vector = vector;
  80990. exports.color = color;
  80991. exports.parseGeoJSON = parseGeoJson$1;
  80992. exports.parseGeoJson = parseGeoJson;
  80993. exports.util = ecUtil;
  80994. exports.graphic = graphic$1;
  80995. exports.List = List;
  80996. exports.Model = Model;
  80997. exports.Axis = Axis;
  80998. exports.env = env$1;
  80999. })));
  81000. //# sourceMappingURL=echarts.js.map